View unanswered posts | View active topics It is currently Sat Oct 25, 2014 2:15 pm






Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3
Encoders aren't changing correctly 
Author Message
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoders aren't changing correctly
Like I said, your loop time is not constant. You really need to divide the delta by time to get the real speed.
Code:
#define ARRAY_IDX_VAL 550
int Array[ARRAY_IDX_VAL];// Right Motor Encoder
int Array2[ARRAY_IDX_VAL];// Left Motor Encoder
int Array3[ARRAY_IDX_VAL];// Set Motor Power
unsigned long Array4[ARRAY_IDX_VAL];// Timestamp

int Index = 0;

task main()
{
   int i;
   int c;
   int d;

   clearDebugStream();

   nMotorEncoder[RightMotor] = 0;
   nMotorEncoder[LeftMotor] = 0;

   for(i = 0; I<=100; i = i + 5)
   {
       motor[RightMotor] = i;
       motor[LeftMotor] = i;
       for(c = 0; c<10; c++)
       {
           wait1Msec(30);
           Array[Index] = nMotorEncoder[RightMotor];
           Array2[Index] = nMotorEncoder[LeftMotor];
           Array3[Index] = motor[RightMotor];
                Array4[iIndex] = nPgmTime;
           Index++;
       }
   }
   for(i = 100; i>=0; i = i - 5)
   {
       motor[RightMotor] = i;
       motor[LeftMotor] = i;
       for(d = 0; d<10; d++)
       {
           wait1Msec(30);
           Array[Index] = nMotorEncoder[RightMotor];
           Array2[Index] = nMotorEncoder[LeftMotor];
           Array3[Index] = motor[RightMotor];
                Array4[iIndex] = nPgmTime;
           Index++;
       }
   }
   wait1Msec(500);
   motor[RightMotor] = 0;
   motor[LeftMotor] = 0;
   for(Index = 0; Index<ARRAY_IDX_VAL; Index++)
   {
       wait1Msec(10);
       writeDebugStream("%d,", Index);
       wait1Msec(10);
       writeDebugStream("%d,", Array[Index]);
       wait1Msec(10);
       writeDebugStream("%d,", Array2[Index]);
       wait1Msec(10);
       writeDebugStream("%d\n", Array3[Index]);
       wait1Msec(10);
       writeDebugStream("%d\n", Array4[Index]);
   }
}

Your "rate" should be calculated by (Array[Index] - Array[Index - 1])*1000/Array4[Index]
Also note that even with this calculation, the data should look reasonable but may still be fluctuating a little bit probably due to unbalanced wheels etc.


Sat Jan 04, 2014 10:26 pm
Profile
Rookie
User avatar

Joined: Thu Jan 02, 2014 11:04 pm
Posts: 15
Post Re: Encoders aren't changing correctly
Thank you. I will try the new equation. also i don't believe it is because of an unbalanced wheel because we are using treads on our robot

Thanks again,
kitbear23


Mon Jan 06, 2014 6:18 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Encoders aren't changing correctly
there is nothing harder to balance or to synchronise or do odometry stuff with like dealing with tank treads.
;)

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


Last edited by Ford Prefect on Tue Jan 07, 2014 12:46 pm, edited 1 time in total.



Mon Jan 06, 2014 7:01 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoders aren't changing correctly
kitbear23 wrote:
Thank you. I will try the new equation. also i don't believe it is because of an unbalanced wheel because we are using treads on our robot

Thanks again,
kitbear23

You will be surprised. In the past, I have logged data that has a periodic speed slow down. It turns out the motor has some mechanical binding only at a certain angle. So the motor turns fine until it hits that angle and it slowed down a bit. And it showed in the data log.


Mon Jan 06, 2014 8:09 pm
Profile
Rookie
User avatar

Joined: Thu Jan 02, 2014 11:04 pm
Posts: 15
Post Re: Encoders aren't changing correctly
Ok so there might be something mechanically wrong in the motors or something? that kind of explains it because it fluctuates a little when we go slow but the faster it gets the more fluctuation.


Mon Jan 06, 2014 8:54 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoders aren't changing correctly
You should be able to turn the wheels by hand and feel the resistance at a certain angle.


Mon Jan 06, 2014 8:57 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Encoders aren't changing correctly
sry, OT:
what is nPgmTime ?

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


Tue Jan 07, 2014 11:48 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoders aren't changing correctly
nPgmTime is the system timestamp in msec.


Tue Jan 07, 2014 3:36 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Encoders aren't changing correctly
and what is nSysTime opposite to it?


aah - I assume:

nSysTime is time since the sys_timer (the NXT) was switched on
(sort of ANSI C: time(0) )

nPgmTime is time since the program was started
(ANSI C: clock() )

correct?

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


Tue Jan 07, 2014 5:54 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoders aren't changing correctly
Direct cut and paste from RobotC help:
Code:
nPgmTime const long nPgmTime 
(long) This variable contains the value of the lower 16-bits of the internal 1-msec clock. This variable is reset when user program first starts running. This clock does not increment when the program is in a debugger "suspended" state which is useful during single step debugging as the clock does not increment. 
int varPgmTime;         // creates a variable
varPgmTime = nPgmTime;  // stores the current value of nPgmTime to a variable

nSysTime const long nSysTime 
(long) This variable contains the value of the lower 16-bits of the internal 1-msec clock. This variable is reset when NXT is first powered on. 
int varSysTime;         // creates a variable
varSysTime = nSysTime;  // stores the current value of nSysTime to a variable
 


Wed Jan 08, 2014 4:17 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Encoders aren't changing correctly
thank you!

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


Wed Jan 08, 2014 5:49 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: Encoders aren't changing correctly
BTW, I don't quite trust the documentation I cut and pasted because I know for a fact that nPgmTime is actually unsigned long and I believe it's actually 32-bit not just the low 16-bit. You can easily test that though. If it were really 16-bit even unsigned, it would roll-over in 65 second. I am very sure the time did not roll-over in a little over one minute. My intention of cutting and pasting the doc was to show you the difference between nPgmTime and nSysTime that one is cumulative since powering up and one is cumulative since program start. That's all you should trust.


Wed Jan 08, 2014 5:57 am
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 613
Post Re: Encoders aren't changing correctly
Everything used to be 16-bits until 3.0 and the overhaul with pointers/etc. They're now 32-bits.

We also looked at making int's by default 32bits, but too many weird things were occurring so we forced them back to 16-bits for the time being.

We're overhauling the help documentation with the loss of data on the Wiki - so we'll be reviewing all of this content in the coming months.

Thanks.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Thu Jan 16, 2014 3:52 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 43 posts ]  Go to page Previous  1, 2, 3

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.