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)
from tamproxy import TAMProxy
- 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.
- Turn on continuous requests:
tamp.pf.pc.set_continuous_enabled(True)This means that when you create a digital or analog input or sensor class, the latest values will continuously stream in when possible
- Import all device classes you need:
from tamproxy.devices import DigitalOutput
- Instantiate your devices:
led = DigitalOutput(tamp, 13)Then you can try
led.write(1) or led.write(0), etc
- 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: https://github.mit.edu/MASLAB-2017/team0/blob/master/catkin_ws/src/tamproxy_example/scripts/teensy.py. The demo reads from one ToF sensor and publishes the result to topic
/tof0. It also subscribes to topics
/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
rosrun tamproxy_example teensy.py
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.