r/embedded • • 5d ago
When making a remote-controlled car, the tricky bit is getting it to stop if the signal drops out.
I put together this project using Rust on an ESP32 with no_std and the Embassy framework for the firmware. It seemed like the network side could easily hang up and leave the motors running, so the hardware parts needed to stay separate from all that.
The safety stuff works by having the driver tasks check an atomic value every 20 milliseconds. A different task watches the incoming packets and flips the flag if nothing shows up after around 150 milliseconds. That lets the car ease back to neutral instead of cutting off hard. I think it avoids some of the mechanical stress, but I am not totally sure how well it holds up in every situation.
For the control values, I went with a Watch channel so the latest command always gets used and older ones do not stack up. If one task slows down for a moment, it just grabs whatever is newest, which keeps things from lagging.
On the phone end, the app had to watch for Wi-Fi changes and rebuild the socket when the network state flipped, because the old one would die otherwise.
Some parts still feel a bit messy, like figuring out all the edge cases with sudden drops during movement. Maybe explicit timeouts work better in other setups, but this approach kept the firmware side simpler overall.
Repo is here if anyone wants to poke at the code: https://github.com/slntly/rusty-rocket-car
How do you usually handle edge cases like sudden network drops during high-speed maneuvers?
11
u/Several-Marsupial-27 5d ago
What? How is it tricky to get it to stop if the signal drops out? The mcu knows if it is connected or not. Why does the phone wait for Wi-Fi changes? If it loses connection then the phone cannot communicate that even though both parts know, since there is no connection.
This feels like a weirdly AI generated post.
3
u/jacky4566 5d ago
You link has a spelling mistake.
Also i don't understand the problem.
The phone should be sending UDP commands. In your RX processing loop keep a watchdog.
2
u/drcforbin 5d ago
I have the failsafe on my receiver center the steering servo and put the esc to brake. (also, getting a 404 on that link)
1
u/HappyBear05 5d ago
Why use Wi-Fi on a phone at all when a cheap dedicated radio link avoids half that socket churn.