Note: This tutorial assumes that you have completed the previous tutorials: Basic Interaction with ROS and TouchOSC.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Using the Default tabpage handler to interact with TouchOSC layouts

Description: How to use the default tabpage handler to interact with TouchOSC layouts

Tutorial Level: BEGINNER

Next Tutorial: rososc_tutorials/Tutorials/A more advanced Publisher and Subscriber

Background on Tabpage Handlers

The touchosc_bridge node is written with modularity in mind. Because of this, it has a method of interacting with ROS and the TouchOSC application using what is called a tabpage handler.

Simply put, a tabpage handler is a Python module that can publish and subscribe to both ROS and TouchOSC and fit into the larger framework of the touchosc_bridge.

When no other handlers are specified, and the load_default parameter is set, then a default tabpage handler will be instantiated to handle transactions between ROS and OSC. Additionally, when the load_default parameter is set, tabpages that aren't handled by other handlers will "fall back" to the default handler.

The default handler parses a given layout file using the pytouchosc Python module, and then creates a publisher/subscriber for each control found.

Starting the Default Handler

Much like the previous tutorials, we will use a launch file to start the touchosc_bridge node.

The contents of the launch file are the same as the previous lesson, and can be launched with:

roslaunch rososc_tutorials basic_interaction.launch

To prove that the default tabpage handler has loaded, try listing available topics.

∫ rostopic list
/diagnostics
/touchosc/1/HFader
/touchosc/1/VFader
/touchosc/1/battery1
/touchosc/1/encoder1
...
/touchosc/TextDemo/down
/touchosc/TextDemo/downLabel
/touchosc/TextDemo/fader1
/touchosc/TextDemo/l1
...
/touchosc/accel
/touchosc/tabpage
/touchosc/vibrate

Note that on top of the common touchosc_bridge topics, a namespace has been created for each tabpage, as well as a ROS Publisher/Subscriber for each control found in the layout files specified.

Subscribing to Control Messages

Each control has it's own set of properties that may be subscribed to via ROS. For more details on the capabilities of each control, and a full listing of all available controls, please consult the Controls Reference in the touchosc_bridge package documentation.

Control Z Messages

In order for the "z" field of messages to populate correctly, the "Send z messages" setting must be on in the Options page of the TouchOSC settings.

Experiment with subscribing to multiple kinds of controls. A few examples are listed below:

rostopic echo /touchosc/1/toggle1
rostopic echo /touchosc/1/multifader1
rostopic echo /touchosc/1/xy2
rxplot /touchosc/1/xy/{x,y}

Reference the Controls Reference wiki page to see what types of messages each control is capable of sending and receiving.

Publishing to Controls

In addition to capturing values coming off of controls, it is possible to Publish ROS messages to interact with controls on the screen.

Publishing Control Properties

All controls are capable of changing some common properties via a ROS Subscriber. To view these common properties, see the touchosc_msgs/CommonProperties message, or simply type the following at the command line:

rosmsg show touchosc_msgs/CommonProperties

As an example, let's change the color of an LED. rostopic list shows that there is a /touchosc/1/led12 control on the main tabpage of the tutorial layout. Use the rostopic tool to turn the LED on, and change it's color.

rostopic pub /touchosc/1/led12 touchosc_msgs/ScalableControl '{common: {color: "blue"}, value: 1.0}'

If the rostopic tool is successful, the leftmost LED should now be on and blue.

This can be done with any control on the screen, experiment with different controls and the rostopic tool.

# Set the XY Pad cursor to the center
rostopic pub /touchosc/1/xy2 touchosc_msgs/XYPad '{x: 0.5, y: 0.5}'

# Hide the battery display
rostopic pub /touchosc/1/battery1 touchosc_msgs/TouchOSC_Common '{common: {visible: "false"}}'

# Set all of the faders in multifader1 to full.
rostopic pub /touchosc/1/multifader1 touchosc_msgs/MultiFader '{values: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]}'

# Make a vee out of the faders
rostopic pub /touchosc/1/multifader1 touchosc_msgs/MultiFader '{values: [1.0, 0.8, 0.6, 0.4, 0.4, 0.6, 0.8, 1.0]}'

And so on.

Wiki: rososc_tutorials/Tutorials/Using the Default Handler (last edited 2011-11-06 11:43:26 by MichaelCarroll)