TAMProxy with ROS

TAMProxy's built-in sketch construct is nice if you're coming from the world of Arduino sketches, but becomes inconvenient if you want to use the ROS approach of nodes with publishers and subscribers. For this reason, we recommend using TAMProxy outside of a sketch class, which is fairly straightforward.

To test the waters, try the following in a python interpreter (type python in the terminal)

  1. from tamproxy import TAMProxy
  2. Create the TAMProxy instance: tamp = TAMProxy() This connects to the Teensy and starts the packet forwarder and controller processes. Only one of these can work at once since it will claim the serial port to the Teensy, which is why multiple sketches won't work.
  3. Turn on continuous requests: This means that when you create a digital or analog input or sensor class, the latest values will continuously stream in when possible
  4. Import all device classes you need: from tamproxy.devices import DigitalOutput
  5. Instantiate your devices: led = DigitalOutput(tamp, 13) Then you can try led.write(1) or led.write(0), etc
  6. Whenever you're done, make sure to call tamp.stop() to close the background processes.

Example ROS Sketch setup

From this point, you're probably best off having one ROS node for the Teensy that has multiple publisher and subscribers for motors and actuators. Currently TAMProxy does not support communicating with the Teensy across multiple processes, so you would have to do a lot of hacking to get multiple ROS nodes working.

You can find a working demo of such a ROS node in the team0 repo under the tamproxy_example package: The demo reads from one ToF sensor and publishes the result to topic /tof0. It also subscribes to topics /motor0 and /motor1 and sets the respective motor outputs based on values in the range [-1.0, 1.0].

To test the demo you should make, then run the script:

rosrun tamproxy_example

You can then manually see the ToF data via:

rostopic echo /tof0

You can also write to either motor via, e.g.:

rostopic pub -1 /motor0 -- std_msgs/Float32 0.7

To extend the sketch with more devices, the ROS tutorial on creating a basic publisher may be helpful. Note that the example sets a target rate for the main control loop and sleeps once each loop to maintain that rate, which is important to make sure packets aren't being spammed to the Teensy.