Gyro Blocks example

Here’s some code I threw together for GYRO turns.


By making the velocity dependent on the rotation, you get a nice slowdown so you don’t overshoot your target. If you did, the bot would correct.

Here’s a video of the code running:


A couple of questions:

  1. Is it necessary to calibrate for 8s - will 2s not work ?
  2. I don’t see how this slows down. The velocity is Gyro Rotation in Deg times 1.5. Which means as the Gyro goes from 0 to 90 that value is increasing and so the velocity has to increase and not slow down.
    I tried the exact same code - i see the velocity increase and our robot also does not stop turning…keeps going in circles.

I think i get it…if the gyro is on the top then it goes from 360 to 270 - so the value is reducing.

Ours oscillates. :frowning:

Even if we reduce our multiplier to 0.5…i don’t think it comes out of the forever loop to do the next step in the code. Will a ‘while gyro < 90’ work the same way, instead of a forever.
How can we get the Gyro Rotation to be a range rather than it trying to accurately turn 90. So if it is between 89 and 91…then break out of the forever loop.

This will only work if you are aiming for zero… So as the value gets closer to zero it will slow down. You are trying to get the bot to get to and stay on 0.

You also need to be sure to use rotation, not heading.

Rotation will go 3, 2, 1, 0, -1, -2, -3

Heading will go 3, 2, 1, 0, 355, 354, 353…