3

Currently the gyro sensor connected to the EV3 brick doesn't really work. whenever the gyro is attempted to be used the robot will just sit and spin once it gets to where it needs to use the gyro. Any suggestions would be appreciated

forward(4.8, rotations, 50);
wait(.5, seconds);
resetGyro(S2);
setMotor(motorB, 35);
setMotor(motorC, -35);
waitUntil (getGyroDegrees(gyroSensor) > 80);
forward(2, rotations, 50);
wait(.5, seconds);
resetGyro(S2);
setMotor(motorB, 35);
setMotor(motorC, -35);
waitUntil (getGyroDegrees(gyroSensor) > 80);
forward(4.8, rotations, 50);
wait(.5, seconds);
resetGyro(S2);
setMotor(motorB, -35);
setMotor(motorC, 35);
waitUntil (getGyroDegrees(gyroSensor) > 80);
forward(2, rotations, 50);
wait(.5, seconds);
resetGyro(S2);
setMotor(motorB, -35);
setMotor(motorC, 35);
waitUntil (getGyroDegrees(gyroSensor) > 80);
4

1 Answer 1

2

Debugging tip: Inside of the wait loop, print the gyro angle on the screen so that you can see what the actual value is.


In your code, I see...

setMotor(motorB, 35);
setMotor(motorC, -35);

...which presumably causes the robot to rotate clockwise. And also...

setMotor(motorB, -35);
setMotor(motorC, 35);

...which presumably rotates the robot counter clockwise. But, you always have...

waitUntil (getGyroDegrees(gyroSensor) > 80);

I would assume that when you rotate counter-clockwise that the angle gets smaller (or it could be the opposite depending on which way the gyro is oriented). In this case, I would thing you need...

waitUntil (getGyroDegrees(gyroSensor) < -80);

...instead since the value will be decreasing from 0.


You also need to be aware of gyro drift that can cause the angle to change even when the robot is not moving. Calling resetGyro(S2); resets the angle reading to 0, but it probably does not "calibrate" the sensor to eliminate drift. Common ways of doing this are unplugging the sensor and plugging it back it and changing the "mode" of the sensor (e.g. by reading rate and then reading angle).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.