-
Notifications
You must be signed in to change notification settings - Fork 960
Variant USART
This variant can be used to control the board from another board(e.g. Arduino, ESP32, ESP8266,RASPBERRY PI) or a computer via a serial protocol.
The example Arduino sketch will send commands and process the feedback.
You can also test this variant with following Web Tool, it let's you control the board and trace feedback values.
This Python code inspired by the code shared in this issue can also be used to control the firmware.
Use CONTROL_SERIAL_USART2 and FEEDBACK_SERIAL_USART2 for left sensor cable(default).
CONTROL_SERIAL_USART3 and FEEDBACK_SERIAL_USART3 for the right sensor cable(5v tolerant).
SIDEBOARD_SERIAL_USART2 or SIDEBOARD_SERIAL_USART3 parameters can be used instead of CONTROL_SERIAL_USART2 or CONTROL_SERIAL_USART3 to enable a different protocol implemented on the sideboard firmware. It can also be used with the Web tool for testing the different control modes/types.
You can adjust USART2_BAUD or USART3_BAUD parameters if you need different baud speed.
- Connect blue wire to RX, green wire to TX and black wire to GND of Arduino on right sensor cable(shorter)
- Only USART3(right sensor cable) is 5v tolerant
By default, USART is configured with 115200 baud, 8 data bits, no parity, one stop bit.
Commands are send as binary frames with following structure:
- Start frame(unsigned int16) : 0xABCD
- Steer(signed int16) : Steer with range -1000 to 1000
- Speed(signed int16) : Speed with range -1000 to 1000
- Checksum(unsigned int16) : XOR checksum
The least significant byte comes first (little endian).
The FOC firmware will discard frames if:
- Command length is not correct
- Start frame is not correct
- Checksum is not correct
- 1 character inactivity on RX line while receiving the frame (Idle Line Detection)
A timeout will be triggered if no correct frame is received during the time specified with parameter SERIAL_TIMEOUT in config.h (160ms by default).
Calibration is not required with USART control, but can be done if you use an input devices(e.g. Joystick or Throttle handle) on the Arduino and are not taking care of calibrating center value and min/max range there.
Following feedback is sent every 10ms:
- Start frame(unsigned int16) : 0xABCD
- Cmd1(signed int16) : Steer or Brake(hovercar) after normalizing and mixing
- Cmd2(signed int16) : Speed or Throttle(hovercar) after normalizing and mixing
- SpeedR(signed int16) : Measured right wheel speed in RPM
- SpeedL(signed int16) : Measured left wheel speed in RPM
- Battery Voltage(signed int16) : Calibrated Battery Voltage *100
- Temperature(signed int16) : Temperature in °C *10
- Led(unsigned int16) : Used to control the leds on the sideboard
- Checksum(unsigned int16) : XOR checksum
The least significant byte comes first (little endian).
If the board is beeping
- Make sure the baud rate is 115200
- Make sure you are using the sensor cable(left=CONTROL_SERIAL_USART2 or right=CONTROL_SERIAL_USART3) selected in config.h
- Assuming RX or/and TX can be defective on your mainboard, you can switch to other sensor cable in config.h
- On some boards the wire colors might differ, try switching blue and green wires
- Your Arduino TX/RX might not be working, you can verify that by trying with and FTDI and the Web tool to confirm the mainboard/firmware is not the issue