View unanswered posts | View active topics It is currently Mon Sep 21, 2020 3:00 pm






Reply to topic  [ 11 posts ] 
nMotorEncoderTarget accuracy 
Author Message
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post nMotorEncoderTarget accuracy
I have problem using nMotorEncoderTarget. I did the following and when the motors stopped, the encoder values are always short of 9000. Every time you run it, it is not consistently the same value. So the question is: does nMotorEncoderTarget uses PID? If it does, it should be right on the target instead of being short of 9000. Can somebody explain how nMotorEncoderTarget works? Thanks.

Code:
  nMotorEncoder[motorLeft] = 0;
  nMotorEncoder[motorRight] = 0;
  nMotorEncoderTarget[motorLeft] = 9000;
  nMotorEncoderTarget[motorRight] = 9000;
  motor[motorLeft] = 100;
  motor[motorRight] = 100;
  while (nMotorRunState[motorLeft] != runStateIdle || nMotorRunState[motorRight] != runStateIdle)
  {
  }
  nxtDisplayTextLine(0, "LEnc=%d,REnc=%d", nMotorEncoder[motorLeft], nMotorEncoder[motorRight]);


Mon Dec 14, 2009 6:17 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: nMotorEncoderTarget accuracy
How much short are you? 5? 20? 100?

Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Dec 14, 2009 6:38 am
Profile WWW
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: nMotorEncoderTarget accuracy
Very short, usually over 100. For example, I've got 8700 before.


Mon Dec 14, 2009 1:57 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: nMotorEncoderTarget accuracy
If you believe this to be a bug, send a mail to support@robotc.net with a description of the problem and preferably a sample program that reproduces the problem.

Thanks,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Dec 14, 2009 2:48 pm
Profile WWW
Expert
User avatar

Joined: Mon Oct 06, 2008 6:30 pm
Posts: 176
Location: Netherlands
Post Re: nMotorEncoderTarget accuracy
Are the motors synched? Maybe this interferes with nMotorEncoderTarget.

_________________
My most recent blog: A grain of sugar


Mon Dec 14, 2009 7:03 pm
Profile WWW
Rookie
User avatar

Joined: Wed Nov 11, 2009 9:57 pm
Posts: 12
Post Re: nMotorEncoderTarget accuracy
Does it make a difference if you use a speed lower than 100, like 75 for example. I believe the motor PID controls don't work well with speeds near 100.


Mon Dec 14, 2009 9:49 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Post Re: nMotorEncoderTarget accuracy
Yes, the run to encode uses a PID algorithm to precisely stop at the target position. "At the target position" should be within a few encoder counts of the desired position.

Speed regulation at 100% speed can be unreliable. Here's why:
  • Maximum "raw" unregulated speed is something like 1200 encoder counts per second. This is for a unloaded motor at full battery charge.
  • 100% speed regulation tries to maintain, via a PID algorith, a speed of about 1000 counts per second.
  • The remaining 200 counts per second capability is to allow the speed regulation to "do its work".
  • Suppose the batteries are near discharge, you're going up a hill, the motor is heavily loaded, this motor is not as strong as average, etc. All of these can result in slower than expected speed.
  • PID provides feedback on the actual speed of the motor to adjust the nominal power up or down to compensate for the above factors.
Now if you're using 100% on a heavily loaded motor and batteries are near discharge it may only bet able to get 975 (or less) counts per second at full power. There's no way for it to ever achieve the nominal 1000 counts per second expected at full power!

Anyway this likely does not explain your observations. Because when you're moving to a specific encode position, the speed regulation is used until the motor gets close to the target. Then a different PID algorithm -- distance based rather than speed based -- kicks ins where the algorithm tries to bring the motor to a smooth stop at the desired position.

I have never seen the "move to encoder" fail so badly and be off by 100 counts. Generally it stops within a few counts. And the algorithm actually stops the motors if they are really close (i.e. within a few counts) to the target and moving very slowly.

The PID algorithms use a single set of PID "error factors" (i.e. weighting values) to calculate the power settings. These have been found to work across a wide range of robot configuration -- i.e. lightly and heavily loaded. It's pretty time consuming to get these factors working well.. There's one set of factors for speed regulation and another set for position regulation.

You should post your complete program if you want more assitance. One thing to watch out for is that the motor drivers keep a "shadow" position of where you wanted the robot to move vs where it actually is. An example helps illustrate this:
  • Suppose you tell the motor to move 100 counts and it only moves 98 counts instead.
  • Repeat this 10 times and the accumulated error is 20 counts.
  • With the "shadow" count it has remembered that you wanted to be at 100 but was only at 98. So when you tell it to move another 100 counts it tries to move to 200 and not 198 -- i.e. 102 counts and not just 100. This eliminates the accumulation of errors.


Tue Dec 15, 2009 1:01 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: nMotorEncoderTarget accuracy
Unfortunately, we just finished our regional competition, so I am not sure if I have access to the robot to reproduce the problem. I will try to reproduce the problem with my own little NXT robot but again the environment is different so I am not sure the problem will show. The competition robot uses Tetrix motor controller and encoders whereas my NXT robot is using the NXT motors.

In any case, for the competition, I implemented my own PID control which worked very well. I tuned my own PID constants and it was running very accurately.


Tue Dec 15, 2009 3:56 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Post Re: nMotorEncoderTarget accuracy
MHTS wrote:
Unfortunately, we just finished our regional competition, so I am not sure if I have access to the robot to reproduce the problem. I will try to reproduce the problem with my own little NXT robot but again the environment is different so I am not sure the problem will show. The competition robot uses Tetrix motor controller and encoders whereas my NXT robot is using the NXT motors.

In any case, for the competition, I implemented my own PID control which worked very well. I tuned my own PID constants and it was running very accurately.

TETRIX motors? My explanation was written for the LEGO NXT motors.

There's a related post that I did yesterday that explains some of the differences on how the TETRIX motor control vs the LEGO motors. It's probably in the "FTC Programming" forum.


Tue Dec 15, 2009 7:19 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: nMotorEncoderTarget accuracy
Any chance to post a link to the related post? I tried to search for it (not too hard though) but couldn't find it.


Tue Dec 15, 2009 4:00 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
Post Re: nMotorEncoderTarget accuracy
MHTS wrote:
Any chance to post a link to the related post? I tried to search for it (not too hard though) but couldn't find it.

Try this link http://www.robotc.net/forums/viewtopic.php?f=46&t=2038.


Tue Dec 15, 2009 8:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.