ROBOTC.net forums
http://robotc.net/forums/

Gyro and drift
http://robotc.net/forums/viewtopic.php?f=1&t=9360
Page 1 of 1

Author:  KeesSmit [ Sat Sep 13, 2014 2:09 pm ]
Post subject:  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

Author:  Sirius [ Sun Sep 14, 2014 7:12 am ]
Post subject:  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;
}

Author:  KeesSmit [ Sun Sep 14, 2014 3:02 pm ]
Post subject:  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

Author:  Sirius [ Sun Sep 14, 2014 9:39 pm ]
Post subject:  Re: Gyro and drift

Looks like this is all good information to know.

Certainly sounds like undocumented features to me.

Author:  mightor [ Tue Sep 16, 2014 12:35 am ]
Post subject:  Re: Gyro and drift

I'll look into this!

= Xander

Author:  KeesSmit [ Sun Jun 21, 2015 3:30 pm ]
Post subject:  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

Author:  mightor [ Wed Jun 24, 2015 1:54 am ]
Post subject:  Re: Gyro and drift

Is there a reason you would not want to use the RateAndAngle mode?

= Xander

Author:  casnova [ Wed Jun 24, 2015 3:01 am ]
Post subject:  Re: Gyro and drift

I agree with the post.
Very interesting thanks for sharing. :bigthumb:




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

Author:  KeesSmit [ Wed Jun 24, 2015 4:01 am ]
Post subject:  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

Author:  mightor [ Wed Jun 24, 2015 4:07 am ]
Post subject:  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

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/