cinaral / teensy41_pd

This is a PD control library to command to and receive from a Teensy 4.1's that is discoverable in the local area network (LAN) using UDP packets. This is a multi-platform project. The commanding device can be any x86 computer running Linux, and the commanded device is Teensy 4.1 which is an ARM Cortex-M7 microprocessor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

1. teensy_pd: Proportional-Derivative control over UDP packets

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.


2. Dependencies

  1. udp_msg
  2. cxxopts

3. Quick Start

3.1. Build firmware using PlatformIO

Open the teensy/ folder using PlatformIO IDE on VS Code, and compile the firmware for the Teensy 4.1.

3.2. Copy files to Raspberry Pi

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

3.3. Upload the Teensy firmware

Upload the firmware. You can use the upload script.

3.4. Build the Raspberry Pi executable

Configure and build the Raspberry Pi executable using the configure script and the build script. Delete existing configuration using the clear script.

3.5. Check if the Teensy was assigned a local IP

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.

3.6. Run the Raspberry Pi main executable

rasppi: ~ $ rasppi/build/bin/main

You should see the telemetry data printed in your console.

Telemetry example

4. send_udp usage

You can use use send_udp executable to send invididual flags as defined in config.hpp.

4.1. Flags and their meanings:

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

4.2. Examples:

  1. 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
  1. 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

Acknowledgements

This work was supported by the National Science Foundation DCSD Grant (No. 2029181).

About

This is a PD control library to command to and receive from a Teensy 4.1's that is discoverable in the local area network (LAN) using UDP packets. This is a multi-platform project. The commanding device can be any x86 computer running Linux, and the commanded device is Teensy 4.1 which is an ARM Cortex-M7 microprocessor.

License:MIT License


Languages

Language:C++ 87.1%Language:Shell 12.9%