View unanswered posts | View active topics It is currently Fri Jul 01, 2016 4:11 am

 Page 3 of 3 [ 43 posts ] Go to page Previous  1, 2, 3
 Print view Previous topic | Next topic
Encoders aren't changing correctly
Author Message
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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 550int Array[ARRAY_IDX_VAL];// Right Motor Encoderint Array2[ARRAY_IDX_VAL];// Left Motor Encoderint Array3[ARRAY_IDX_VAL];// Set Motor Powerunsigned long Array4[ARRAY_IDX_VAL];// Timestampint 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

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
Rookie

Joined: Thu Jan 02, 2014 11:04 pm
Posts: 15
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
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
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)

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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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 robotThanks 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
Rookie

Joined: Thu Jan 02, 2014 11:04 pm
Posts: 15
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
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)

Tue Jan 07, 2014 11:48 am
Guru

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

Tue Jan 07, 2014 3:36 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
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)

Tue Jan 07, 2014 5:54 pm
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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 variablevarPgmTime = 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 variablevarSysTime = nSysTime;  // stores the current value of nSysTime to a variable

Wed Jan 08, 2014 4:17 am
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
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)

Wed Jan 08, 2014 5:49 am
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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

Joined: Wed Jan 24, 2007 10:42 am
Posts: 620
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
Display posts from previous:  Sort by
 Page 3 of 3 [ 43 posts ] Go to page Previous  1, 2, 3

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning