This is a PD controller project intended to command a Teensy 4.1 microcontroller from a Raspberry Pi 4 B running RaspOS over UDP packets.
- 1.
teensy_pd
: Proportional-Derivative control over UDP packets - 2. Dependencies
- 3. Quick Start
- 4.
send_udp
usage
Open the teensy/ folder using PlatformIO IDE on VS Code, and compile the firmware for the Teensy 4.1.
You need to transfer the firmware and the source files in the rasppi/
folder to the Raspberry Pi. If you can use rsync
, you can use the sync script to do this automatically.
Navigate to the teensy41_udp/
or the project folder on the Raspberry Pi, which should look like (Expand the details to display):
│teensy41_pd/
│
├── │rasppi/
│ │
│ ├── │include/
│ │ │ print_echo_resp.hpp
│ │
│ ├── │scripts/build/
│ │ │ build.sh
│ │ │ clear.sh
│ │ │ configure.sh
│ │
│ ├── │src/
│ │ │ main.cpp
│ │ │ send_udp.cpp
│ │
│ │ README.md
│
├── │shared/
│ │
│ ├── │include/
│ │ │ config.hpp
│ │
│ │ README.md
│
├── │teensy/
│ │
│ ├── │.pio/build/teensy41/
│ │ │ firmware.hex
│ │
│ ├── │include
│ │ │ MotorDriver.hpp
│ │ │ UdpHandler.hpp
│ │
│ │
│ ├── │lib
│ │ │
│ │ ├── │pid_control/include/
│ │ │ │
│ │ └── ├── │ pid_control
│ │ │ │ pdf_filter.hpp
│ │ │ │ types.hpp
│ │ │
│ │ │ pid_control.hpp
│ │
│ ├── │scripts/teensy_loader_cli/
│ │ │ upload.sh
│ │ │ upload_to_TEENSY41.sh
│ │
│ ├── │src
│ │ │ main.cpp
│ │ │ MotorDriver.cpp
│ │ │ UdpHandler.cpp
│ │
│ │ README.md
│
│ LICENSE
│ README.md
Upload the firmware. You can use the upload script.
Configure and build the Raspberry Pi executable using the configure script and the build script. Delete existing configuration using the clear script.
Check if the Teensy was assigned a local IP:
rasppi: ~ $ cat /dev/ttyACM0
Modify /dev/ttyACM0
with the USB serial port that your Teensy is connected to. You should see something like:
Local IP = 192.168.1.10
Subnet mask = 255.255.255.0
Gateway = 192.168.0.1
DNS = 192.168.1.1
Listening for clients on port 11337...
If you get the "Failed to start Ethernet" or "Failed to get IP address from DHCP" error, you should attempt a power cycle. If the error persists, uou should check your Teensy's ethernet hardware configuration and the Raspberry Pi DHCP server configuration.
rasppi: ~ $ rasppi/build/bin/main
You should see the telemetry data printed in your console.
You can use use send_udp
executable to send invididual flags as defined in config.hpp.
Flag (ASCII) | Meaning | Argument |
---|---|---|
0x0 ('NUL') | Null, no message. | N/A |
0x30 ('0') | Stop the motor. | N/A |
0x31 ('1') | Reset everything by their default values. | N/A |
0x32 ('2') | Start tracking PD control and start relaying packets. | target pos (rad) |
0x33 ('3') | Set reference to track. | target pos (rad) |
0x34 ('4') | Set the controller's proportional gain (Kp). | gain |
0x35 ('5') | Set the controller's derivative gain (Kd). | gain |
0x36 ('6') | Request an echo response. | N/A |
0x60 ('<') | Marks the beginning of the interrupts for syncronization. | N/A |
0x61 ('=') | Marks the echo response. | N/A |
- Send a stop command to the default IP and port:
$ rasppi/build/bin/send_udp -f 0
Sent 0x30: 0 to 192.168.1.10:11337
- Send a track reference command to track
$x = 1$ radians to 192.168.1.22 at port 6667:
$ rasppi/build/bin/send_udp 192.168.1.22 -f 2 -v 1-p 6667
Sent 0x32: 1 to 192.168.1.10:6667
This work was supported by the National Science Foundation DCSD Grant (No. 2029181).