Page 1 of 1

Programmatically synchronizing two motors

Posted: 18 Oct 2010, 18:11
by alexgd
Hi everybody,

nice to find a substitute to the old NXTasy forum (where I was named Enciladus).

I am currently working on a LEGO Mindstorms project and I am programming the robots using nxtOSEK and Eclipse. I have to use a language that supports classes. As I have noticed so far, there is no function implemented, that enables to servos to drive synchronized like the OnFwdSync method in NXC. I need this, because the variation of the motors from each other is getting to big.

Could you give me some suggestions perhaps? I have tried to read out the tacho count and adjust the speed of the slow motor manually, but therefore I have to know what distance the robot drove, which is rather difficult to know, since the robot drives on different surfaces.

I think one good way would be to read out the currently applied voltage of the servo and adjust them, but I can't see a way with the ECRobot API which nxtOSEK uses.

I would be glad for any suggestions you guys might have.

Greetings, Alex

Re: Programmatically synchronizing two motors

Posted: 18 Oct 2010, 21:46
by schodet
alexgd wrote:I am currently working on a LEGO Mindstorms project and I am programming the robots using nxtOSEK and Eclipse. I have to use a language that supports classes. As I have noticed so far, there is no function implemented, that enables to servos to drive synchronized like the OnFwdSync method in NXC. I need this, because the variation of the motors from each other is getting to big.
Could you give me some suggestions perhaps? I have tried to read out the tacho count and adjust the speed of the slow motor manually, but therefore I have to know what distance the robot drove, which is rather difficult to know, since the robot drives on different surfaces.
You can use a PID controller to make the difference between the two motors tacho count null.

Basically:

Code: Select all

error = left_count - right_count
power_diff = kP * error   # this is a P controller, it may be sufficient, or you can add I and D.
power_left = power - power_diff
power_right = power + power_diff
That is actually what is done in the LEGO firmware.

Re: Programmatically synchronizing two motors

Posted: 19 Oct 2010, 16:10
by alexgd
thanks a lot!

I will give it a try.