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

Gyro
http://robotc.net/forums/viewtopic.php?f=11&t=3262
Page 1 of 1

Author:  Sman [ Tue May 10, 2011 3:22 pm ]
Post subject:  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 !!*//

#include"Functions.c"
task main ()
{

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

turn_left();


}
stopallmotors();

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.

Thanks,
Lance

Author:  MHTS [ Tue May 10, 2011 3:50 pm ]
Post subject:  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.

Author:  jbflot [ Tue May 10, 2011 4:49 pm ]
Post subject:  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.

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