Rosserial Script: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
This is a brief explanation of the code used to read data from a file containing the angles controlling the AMIGO's arms and sending these angles to an Ubuntu machine to publish them on a ROS topic.
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 [http://cstwiki.wtb.tue.nl/index.php?title=PRE2015_4_Groep1#scripts project] to create a robot technique that allows users to hug someone when separated by a disctance like a phone call.
This code is part of a [http://cstwiki.wtb.tue.nl/index.php?title=PRE2015_4_Groep1#scripts 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 ==
== Setting up the connection to ROS ==
[[File:Setup.png|x400px]]
[[File:Setup.png|x340px]]


== Reading the data from a text-file ==
The lines '''27-30''' are responsible for setting up the connection to the Ubuntu machine. The characterstring <code>*ros_master</code> 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.
[[File:Read file.png|x420px]]
 
The lines '''33-36''' are used to create a new ROS topic <code>arm_angles</code> to publish the ROS message <code>floats_msg</code> 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 [http://cstwiki.wtb.tue.nl/index.php?title=Sending_data_between_Windows_Applications&action=edit&redlink=1 here].


== Sending the data to ROS ==
== Sending the data to ROS ==
[[File:Send data.png|x400px]]
[[File:Send data.png|x280px]]
 
The lines '''75-77''' are used to print the content of the <code>data</code> array onto the console. This can be used to check whether the correct values are read from the text file using this piece of [http://cstwiki.wtb.tue.nl/index.php?title=Sending_data_between_Windows_Applications&action=edit&redlink=1 code].
 
The lines '''80-82'''  take the <code>data</code> array and its contents and put it into the <code>floats_msg</code> 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.

Latest revision as of 18:30, 20 June 2016

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.