Announcement

Collapse
No announcement yet.

Gyro Sensor Gives Inconsistent Readings

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Gyro Sensor Gives Inconsistent Readings

    I'm currently trying to program a turn function for our robot that uses the gyro sensor for autonomous. While the gyro makes accurate turns most of the time, about a quarter of the time I run the testing op mode, the sensor's integrated z-value (and heading, I believe) seem to be much less sensitive to movement than they should be, resulting in turns being twice as wide as they should be. I couldn't find any pattern for when this happens, but when it does, it happens for the entire duration of the op mode. It also seems to happen regardless of whether or not I calibrate the gyro sensor or reset its integrated z-value.

    Has anyone else had an issue similar to ours? Is this a software problem, or a problem with the sensor/sensor module?

    Our testing op mode.
    Our turnng method.

  • #2
    Originally posted by Crorem View Post
    I'm currently trying to program a turn function for our robot that uses the gyro sensor for autonomous. While the gyro makes accurate turns most of the time, about a quarter of the time I run the testing op mode, the sensor's integrated z-value (and heading, I believe) seem to be much less sensitive to movement than they should be, resulting in turns being twice as wide as they should be. I couldn't find any pattern for when this happens, but when it does, it happens for the entire duration of the op mode. It also seems to happen regardless of whether or not I calibrate the gyro sensor or reset its integrated z-value.

    Has anyone else had an issue similar to ours? Is this a software problem, or a problem with the sensor/sensor module?

    Our testing op mode.
    Our turnng method.
    I can't see a specific problem in the code.
    I assume the diagnostics indicate that the final angle is correct, but it's just turned too much?
    Do you see any delay in the angle starting to change when the robot turns? You could put the robot up on a turntable and spin by hand to see where the error is occuring...

    I do notice that you don't wait a hardware cycle after setting the motors to zero, but I don't see this as a critical problem if you eventually allow time for the command to execute.

    I did notice that you are concerned about overshoot, since you have a rev 2 version that only moves 90% of the requested angle.
    Have you considered doing something that slows down when it approaches the desired heading?

    I threw this together as an example. There are probably some syntax errors in there.
    Although more sophisticated it's actually simpler code.
    You can tweak the GAIN to vary how soon the bot starts slowing down.

    Code:
    public void turnGyro(int deg, double speed) throws InterruptedException // Pos Values, turn right
    {
    	int 	gyroTarget = gyro.getIntegratedZValue() + deg;
    	int 	error = deg;
    	int 	loopnum = 0;
    	double 	power;
    	
    	int 	TOLERANCE = 2;     // Two degrees is close enough
    	double	P_GAIN	   = 0.1;   // Use full power when more than 10 degrees from target heading
    	
    	// keep looping while not close enough to target
    	while(Math.abs(error) > TOLERANCE) 
    	{
    		// Apply Proportional gain to error
    		power = Range.clip(error * P_GAIN, -1, 1) ;
    
    		// Spin based on desired power		
    		driveLeft .setPower( power);
    		driveRight.setPower(-power);
    		waitOneFullHardwareCycle();
    
    		error = gyroTarget - gyro.getIntegratedZValue()
    		loopnum++;
    
    		// Display status
    		telemetry.addData("Target: ", gyroTarget);
    		telemetry.addData("IZ-Value", gyro.getIntegratedZValue());
    		telemetry.addData("Power #: ", power);
    		telemetry.addData("Loop #: ", loopnum);
    	}
    
    	// We're done.  Stop motors.
    	driveLeft .setPower(0);
    	driveRight.setPower(0);
    	waitOneFullHardwareCycle();
    }

    Comment


    • #3
      One thing I would caution about your code is that you did a gyro calibration in the resetGyro() method and you called resetGyro() in a lot of your turnXXX methods. Gyro calibration takes time and requires the robot be stationary for a period of time. If that's not true, you will screw up calibration and cause inaccuracy. I would recommend you only do calibration in your initializing and nowhere else. There is no reason to calibrate the gyro multiple times.

      Comment


      • #4
        Originally posted by Philbot
        I can't see a specific problem in the code.
        I assume the diagnostics indicate that the final angle is correct, but it's just turned too much?
        Do you see any delay in the angle starting to change when the robot turns? You could put the robot up on a turntable and spin by hand to see where the error is occuring...
        That's correct, on the occasions where the sensor is bugged, the heading and integrated z-value of the gyro sensor do not match up with the actual angle of the turn.
        I don't believe that there's any delay in the angle changing. The integrated z-value starts to change pretty much immediately after the robot starts turning, whether or not the sensor is bugged.

        Originally posted by Philbot
        I did notice that you are concerned about overshoot, since you have a rev 2 version that only moves 90% of the requested angle.
        Have you considered doing something that slows down when it approaches the desired heading?
        I have been planning on implementing something to that effect, but I felt it was necessary to fix the gyro sensor first, so I just put in that quick fix.
        Thank you for the example code, though. I'll use that once this glitch is fixed.

        Originally posted by mikets
        One thing I would caution about your code is that you did a gyro calibration in the resetGyro() method and you called resetGyro() in a lot of your turnXXX methods. Gyro calibration takes time and requires the robot be stationary for a period of time. If that's not true, you will screw up calibration and cause inaccuracy. I would recommend you only do calibration in your initializing and nowhere else. There is no reason to calibrate the gyro multiple times.
        Got it, we'll avoid doing that in the future. I don't think that's the problem with the sensor, unfortunately, since turnGyro2() doesn't have any resetGyro() calls and that's what''s being used in the testing op mode.

        Comment


        • #5
          Our programmers (and operators) have been doing a lot of additional coding to compensate for gyro drift. The long delay that sometimes occurs between setting up the robot for autonomous and actually running (someone has a radio issue, or delays in setting the field) were allowing considerable drift to factor into our movements. Make sure in your testing that you reset/calibrate the gyro (likely during init) and then MONITOR it for some time (30-60 seconds) to ensure it's not drifting. Even after multiple calibrations, we sometimes are getting 5+ degrees per minute drift sitting still (i.e., calibrate and wait). We've even swapped to a second gyro but it shows the same tendencies.

          Oddly enough, if we encounter issues where the drift won't stop even after multiple calibrations, a somewhat sharp tap on the side of the robot will frequently allow the next calibration to hold zero. While I know how these MEMS devices are constructed at the chip level, it seems odd that this procedure would be impactful (no pun intended), but it does.
          Technical Coach, Newton Busters FTC 10138, FLL 3077
          Chicago 'burbs, IL

          Comment

          Working...
          X