View unanswered posts | View active topics It is currently Thu Oct 30, 2014 8:46 am






Reply to topic  [ 12 posts ] 
Problems with the motor encoder 
Author Message
Rookie

Joined: Sun Aug 12, 2007 3:18 pm
Posts: 38
Post Problems with the motor encoder
Hi

I want to develop a program that moves the motor to diverse positions in forward and backward. I do not have problems when it is in forward but yes in backward. I am trying to correct the difference when the nEncodertarget is <0 , but I have some problems with the encoders.

In he program: when the nEncoderTarget is -200, the result is Tach User is -281 but nMotorEncoder [motor] read -200 (it isn’t the real position), so I can’t correct the diference.

Witch tach read nMotorEncoder [motor]?

Thanks

Image

Code:
//*!!Motor,  motorC,             motor__, tmotorNxtEncoderClosedLoop,           !!*//
//*!!                                                                            !!*//
//*!!Start automatically generated configuration code.                           !!*//
const tMotor   motor__             = (tMotor) motorC; //tmotorNxtEncoderClosedLoop //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration.                !!*//

task main()
{
   int position,difference;

   nMotorEncoder[motor__]=0;
   nMotorEncoderTarget[motor__]=-200;
   motor[motorC]=-100;
   while(nMotorRunState[motor__] !=runStateIdle);

   eraseDisplay();
  position = nMotorEncoder[motor__];


        //nMotorEncoder[motor__]=0; The result is the same with this line and wihtout it

   nxtDisplayString(4, "%d",position );
   wait10Msec(200);

   nMotorEncoderTarget[motor__]=200;
   motor[motorC]=80;
   while(nMotorRunState[motor__] !=runStateIdle);

  eraseDisplay();
  position = nMotorEncoder[motor__];
   nxtDisplayString(4, "%d",position );
   wait10Msec(500);

}

_________________
Image http://lrobotikas.net English version


Fri Jul 04, 2008 5:02 am
Profile WWW
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post 
Hi

If you change the line:
nMotorEncoderTarget[motor__]=-200;
to be
nMotorEncoderTarget[motor__]= 200; (no negative sign)
you will get a more accurate result. Setting the nMotorEncoderTarget to a negative value means the motor will coast or float rather than braking after it reaches the desired target.


Sat Jul 05, 2008 4:42 am
Profile WWW
Expert
User avatar

Joined: Fri Nov 09, 2007 4:51 am
Posts: 121
Location: Hungary, Europe
Post 
Abbeyjean wrote:
Setting the nMotorEncoderTarget to a negative value means the motor will coast or float rather than braking after it reaches the desired target.


wow, how did you find it out?

is that a bug or a feature?


Sat Jul 05, 2008 7:48 am
Profile
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post 
It's a feature I guess as it is mentioned in the documentation.


Sat Jul 05, 2008 1:23 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
Actually, to my opinion, this "feature" is a big fat BUG ! :evil:

_________________
regards,
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)}


Sat Jul 05, 2008 1:44 pm
Profile
Rookie

Joined: Mon Oct 29, 2007 4:25 pm
Posts: 7
Location: Potsdam, Germany
Post 
Ford Prefect wrote:
Actually, to my opinion, this "feature" is a big fat BUG ! :evil:


I knew that bugs simply are undocumented features.
Now, documented features turn into bugs ;-) ?

I stopped to judge the motor control by my expectation as how motor control should work. For my application, precise position control is required. Initially, I expected the nMotorEncoderTarget being of use for that. However, even after finding out that these values are not absolute targets (encoder positions that the PID tries to reach) but count from the current encoder position, there still is the drift due to overshoot.

Still, the nMotorEncoder value is my friend, based on which a simple PD position control can be implemented (works fine for me and has been posted if I remember correctly).

MK


Sat Jul 05, 2008 5:03 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
Quote:
It's a feature I guess as it is mentioned in the documentation


where in the documentation is this stated?

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Fri Jul 11, 2008 12:05 am
Profile WWW
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post 
Hi

It is in the section 'Motors Overview' under 'Moving to a Specific Encoder Value'
Quote:
You can move a motor a specific amount with the variable nMotorEncoderTarget[]. This indicates the number of encoder ticks to move. If you specify a positive value the motor will slow to a stop at this position. A negative value will leave the motor in coast / float mode when the encoder position is reached.


Fri Jul 11, 2008 3:47 am
Profile WWW
Rookie

Joined: Sun Aug 12, 2007 3:18 pm
Posts: 38
Post 
My last solution:
Code:
if (Turngrades> 0)
       {
          nMotorEncoderTarget[motorA] = Turngrades;
         motor[motorA] = 100;
         while (nMotorRunState[motorA] != runStateIdle);
       }
       else
       {
           bMotorReflected[motorA] = true;
           nMotorEncoder[motorA]=0;
           nMotorEncoderTarget[motorA] = abs(Turngrades);
          motor[motorA] = 100;
          while (nMotorRunState[motorA] != runStateIdle);
          bMotorReflected[motorA] = false;
       }

With "bMotorReflected[motorA] = true" the encodertarget always is positive. It runs fine.

_________________
Image http://lrobotikas.net English version


Fri Jul 11, 2008 5:55 pm
Profile WWW
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post 
Hi

You could cut this code down to 3 lines if you wanted.

Code:
nMotorEncoderTarget[motorA] = abs(Turngrades);
motor[motorA] = sgn(Turngrades) * 100;
while (nMotorRunState[motorA] != runStateIdle);


Sat Jul 12, 2008 3:02 am
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
or forget about the nMotorEncoderTarget and runstates etc and do it this way, simple and stupid:

Code:
int target; int speed=100;
while (target!=nMotorEncoder[motorA]) {
  motor[motorA] = sgn( target-nMotorEncoder[motorA])*speed;
}
else motor[motorA]=0;


maybe you wish to make the motor a little slower if is it's getting close to the target, you can add to the while loop:
Code:
if (abs(target-nMotorEncoder[motorA])<10) speed=30; // or sth like that

_________________
regards,
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)}


Sat Jul 12, 2008 5:11 am
Profile
Rookie

Joined: Sun Aug 12, 2007 3:18 pm
Posts: 38
Post 
Thanks

it runs fine

Abbeyjean wrote:
Hi

You could cut this code down to 3 lines if you wanted.

Code:
nMotorEncoderTarget[motorA] = abs(Turngrades);
motor[motorA] = sgn(Turngrades) * 100;
while (nMotorRunState[motorA] != runStateIdle);

_________________
Image http://lrobotikas.net English version


Sat Jul 12, 2008 11:29 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.