View unanswered posts | View active topics It is currently Fri Oct 30, 2020 4:00 am

Reply to topic  [ 3 posts ] 
Problem with motors 
Author Message

Joined: Tue Mar 11, 2008 10:51 am
Posts: 1
Post Problem with motors
We're working on a project and a part of it is to make the robot turn a certain angle. When the robot is fully charged the code works perfectly but when its 75% charged it doesnt. The encoder value isnt reached. We browsed around on the forum and saw people have the same problem but haven't been able to solve it. Can any1 help us out?

the code looks somthing like this

int turnr(int deg)
   int encr=deg/0.195;
   nSyncedMotors = synchAB;
   nSyncedTurnRatio = -100;
   nMotorEncoderTarget[motorA] = -encr;

   motor[motorA] = -50;

   while (nMotorRunState[motorA] != runStateIdle)

      // Code gets stuck in this loop as the motor is under strain and cant reach the specified encoder target.


   nSyncedMotors = synchNone;
   motor[motorA] = 0;
   return encr;


Tue Mar 11, 2008 10:57 am

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
I'd like a little more info. In particular.

Are you trying to turn a large or small number of degrees? Is it more or less than 45 degrees?

If you change the motor speed from '-50' to '-100' does the code now work?

If you lift the robot into the air and try the program (or at least the turn function) do the motors turn OK to the expected locations. YOu can check the value of the motor encoders with the Debugger "NXT Devices" window. What this is doing is checking the performance of the motors with a much reduced friction/drag co-efficient.

Is the problem that it doesn't move at all or that it does move but the error is large? I suspect that it is the second type. If so, here's what may be happening:
1. The control algorithm uses a PID algorithm to (hopefully) smoothly move the motors to stop at the target encoder position.
2. The algorithm reduces the power level to the motors as it gets close to the target so that it should not overshoot the target.
3. If in state (2) and the firmware detects that the motors are not moving and the target is reasonably close it gives up thinking "this is the best that I can do". The logic is that the motors are not moving and a much higher power level needs to be applied to get them moving and overcome the initial static friction; this is likely to cause the motor to overshoot the target; since the motor is reasonably close to the target it simply ends.
4. Most of the time tuning the PID algorithms were performed with fully charged batteries and a lightly loaded robot. The parameters selected may prove to be too small to correct from lower battery levels and/or robots with lots of friction.
5. Another potential problem is that if the load (friction) on the two motors is not equal. Say for example one wheel is binding against axle for lots more friction and not the other one.

Let me know about the above. Meanwhile I will set up a test condition of low battery and heavy load and see what I can find.

Wed Mar 12, 2008 6:01 am
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
I can confirm that there are many problems I also got using
nMotorEncoderTarget in my navigation program.

I finally replaced all that code and wrote my own algorithms which are working absolute correctly down to fractions of a cm after many meters of going and turning.

HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Wed Mar 12, 2008 6:15 am
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.