Close

'MULTITHREADING'

A project log for 'Thor' robot with addons and GUI

Thor robot based on the author AngelLM

dannyvandenheuveldannyvandenheuvel 01/03/2017 at 23:115 Comments

I did a total makeover, through away FreeRTOS and changed everything with the standard library 'Scheduler'.
By reading the whole documentation I understood that it isn't a real 'realtime system' . By every delay in the task it starts another task, this feels like doing things at the same time, but it isn't. You can't, so I disayded to try it on another way. I readed the instructions of 'Scheduler' and saw it was on the same way but in a lot simpler way.
I was very suprised of the result, it is a lot better. The benefit is working with a arduino due, it is a lot powerfuller then the mega board.

This is what I did,

#include <Scheduler.h>
void setup()
{
	Scheduler.startLoop(vStp01TaskON); // Write data to display
	Scheduler.startLoop(vStp02TaskON); // Read data from display
	Scheduler.startLoop(vStp03TaskON); // set position steppers
	Scheduler.startLoop(vStp04TaskON); // stepper 1
	Scheduler.startLoop(vStp05TaskON); // stepper 2
	Scheduler.startLoop(vStp06TaskON); // stepper 3
	Scheduler.startLoop(vStp07TaskON); // stepper 4
	Scheduler.startLoop(vStp08TaskON); // stepper 5
	Scheduler.startLoop(vStp09TaskON); // stepper 6
	Scheduler.startLoop(vStp10TaskON); // stepper 7
}

/*-----------------------------------------------------------*/
void loop()
{
	delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp01TaskON()
{
		digitalWrite(leds[4], task1 = !task1);
		SerialWrite();
		delay(10);  // 10ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp02TaskON()
{
		SerialRead();
		delay(10);  // 10ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp03TaskON()
{
		position();
		delay(10);  // 10ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp04TaskON()
{
		Stepper1Routine();
		delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp05TaskON()
{
		Stepper2Routine();
		delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp06TaskON()
{
		Stepper3Routine();
		delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp07TaskON()
{
		Stepper4Routine();
		delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp08TaskON()
{
		Stepper5Routine();
		delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp09TaskON()
{
		Stepper6Routine();
		delay(1); // 1ms seconds waiting
}
/*-----------------------------------------------------------*/
void vStp10TaskON()
{
		// Gripper & light
//		Scheduler.delay(1); // 2ms seconds waiting
		yield();
}
/*-----------------------------------------------------------*/
Looking good so far!

Discussions

dannyvandenheuvel wrote 01/04/2017 at 22:16 point

OK! now speeds can be independent been switched between all motors, positioning module is working smooth now.
Now looking at the best way to communicate with a seperate controller. I think a need an usb host so I can add a bluetooth dongle at it, seems the best way to use different bluetooth controllers.
Adding a usb host could be a problem for the ultratronics board because not all pins are reachable like the arduino due board. Did some google with no results at this moment. If somebody knows more, give me a hint! thanks!

  Are you sure? yes | no

Olaf Baeyens wrote 01/04/2017 at 22:35 point

How do you solve the 2 geared stepper-motors that should work together?

Th Z axis on that board has the ability to drive 2 stepper motors with one driver but I have not experience enough to see how that would work. I would assume that one stepper-motor would draw more current than the other one. In theory they get driven by the same cog so they will compensate each others speed and therefore drawn current I assume. But then again when none motor has a disconnected or break lose wire the other will draw double the amount of current now.

  Are you sure? yes | no

dannyvandenheuvel wrote 01/04/2017 at 22:41 point

Have to experiment with it, good to make me warn for it, I'll write it down :-)

  Are you sure? yes | no

Olaf Baeyens wrote 01/04/2017 at 17:27 point

They work fuluently!

  Are you sure? yes | no

brett.schenck wrote 01/04/2017 at 11:30 point

Impressive!!

  Are you sure? yes | no