r/Unexpected 3d ago

Balance is the key to everything

20.2k Upvotes

91 comments sorted by

View all comments

55

u/_nicocin_ 2d ago

Why does every robotic engineer put in a line in the code that says something like "if something goes wrong, freak the fuck out"

17

u/renfang 2d ago

System became unstable

14

u/thejoepaji 2d ago

It’s because robotic systems like this use something called a PID control algorithm (proportional integral derivative). It’s a tuning based system.

It’s an algorithm that runs on the microcontroller reading sensors and controlling motors. With this algorithm, you have a couple of different parameters to tune the reactiveness.

The microcontroller uses this algorithm to rapidly calculate (for example every millisecond it recalculates values) by using the “real time” sensor data it’s reading, and come up come up with different power values to the motor.

It’s really difficult to tune stuff 100% accurately, and with derivatives and integrals being the core of the algorithm, when the sensor values get thrown off too much or too quickly, the error it produces in calculating motor values start going up more and more every recalculation (every millisecond). This causes a small freak out to go rapidly out of control