![]() |
[FTC]: I really need help on gyro!!!
so my team is trying to figure out how to use a gyro sensor. i am a new Programmer and i have no idea what im doing with this! can someone please give me some guidance? ASAP!!
|
Re: [FTC]: I really need help on gyro!!!
They gyro sensor reads the CHANGE in degrees of the rotation of your sensor. in order to get the number of degrees your robot has traveled, you need to integrate it over the number of cycles.
Start first by calibrating your gyro sensor to the current heading. My Gyro sensor's name is HTGYRO Code:
HTGYROstartCal(HTGYRO);now we need to create variables for the current heading and the elapsed time Code:
float heading = 0.0;Code:
while(true)Then we take the heading (currently 0) and add the degrees rotated by the change in time (comes in as milliseconds, we divide by 1000 to change to seconds). Code:
prevTime = currTime;Then we put in the logic for looking at the direction to turn. Code:
if(turningRight) //If you want to turn to the rightThe buffer values are put in to ensure you dont have the "jiggle" that often happens because the robot shoots past the target while turning then has to compensate backwards again. This is essentially a "dead-zone" where the robot will stop moving if you are within a few degrees of the target. So, the entire function I have written is as follows: Code:
void gyroTurn(int target, int buffer, int drivePower, bool turningRight, int waitTime)Code:
turnLeft(drivePower);Code:
turnRight(drivePower); |
Re: [FTC]: I really need help on gyro!!!
I realize that I forgot a few things and for some reason I cannot edit my OP...
at the beginning of your code, you will need to import the HTGYRO driver written by Xander Soldaat, the writer of all the RobotC 3rd Party Sensor Drivers you can find this file in the Sample Programs->3rd Party Sensor Drivers->drivers folder and can import it using: #import "HYGYRO-driver.h"; I also have one error in my code... where it says "direction == 1" and "direction == 2" it should be "turningRight" and "turningRight == false" If you have any other question be sure to let me know (Sorry mods for the DP but I couldnt edit my original post :/ ) |
| All times are GMT -5. The time now is 19:08. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi