Add notes.md
This commit is contained in:
commit
078a5b4902
63
notes.md
Normal file
63
notes.md
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
Here is a developer-oriented description for the protocol and requirements needed to control two motors on your ESP32 device via serial communication:
|
||||||
|
|
||||||
|
### Data Packet Format
|
||||||
|
|
||||||
|
- The controller expects a data packet sent over UART containing exactly three bytes:
|
||||||
|
1. **Envelope Byte:** `0xAA` (serves as a sync marker and must be the first byte of every packet)
|
||||||
|
2. **Motor 1 PWM Value:** Ranges from 0 (off) to 255 (full speed)[2][3]
|
||||||
|
3. **Motor 2 PWM Value:** Ranges from 0 (off) to 255 (full speed)[3][2]
|
||||||
|
|
||||||
|
- The packet structure: `[0xAA][Motor1_PWM][Motor2_PWM]`
|
||||||
|
|
||||||
|
### Serial Transmission Requirements
|
||||||
|
|
||||||
|
- Transmit at a reliable baud rate compatible with the ESP32 UART (for example, 115200).
|
||||||
|
- Always ensure that `0xAA` is the leading byte for synchronization. If noise or loss occurs, the receiver will wait for `0xAA` before processing the next two bytes as PWM data.[6]
|
||||||
|
|
||||||
|
### Motor Control Logic
|
||||||
|
|
||||||
|
- Upon receiving a properly formed packet (`0xAA` followed by two PWM bytes), the ESP32 sets the PWM on Motor 1 and Motor 2 using an 8-bit analog or ledcWrite function. Valid duty cycle values are 0–255 (8-bit resolution).[3]
|
||||||
|
- The system compares received PWM values against the last command. The motor PWM will only be updated if the new value differs from the previous value, reducing redundant actions and communication overhead.
|
||||||
|
|
||||||
|
### Safety and Signal Timeout
|
||||||
|
|
||||||
|
- If no valid packet (with `0xAA` header) is received for 200 milliseconds, the ESP32 will automatically set both motors’ PWM to zero, stopping the robot for safety.[6]
|
||||||
|
- Developers must ensure that new packets are sent at intervals shorter than 200 ms to keep the motors active and avoid unwanted stops.
|
||||||
|
|
||||||
|
### Example Packet
|
||||||
|
|
||||||
|
To set Motor 1 to 120 and Motor 2 to 180:
|
||||||
|
```
|
||||||
|
[0xAA][0x78][0xB4]
|
||||||
|
```
|
||||||
|
Where:
|
||||||
|
- `0xAA` = Envelope/sync
|
||||||
|
- `0x78` = 120 (Motor 1 PWM)
|
||||||
|
- `0xB4` = 180 (Motor 2 PWM)
|
||||||
|
|
||||||
|
### Summary Table
|
||||||
|
|
||||||
|
| Byte | Value Range | Purpose |
|
||||||
|
|---------|---------------|---------------------------|
|
||||||
|
| 1 | 0xAA | Envelope / header |
|
||||||
|
| 2 | 0–255 | Motor 1 PWM signal |
|
||||||
|
| 3 | 0–255 | Motor 2 PWM signal |
|
||||||
|
|
||||||
|
### Additional Notes
|
||||||
|
|
||||||
|
- All bytes must arrive without alteration; avoid extra bytes or other headers.
|
||||||
|
- If you need to change the sync byte, update the ESP32 firmware accordingly.
|
||||||
|
- Tie the GND of the sender to ESP32’s GND for reliable UART connection.[6]
|
||||||
|
|
||||||
|
This ensures that motor control commands are robust, noise-resistant, and safe for continuous operation.
|
||||||
|
|
||||||
|
[1](https://github.com/manojramesh-io/ROS2-ESP32-Serial-Bridge)
|
||||||
|
[2](https://www.hqonline.com/blog/esp32-with-dc-motor-and-l298n-motor-driver--speed-and-direction-control)
|
||||||
|
[3](https://randomnerdtutorials.com/esp32-dc-motor-l298n-motor-driver-control-speed-direction/)
|
||||||
|
[4](https://www.instructables.com/How-to-Control-4-Motors-With-Two-ESP32s-Over-I2C-A/)
|
||||||
|
[5](https://www.techrm.com/practical-guide-to-esp32-communication-protocols/)
|
||||||
|
[6](https://randomnerdtutorials.com/esp32-uart-communication-serial-arduino/)
|
||||||
|
[7](https://docs.espressif.com/projects/esptool/en/latest/esp32/advanced-topics/serial-protocol.html)
|
||||||
|
[8](https://resources.basicmicro.com/esp32-roboclaw-motor-control/)
|
||||||
|
[9](https://documentation.espressif.com/esp32-c5_technical_reference_manual_en.html)
|
||||||
|
[10](https://docs.cirkitdesigner.com/project/published/f8dacc1a-61b1-4499-be1f-431b347f9a79/arduino-and-esp32-based-sensor-monitoring-and-motor-control-system)
|
||||||
Loading…
x
Reference in New Issue
Block a user