Hi, for some reason my gyro turn doesn’t work as its supposed to, I made a simple turn function using the gyro but when I tell it to turn 90 degrees it turned 360, I even tried changing the gyro itself but it was no different.
Here’s the code
void turnLeft(float d, int v){
float oldgyro=giro.rotation();
while(giro.rotation() > oldgyro-d){
turn(-v);
}
brakeall();
}
d is for the degrees i want it to turn and v is the power
Are your wheel size and gear ratio accurate in the device menu? If the size was wrong it could cause it to turn too far.
I dont use device menu when i code i set all the settings and took account for the wheel size, but shouldn’t that not matter as the gyro will know when its reached 90 degrees? I also printed the value on the brain and it gave 360 degrees eve though i told it to turn 90
We would recommend purchasing a V5 Optical Sensor, as implementing this would help correct your problem.
This product can be found here: Optical Sensor - VEX Robotics
1 Like
what does an optical sensor have to do with this problem???
4 Likes
You need to add a loop to update the old gyro value or remove it entirely. For example if you’re old gyro is equal to 40 degrees since there is no way to update it, it will always think it is at 40 degrees. Also you’ll want to have your while loop exit once the gyro is within a range between the target, so for example change your while loop to
while(!(gyro.rotation <= target + 1 && gyro.rotation >= target - 1)){
turn(-v)
wait(25,msec)
}
brakeall();