Rosserial Script

From Control Systems Technology Group
Jump to navigation Jump to search

This is a brief explanation of the code used to set up a connection to a Ubuntu machine running ROS and the ROS socket node and to publish ROS messages to a specific ROS topic from a Windows machine.

This code is part of a project to create a robot technique that allows users to hug someone when separated by a disctance like a phone call.

Setting up the connection to ROS

Setup.png

The lines 27-30 are responsible for setting up the connection to the Ubuntu machine. The characterstring *ros_master should be the IP address of the Ubuntu machine. Make sure a connection can be established from the Windows machine to this computer by pinging this IP address.

The lines 33-36 are used to create a new ROS topic arm_angles to publish the ROS message floats_msg onto. This message is a standard Float64MultiArray message. Only the data property of this message type is used to send all the latest calculated arm angles in a bundle.

In the final lines 39-42 an empty array of 14 doubles is created. The calculated arm angles are put into this array. This is part of the code is however not covered on this page, but here.

Sending the data to ROS

Send data.png

The lines 75-77 are used to print the content of the data array onto the console. This can be used to check whether the correct values are read from the text file using this piece of code.

The lines 80-82 take the data array and its contents and put it into the floats_msg message. Then the message is published onto the ROS topic.

After the message has been send, the application is delayed 4000 milliseconds before sending another message. This time interval is quite long and causes the AMIGO's movements to be delayed by a big amount. A smaller delay can be tried, but it might overload the AMIGO simulator and cause it to crash.