Control ESCs in Embedded Rust
The purpose of this repository is to control the speed of a motor using an ESC driven by a pwm signal. In particular, this pwm signal is 50Hz with a width of anywhere from 1-2ms (min to max throttle).
- PWM
- Dshot
In order to control the speed of a brushless motor, a middleman that can deal with intricacies involved with such as a motor is necessary. ESCs are helpful as they abstract away technical details such that the end user just needs to supply a pwm signal (or other policies such as oneshot, Dshot etc.)
The ESC I used is the LITTLEBEE 30A, which includes the BLHeli S software. Using documentation found online (which was for a different ESC, but I believe these are of the same model), a particular behaviour can be noted.
![image](https://private-user-images.githubusercontent.com/25258108/293484571-eca774d8-6ee6-421e-829f-772910728210.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ1NTA1ODEsIm5iZiI6MTcyNDU1MDI4MSwicGF0aCI6Ii8yNTI1ODEwOC8yOTM0ODQ1NzEtZWNhNzc0ZDgtNmVlNi00MjFlLTgyOWYtNzcyOTEwNzI4MjEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjUlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI1VDAxNDQ0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTM3NTcwYTVlNjdjMjEyZjBhYWI4NWU1NTIyNjUzNjE1OTc4OTFmYzNjYjdiYjFkNDU2ZTg1YjAwM2I5MzZhNDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.amB3taOtWmiLOkJBVEv1rw0P5-fGiGcfGpx2tioT5gc)
From the image above, I can discern that the ESC needs to detect zero throttle for a normal start up. Afterwards, the motor will run to the user's specifity.
// Zero signal
rprintln!("Zero signal");
ch1.set_duty(max_duty / 20);
rprintln!("Slight delay");
delay.delay_ms(10000_u32);
rprintln!("Mid-throttle signal");
ch1.set_duty(max_duty / 18);
In the code above, I send an initial zero throttle signal to run the ESCs normal start-up process. I also introduce a slight delay so the ESC can register the zero throttle signal. Afterwards, I can send whatever throttle signal I would like to send.