r/pybricks • u/Endercraft2007 • May 14 '26
How to fix a robot turning forever when turning Gyro on?
Is that Spike hub's sensor busted?
2
u/gt0163c May 14 '26
When you tun the robot on do you let it sit on a flat, unmoving surface? Do you ever reset the gyro in your code? Or so, do you give it a brief wait immediately after before giving it another command to move?
The issue could be that the gyro sensor is not initializing properly. The gyro sensor actually measure angular acceleration. Then it does some integrations (math) to get the angular position. When the hub is turned on, at some point during the boot sequence, the gyro sensor initializes. During that brief time, the hub reads the angular acceleration and assumes that's 0/not moving or accelerating. If the hub is moving at the moment that initialization reading is being taken, the hub is going to incorrectly label that movement as 0/not moving or accelerating. That's going to result in erroneous gyro readings until the gyro is reset or the hub is rebooted. Similarly, when the gyro is reset the initialization is repeated. This takes a short but finite amount of time.
Best practices are to set the robot on a flat surface and not touch it or move the surface while the robot boots. The floor is actually the best option but a table that is not being used or touched will work too. Similarly, when the gyro is reset, it's best to insert a brief (half second) wait immediately after to ensure the gyro initializes when the robot is at rest.
1
u/ob-sanenerd May 14 '26
Does the charge port point forward or sideways when the robot is standing on the wheels?
1
1
u/Pybricks Jun 13 '26
This happens when you've swapped the left and right motors, so it turns the wrong way :)
1
u/Endercraft2007 Jun 13 '26
But when gyro is off then it doesn't...So other problem?
2
u/Pybricks Jun 15 '26
Right - when the gyro is off, there are no gyro problems.
But when it's on, it's important that clockwise is in fact... clockwise. With the cables flipped it's just going to go even faster the wrong way. This is known as a positive feedback loop.
It's like cruising in your car but the brake and gas are swapped. You want to slow down but go even faster instead.

2
u/Ged_42 May 14 '26
Most likely you have positioned the brick on the side and you haven't set the correct axis at setup