View unanswered posts | View active topics It is currently Fri Jul 28, 2017 11:07 am

Reply to topic  [ 3 posts ] 
Author Message

Joined: Tue May 10, 2011 3:00 pm
Posts: 1
Post Gyro
Hi I am a Vex programmer and I was wondering. If there is any VEX sample code for the Gyro.
The problem that I have with the gyro is that it has a max value of about 4095. So if I say add 500 to the current position, and the gyro is currently at the value 4000 then the robot will turn infinitely.
Here is my code:
#pragma config(Sensor, in1, guyo, sensorGyro)
#pragma config(Motor, port1, , tmotorNormal, openLoop)
#pragma config(Motor, port2, left, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port3, right, tmotorNormal, openLoop)
#pragma config(Motor, port6, port6, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port7, port7, tmotorNormal, openLoop, reversed)
#pragma config(Motor, port8, port8, tmotorNormal, openLoop)
#pragma config(Motor, port9, port9, tmotorNormal, openLoop)
#pragma config(Motor, port10, Claw, tmotorNormal, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main ()

int current_pos = SensorValue[guyo];
int final = current_pos + 500;
SensorValue[guyo] =0;
while(SensorValue[guyo] <= final)



I also figured out that you can clear a gyro. But the gyro cannot have a negative value. So in my case I can only turn right.


Tue May 10, 2011 3:22 pm
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Gyro
I know NXT but don't know anything about VEX. How gyro works should be the same on both though. Gyro gives you turn rate, not position. If you need to get position, you need to integrate the gyro reading against time. Your code is using the gyro reading as position which is wrong. Think of the gyro reading as the angular velocity (how fast it is turning). If you add 500 to it, you just tell it to turn faster.

Tue May 10, 2011 3:50 pm
Site Admin
Site Admin

Joined: Tue May 15, 2007 9:02 am
Posts: 409
Post Re: Gyro
Hi Lance,

You could think of the gyro like a compass, that rolls over from 0 to 360 and vice versa. Instead of writing conditions that wait for the sensor value to be ">" or "<" as it turns, you could use "!=", so that it looks for a very specific number, regardless of the direction it's turning.

Also, if you want to increment your value, but you go past the sensor limits, you can write an equation to take of that. For example: position = (position + 500) % 4098

The % operator will give you the remainder of the equation.

Jesse Flot
CMU Robotics Academy
ROBOTC Support

Tue May 10, 2011 4:49 pm
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.