Please can someone give me the pseudocode or code for gyro turns?

Please I am having trouble turning to the right with the ROBOTC sample code.

Turn(target value)
If target value < current value
Turn(left)
Waituntil(target value>current value)
Motors to 0

Else if target value>current value
Turn(right)
Wait until(taget<current)
Motors to 0

You should check which way to turn first… if the target it 350 and you are at 20, the. You want to rotate counter clockwise, even though 20<350

You can check by this:
If abs(current - target) < 180 then{
If current >target then
Spin clockwise
Else
Spin counter clockwise
}Else{
If current >target then
Spin counter clockwise
Else
Spin clockwise
}

Sorry, you should reset the gyro each time you use it.

Turn(target value)
Reset gyro to 0
If target value < current value
Turn(left)
Waituntil(target value>current value)
Motors to 0

Else if target value>current value
Turn(right)
Wait until(taget<current)
Motors to 0

Are you trying to do turning for autonomous? If so try something like this:


while(SensorValue[gyroscope]<900){ //While the gyroscope is less than 90 degrees 
motor[frontLeft]=127;
motor[backLeft]=127;
motor[frontRight]=-127;
motor[backRight]=-127;
}

Just a key reminder, the gyroscope values can be reversed whenever you are wanting to turn your robot right. You’d expect turning right to be positive, but some of the times it can be negative. So just display the gyroscopes value to make sure if you’d like. Another, you might have to tamper which motors goes positive, and which goes negative.
Hopefully this helps :slight_smile: