View unanswered posts | View active topics It is currently Wed Jun 26, 2019 8:51 am






Reply to topic  [ 10 posts ] 
Gyro and drift 
Author Message
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
Post Gyro and drift
Hi there,

I hope someone can help me out here. I wrote a simple test program with the Lego EV3 Gyro and two large EV3 motors. Aim is to turn the robot 360 degrees and then stop. This is my code:

Code:
#pragma config(Sensor, S4,     Gyro,           sensorEV3_Gyro)
#pragma config(Motor,  motorA,          RMotor,        tmotorEV3_Large, PIDControl, encoder)
#pragma config(Motor,  motorD,          LMotor,        tmotorEV3_Large, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma DebuggerWindows("Sensors")

task main()
{
   resetGyro(Gyro);

   // Turn Robot 360 degrees around, then stop:
   repeatUntil(getGyroDegrees(Gyro) > 360)
   {
         motor[RMotor] = -30;
         motor[LMotor] = 30;
   }
   motor[RMotor] = 0;
   motor[LMotor] = 0;
}


When I startup my robot I make sure it's standing dead still to make sure there's no drift in the gyro. Downloading the code to the bot and checking the sensors window it says there is no drfit indeed. But after running the program once, there is a terrible drift in such a way that a second time the program doesn't work anymore: the bot keeps turning around. The drift prohibits the condition GyroDegrees>360 to become true.

I did a test in the EV3 software. I built a comparable program which works fine. No matter how often I run the program, there's no drift in the gyro and the program keeps running fine. But when I choose to run the RobotC progam the drift immidiately is there!

Is there something wrong in my RobotC code or is something else going on?

Kees


Sat Sep 13, 2014 2:09 pm
Profile
Rookie

Joined: Fri Sep 20, 2013 8:39 am
Posts: 38
Post Re: Gyro and drift
Verified and did fault finding
Noticed when looking at the sensor window that the gyro kept drifting after the programme had completed
Noticed but no explanation why the motors briefly started when the programme started and before the motor commands were called
introduced a delay before the gyro reset to ensure that the system was not moving before initiating a gyro reset (1000 ms)
Removed the motor command from inside the loop
Initially inserted a 1000 ms window to allow the gyro reset to occur before the motors started
found that still had a gyro drift in the sensor window
Inserted a 2000 ms delay after the gyro reset command issued to allow gyro to calibrate - this appears to be critical

This worked for me

Code:
#pragma config(Sensor, S4,     Gyro,           sensorEV3_Gyro)
#pragma config(Motor,  motorA,          RMotor,        tmotorEV3_Large, PIDControl, encoder)
#pragma config(Motor,  motorD,          LMotor,        tmotorEV3_Large, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma DebuggerWindows("Sensors")

#pragma DebuggerWindows("EV3LCDScreen")
int Angle;

task main()
{
   eraseDisplay();
   displayCenteredTextLine(2,"gyro reset");
   sleep(1000);
   resetGyro(Gyro);
   sleep(2000);

   // Turn Robot 360 degrees around, then stop:
   Angle=getGyroDegrees(Gyro);

   eraseDisplay();
   motor[RMotor] = -30;
   motor[LMotor] = 30;
   displayCenteredTextLine(2,"rotating");
   repeatUntil(abs(Angle) > 360)
   {
      sleep(1);
      Angle=getGyroDegrees(Gyro);
      displayCenteredBigTextLine(5,"%4d",Angle);
   }

   playTone(440,10);
   motor[RMotor] = 0;
   motor[LMotor] = 0;
}


Sun Sep 14, 2014 7:12 am
Profile
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
Post Re: Gyro and drift
Hi Sirius,

Thanks for your response. I didn't think of building in a sleep directly after the resetGyro, but of course I can imagine that's required. But for one reason or another, the sleep before the resetGyro is critical as well: leaving it away still leads to drift of gyro. It has nothing to do with the motors that briefly start when the program starts. I did some further tests on that.
It was only the motor on port D that briefly starts each time the program starts. When I connect this motor on port C (and the other mother stays connected to A), this problem is solved. So it seems it has something to do with port D, I don't know if this is a known issue.
Back to the gyro and drift: connecting motors to ports C and A (so motors do not briefly start at programstart, so no movement of robot at programstart), both sleep-statements are required to avoid drift: before (or at least at programstart) and after resetGyro. Perhaps the first sleep is needed for some kind of initialisation of the gyro?

Kees


Sun Sep 14, 2014 3:02 pm
Profile
Rookie

Joined: Fri Sep 20, 2013 8:39 am
Posts: 38
Post Re: Gyro and drift
Looks like this is all good information to know.

Certainly sounds like undocumented features to me.


Sun Sep 14, 2014 9:39 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Gyro and drift
I'll look into this!

= 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]


Tue Sep 16, 2014 12:35 am
Profile WWW
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
Post Re: Gyro and drift
Hi all,

Did some Gyro-tests with v4.32 today to see if above described effects still occur. This is what I found (not related to this version of RobotC). You only need to use a sleep-statement in the beginning of your program when the mode of the gyro isn't RateAndAngle, which is the default mode I presume. When you set the mode to Angle (by using Motor en Sensor Setup) then the program needs time at startup to change gyro mode from RateAndAngle to Angle. You can see this during runtime in de sensors window: at startup it displays a nonvalid number and after 1 or 2 seconds is displays valid numbers. So you need to use a sleep(2000) or so. But if you use RateAndAngle mode, then no sleep statements are necessary, which makes the program much faster.

Hope this is usefull information :D .

Gr. Kees


Sun Jun 21, 2015 3:30 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Gyro and drift
Is there a reason you would not want to use the RateAndAngle mode?

= 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]


Wed Jun 24, 2015 1:54 am
Profile WWW
Rookie

Joined: Wed Jun 24, 2015 2:59 am
Posts: 1
Post Re: Gyro and drift
I agree with the post.
Very interesting thanks for sharing. :bigthumb:




ระบบที่รองรับการถ่ายทอดสดโดยตรงจาก คาสิโนจริงๆ ได้ที่นี่ รอยัล1688ออนไลน์


Wed Jun 24, 2015 3:01 am
Profile
Rookie
User avatar

Joined: Wed Jun 04, 2014 4:06 pm
Posts: 30
Location: Margraten, The Netherlands
Post Re: Gyro and drift
mightor wrote:
Is there a reason you would not want to use the RateAndAngle mode?

= Xander


No, you're right, there isn't :D


Wed Jun 24, 2015 4:01 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Gyro and drift
I was legitimately asking because I couldn't really see a reason why you wouldn't want access to both without incurring any kind of performance penalty :)

= 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]


Wed Jun 24, 2015 4:07 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.