Where is the RobotC source code for VEX IQ sensor default functionality?
When the gyro is plugged in and when I drive with joystick, the robot will automatically snap back to original orientation very fast and accurately.
I would like to understand how that gyro behavior is implemented, and reference it for my own RobotC programming of gyro.
Hi johnslai,
When the Gyro Sensor first boots up, it starts at 0 degrees, and can increase up to 359.999 degrees before it rolls over back to 0 degrees. If you spin the sensor in a counter-clockwise direction, the angle will count upwards. When you spin the sensor in a clockwise direction, the angle will count down. This follows the right hand rule - hence the counter-clockwise arrow with the “+” sign printed on the Gyro Sensor.
You can see this if you plug in a Gyro Sensor to your Robot Brain, turn on the Robot Brain, press [X] button to get to the Settings menu, then enter the Device Info menu. You can see the Gyro readings change in real time.
To make your own code do the same, the very basic pseudocode for this behavior is:
If gyro angle is between 0 and 180 degrees
{
Turn right until gyro angle = 0
}
else if gyro angle is between 180 degrees and 360 degrees
{
Turn left until gyro angle = 0
}
Regards,
- Art