Using Robobo ROS
As explained briefly in the previous section, the application Robobo Developer contains an implementation of the Robobo remote control system, implemented in Java + Rosjava, that connects the remote control system with a ROS Master, thus converting the Robobo into a 'node' that other ROS 'nodes' can use.
To achieve this, the Robobo Developer application, after having created its own ROS Master, or having connected to an existing one, will create the following ROS elements:
- A set of topics where Robobo publishes notifications of changes in the values of its sensors and other functionalities. More information at Documentation of Robobo Sensor Topics.
- A set of services that allow any ROS node to command/actuate the robot. More information at Documentaton of Robobo Services.
These topics and services use a combination of custom and standard ROS message types, thus in order for other ROS nodes to use Robobo, it is required for them to know and use Robobo's own messages and services package.
Clone the repository robobo-ros-msgs or directly download the file robobo_msgs-1.2.3.zip and uncompress it. Them, with a ROS workspace already in place, follow these steps:
- Copy the 'robobo_msgs' directory, which contains the Robobo messages and services, into the 'src' of your ROS workspace.
- Download the open CV dependencies in the “src” folder: git clone https://github.com/ros-perception/opencv_apps
- At the root directory of your workspace run 'catkin_make install'.
- And finally run 'source devel/setup.bash'.
After executing these steps you will have installed the required message types, and thus you should be able to use 'rostopic' and 'rossservice' commands to explore and play with the Robobo topics and services.
As mentioned, the application creates its own a ROS master in the smartphone. If you want to use it, the ROS nodes must use the smartphone's IP address as ROS Master URI.
-
For example, if the smartphone's IP address is 192.168.0.18, the environment variable: ROS_MASTER_URI must be set with the value http://192.168.0.18:11311.
-
The application uses the port 11311, the same port used by ROS by default. Then:
export ROS_MASTER_URI=http://192.168.0.18:11311/
Once the ROS_MASTER_URI is set, we can already communicate with the master and see the different topics and services available in Robobo with:
rostopic list
rosservice list
Once you have imported the Robobo message package into your workspace, you just need to create a ROS application in Python to send commands and receive status messages from the base.
The following code shows how to receive status messages from the infrared sensors of Robobo:
#!/usr/bin/env python
import rospy
from robobo_msgs.msg import IRs
rospy.init_node("robobo__demo")
def listener(info):
print 'Info: ', info
sub=rospy.Subscriber("/robot/irs", IRs, listener)
rospy.spin()
- We import the IRs message necessary to be able to receive IR notifications from Robobo.
- We start the ROS node in which we will receive the status messages.
- We define a listener that prints each message received by the console.
- We subscribe to the 'irs' Robobo topic.
The execution of this script has the following output (it is only partially shown):
The following piece of code is an example of how to send a command to Robobo using ROS, that is, how to use the ROS services:
#!/usr/bin/env python
import rospy
from std_msgs.msg import String, Int8, Int16, Int32
from robobo_msgs.srv import MoveWheels, SetEmotion, Talk
rospy.init_node("robobo__demo")
robobo_move_srv = rospy.ServiceProxy('robot/moveWheels', MoveWheels)
robobo_emotion_srv = rospy.ServiceProxy('robot/setEmotion', SetEmotion)
robobo_talk_srv = rospy.ServiceProxy('robot/talk', Talk)
robobo_emotion_srv(String('sad'))
robobo_move_srv(Int8(20), Int8(-20), Int32(2000), Int16(0))
robobo_talk_srv(String('Hi, my name is Robobo'))
rospy.sleep(1)
robobo_move_srv(Int8(-20), Int8(20), Int32(2000), Int16(0))
robobo_emotion_srv(String('happy'))
- We import the messages needed to execute the ROS services.
- We start the ROS node.
- We create the proxys to use the Robobo services.
- We publish/send some example commands to some of the Robobo services.
The application also supports the image publication from the smartphone front camera in a ROS topic. The images are published in the topic */robot/camera/image/compressed* and the *compressed_image_transport* is the transport method. Users can employ these images to process or view them in applications such as *rqt_image_view* or *rviz*.