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 !!*//

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

Tue May 10, 2011 3:22 pm

MHTS

Guru

Joined: Sun Nov 15, 2009 5:46 amPosts: 1499

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

jbflot

Site Admin

Joined: Tue May 15, 2007 9:02 amPosts: 406

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

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum