InFeeo
Language

Update — Objective: Autonomous Mapping Robot: Correction of motor vibrations; addition of a safety monitoring system(reddit.com)

×
Link preview Update — Objective: Autonomous Mapping Robot: Correction of motor vibrations; addition of a safety monitoring system Following up on my last post about this robot project (which I'm currently working on with a Raspberry Pi)—I thought I'd share an update on the project's progress, since I ran into a problem that took me a bit of research to figure out, and I was also able to reflect on it thanks to the very valuable feedback I received. (https://www.reddit.com/r/raspberry_pi/s/eCKPFWwPhk) The issue While testing the 4 DC motors from the web interface, I noticed something off: sometimes the robot would suddenly lurch forward at full speed when I'd only tapped a key once, and other times there'd be a noticeable delay between pressing a key and the motor actually responding. Not a one-off glitch — happening often enough that I couldn't trust the controls. What was actually going on After digging into it, the culprit was the PWM signal I was using to control motor speed. I was using RPi.GPIO's software PWM, which relies on a Python thread toggling the pin at precise intervals to simulate the signal. The problem is that thread has to compete for CPU time with everything else my server is doing — streaming gyroscope data 20 times a second, running the radar scan, handling Flask/SocketIO requests. When the Pi got momentarily busy, the PWM timing would drift, which explains both symptoms: a duty cycle spike (sudden full-speed lurch) or a delayed update (the motor not getting the new speed in time). The fix Switched to pigpio, which runs as a separate daemon (pigpiod) in the background. Instead of my Python code generating the PWM signal itself, it just sends simple commands to this daemon, which handles the actual signal generation independently of whatever else the Pi is doing. So far the difference is noticeable — no more random speed spikes during testing. The other thing I added: a watchdog Separately, I realized there was a bigger risk I hadn't addressed: the robot is controlled entirely over WiFi through a browser. If the connection drops for any reason while it's moving forward, there was nothing stopping it from just... continuing toward whatever's in front of it. So I added a watchdog thread on the server side — it tracks the timestamp of the last command received, and if more than 500ms pass without a new one, it force-stops the motors automatically. Independent safety net, regardless of what causes the disconnect (WiFi hiccup, browser crash, whatever). what I plan to do next Mechanical redesign: dropping from 4 driven wheels to 2 front-driven wheels + a rear caster wheel, mainly to simplify trajectory control (the 4-wheel setup made it hard to drive perfectly straight) Mounting HC-020K encoders on the front wheels for actual odometry instead of relying purely on the gyroscope (which drifts over time) Eventually fusing gyro + encoder data to get a stable heading estimate Repo's here if you want to poke around: https://github.com/enzocolombat/EC-Hub Genuinely curious what people think of the pigpio + watchdog approach — is there a cleaner way to handle the real-time PWM issue I'm missing? And for anyone who's done the encoder + gyro fusion thing on a budget robot, would love to hear how you approached it before I dive in. submitted by /u/Pasteque9000 [link] [Kommentare] reddit.com · reddit.com
Following up on my last post about this robot project (which I'm currently working on with a Raspberry Pi)—I thought I'd share an update on the project's progress, since I ran into a problem that took me a bit of research to figure out, and I was also able to reflect on it thanks to the very valuable feedback I received. (https://www.reddit.com/r/raspberry_pi/s/eCKPFWwPhk) The issue While testing the 4 DC motors from the web interface, I noticed something off: sometimes the robot would suddenly lurch forward at full speed when I'd only tapped a key once, and other times there'd be a noticeable delay between pressing a key and the motor actually responding. Not a one-off glitch — happening often enough that I couldn't trust the controls. What was actually going on After digging into it, the culprit was the PWM signal I was using to control motor speed. I was using RPi.GPIO's software PWM, which relies on a Python thread toggling the pin at precise intervals to simulate the signal. The problem is that thread has to compete for CPU time with everything else my server is doing — streaming gyroscope data 20 times a second, running the radar scan, handling Flask/SocketIO requests. When the Pi got momentarily busy, the PWM timing would drift, which explains both symptoms: a duty cycle spike (sudden full-speed lurch) or a delayed update (the motor not getting the new speed in time). The fix Switched to pigpio, which runs as a separate daemon (pigpiod) in the background. Instead of my Python code generating the PWM signal itself, it just sends simple commands to this daemon, which handles the actual signal generation independently of whatever else the Pi is doing. So far the difference is noticeable — no more random speed spikes during testing. The other thing I added: a watchdog Separately, I realized there was a bigger risk I hadn't addressed: the robot is controlled entirely over WiFi through a browser. If the connection drops for any reason while it's moving forward, there was nothing stopping it from just... continuing toward whatever's in front of it. So I added a watchdog thread on the server side — it tracks the timestamp of the last command received, and if more than 500ms pass without a new one, it force-stops the motors automatically. Independent safety net, regardless of what causes the disconnect (WiFi hiccup, browser crash, whatever). what I plan to do next Mechanical redesign: dropping from 4 driven wheels to 2 front-driven wheels + a rear caster wheel, mainly to simplify trajectory control (the 4-wheel setup made it hard to drive perfectly straight) Mounting HC-020K encoders on the front wheels for actual odometry instead of relying purely on the gyroscope (which drifts over time) Eventually fusing gyro + encoder data to get a stable heading estimate Repo's here if you want to poke around: https://github.com/enzocolombat/EC-Hub Genuinely curious what people think of the pigpio + watchdog approach — is there a cleaner way to handle the real-time PWM issue I'm missing? And for anyone who's done the encoder + gyro fusion thing on a budget robot, would love to hear how you approached it before I dive in. submitted by /u/Pasteque9000 [link] [Kommentare]

Comments

Log in Log in to comment.

No comments yet.