ebelski / rust-copter

A quadcopter build using a Teensy running Rust and some other cool stuff that's yet to be determined.
MIT License
6 stars 1 forks source link

pwm-control: stream data over USB, add pypwm-control interface #43

Closed mciantyre closed 3 years ago

mciantyre commented 3 years ago

The PR modifies the pwm-control demo. Rather than sending motion sensor readings over UART, we send it over USB. We should be able to send data much faster than with UART. See discussions in #42 for the numbers. From a quick study of the USB driver, I believe worst-case latency from board to host through the embedded board's USB driver is two microframes (250us) to schedule a bulk transfer, plus movement of data on the bus (480MHz). I've not measured any of this, but I think it should be good enough for our first demo.

We were previously using USB for debug logging and user input. We move debug logging to the UART output. The USB peripheral will still receive motor commands. This means that any feedback from an incorrect motor setting comes from a different serial interface. The test below highlights this change (2.a.)

This PR also introduces pypwm-control, a Python host-side library for

There's a new example, esc-throttle.py, that lets you control the throttle percentage from the command line. See the new entry in hosts/README.md. The existing imu-parse.py script is rewritten to use pypwm-control, serving as an example of streaming IMU readings.

Test

This test assumes that no motors are connected. We're going to speed up one motor to 99% throttle...

  1. Flash pwm-control to your board:
    ./tasks.py demo pwm-control

    Observe a slow-blinking LED.

  2. Run the imu-parse.py example on your host:
    python host/imu-parse.py COMx

    Observe accelerometer and gyroscope readings. Skip this test if the IMU isn't connected. a. COMx is the COM port for the USB peripheral, not the FTDI cable. b. Try changing the enable_readings and disable_readings calls in the script to affect what's printed.

  3. Run the esc-throttle.py example on your host, and change the throttle on motor B to 99%:
    python host/esc-throttle.py COMx B 99

    Observe that the LED blinks rapidly, representing the max throttle for all motors is very high. a. COMx is same as 2.a.

To see debug log output, connect to your FTDI cable with PuTTY, baud rate 115200. Most noise happens at startup, but it may output warnings during runtime if there's an issue.

ebelski commented 3 years ago

Test

This test assumes that no motors are connected. We're going to speed up one motor to 99% throttle...

  1. Flash pwm-control to your board:

    ./tasks.py demo pwm-control

    Observe a slow-blinking LED.

  1. Run the imu-parse.py example on your host:

    python COMx host/imu-parse.py

    Observe accelerometer and gyroscope readings. Skip this test if the IMU isn't connected.

✅ (need to update comment above to say "python host/imu-parse.py COMx"

a. COMx is the COM port for the USB peripheral, not the FTDI cable. b. Try changing the enable_readings and disable_readings calls in the script to affect what's printed.

  1. Run the esc-throttle.py example on your host, and change the throttle on motor B to 99%:

    python host/esc-throttle.py COMx B 99

    Observe that the LED blinks rapidly, representing the max throttle for all motors is very high.

a. COMx is same as 2.a.

To see debug log output, connect to your FTDI cable with PuTTY, baud rate 115200. Most noise happens at startup, but it may output warnings during runtime if there's an issue.

✅ Debug info works well for throttle! image

ebelski commented 3 years ago

@mciantyre are we good to merge this pull request?

mciantyre commented 3 years ago

Fixed step 2. Yup all good for a merge. Thanks for testing!