RoPod/Tutorials/Matlab and a ROS node interface

From Control Systems Technology Group
Jump to navigation Jump to search

The Robotic Systems Toolbox will allow to connect Matlab to the ROS network. Get familiar with the toolbox https://nl.mathworks.com/help/robotics/examples.html

For connecting Simulink and ROS, the following tutorial is particularly useful: https://nl.mathworks.com/help/robotics/examples/connect-to-a-ros-enabled-robot-from-simulink.html

In order to connect matlab with ROS, one has to specify a ROS master machine. If you want to connect locally, then, the ROS master and your ROS matlab node is your local machine, which is the default case.

In case you want to establish a ROS network among different machines, only one ROS master should run the roscore process. Moreover, the ip address of all machines should be known in advance. You can get familiar with the ROS network concept here https://nl.mathworks.com/help/robotics/examples/connect-to-a-ros-network.html.

In this tutorial an example is provided in which the ropod is teleoperated using the keyboard from a laptop, and the matlab ROS node is running on the ropod’s computer.

The first step is to connect the laptop and the ropod to the same wireless network. In this case, the ropod is by default connected to the “MSL_A_field” network, which is used by the Tech United soccer team.

To connect your laptop to that network, run the provided robocup_network.sh script. In a console run:

./robocup_network.sh

Notice that we have set up a fixed IP for the laptop (see script), which will be used also as the master node. Then in another terminal be sure you run the roscore in your laptop. Now you can configure the ROS master in matlab.

setenv('ROS_MASTER_URI','http://192.168.1.100:11311')

Now you can open the ropod_control_ROS_teleop.slx file and build the ROS node by pressing Cntrl+B.

The main difference when building a ROS node is that instead of an executable, which is created by building a standard matlab application, Matlab creates a package that can be built in a catkin workspace. After the build process is complete, two files are created: build_ros_model.sh and ropod_ROS_teleop.tgz, which are sufficient to build the ros node.

A script was made to automatically create the catkin workspace and build the ros node. In a terminal, go to the simulink model folder and run the following command:

./build_ros_model_custom.sh ropod_control_ROS_teleop.tgz ros_node_cws

Notice that the folder ros_node_cws is also created, containing the catkin workspace and the compiled ROS node ropod_ROS_teleop_node.

You can then use scp linux command (http://infohost.nmt.edu/tcc/help/xfer/scp.html) to transfer the node to the ropod. In a terminal:

scp ros_node_cws/* robocup@ropod:~/ropod_motion_control/<pre>

Then, you can open a remote terminal from the ropod using ssh, from where you can use the standard procedure to run the ROS node. (See ROS documentation)

<pre>cd ros_node_cws
source devel/setup.bash
rosrun ropod_control_ros_teleop ropod_control_ros_teleop_node

Once the Matlab ROS node is running in the ropod, you can use the provided ROS node keyboard_teleop to be able to send commands to the ropod using the ROS network. Similarly, open the folder containg the keyboard teleoperation node in your laptop:

cd ropod_teleop
source devel/setup.bash
rosrun ropod_teleop teleop_keyboard