Setup MATLAB and the ROS Toolbox for Ned¶
If you are using a Niryo One, please refer to this tutorial.
Objectives - MATLAB ROS Toolbox¶
Prepare the MATLAB work environment in order to use it for all of our future MATLAB tutorials
Be able to use Ned with MATLAB
Be able to create content with Ned and MATLAB using ROS
Requirements - MATLAB ROS Toolbox¶
Basic knowledge of MATLAB
Basic knowledge in robotics and ROS
Being able to use Ned
What you will need - MATLAB ROS Toolbox¶
It is necessary to install the Matlab add-ons by downloading them from the MATLAB website:
What is the MATLAB Ros Toolbox?¶
We advise you to have a first look to the MATLAB tutorial concerning the ROS Toolbox: https://fr.mathworks.com/help/ros/ug/get-started-with-ros.html.
To be able to use this add-on from MATLAB we will need to set up correctly the connection between Ned and the host computer (the computer with using MATLAB). It means we will need to modifiy the bashrc of the Raspberry Pi of Ned and the one of the host computer.
Install Cmake version 3.19¶
Matlab will need the version 3.19 of Cmake. For this, you should first download the last version of CMake using this link: https://cmake.org/download/.
After that you can follow the command below:
sudo apt remove --purge --auto-remove cmake version=3.19 build=1 mkdir ~/temp cd ~/temp wget https://cmake.org/files/v$version/cmake-$version.$build.tar.gz tar -xzvf cmake-$version.$build.tar.gz cd cmake-$version.$build/ ./bootstrap make -j$(nproc) sudo make install
You can find more information here: https://askubuntu.com/questions/355565/how-do-i-install-the-latest-version-of-cmake-from-the-command-line
Setup the working environment, download the “ned_ros” package from Github¶
In order to control Ned with MATLAB, it is essential to generate Ned’s messages on MATLAB. For this, you will first need to download the “ned_ros” package available on Niryo’s Github.
You can clone the “ned_ros” package from github¶
git clone https://github.com/NiryoRobotics/ned_ros.git
Or download as a ZIP and extract it to the folder of your choice¶
Setup the working environment, generating Ned messages and services from the ROS package¶
Now that you have the ned_ros package, you will have to link messages and services from Ned to MATLAB.
folderpath = "/YOUR_PATH/ned_ros" rosgenmsg(folderpath)
You should then have the message below¶
Identifying message files in folder '/YOUR_PATH/ned_ros'..Done. Validating message files in folder '/YOUR_PATH/ned_ros'..Done. [9/9] Generating MATLAB interfaces for custom message packages... Done. Running catkin build in folder '/YOUR_PATH/ned_ros/matlab_msg_gen_ros1/glnxa64'. Build in progress. This may take several minutes... Build succeeded.build log To use the custom messages, follow these steps: 1. Add the custom message folder to the MATLAB path by executing: addpath('/YOUR_PATH/ned_ros/matlab_msg_gen_ros1/glnxa64/install/m') savepath 2. Refresh all messages class definitions, which requires clearing the workspace, by executing: clear classes rehash toolboxcache 3. Verify that you can use the custom messages. Enter "rosmsg list" and ensure that the output contains the generated custom message types.
For the step 1 you should use the command below on the command window¶
If you have a warning after this step it’s normal, you can continue to step 2.
For the step 2 you should use the command below on the command window¶
clear classes rehash toolboxcache
If you have a warning after this step it’s normal, you can continue to step 3.
For the step 3 you should use the command below on the command window¶
Normally you should have all messages available on MATLAB and more especially all the messages of Ned.
niryo_robot_commander/ArmMoveCommand niryo_robot_commander/GetFKRequest niryo_robot_commander/GetFKResponse niryo_robot_commander/GetIKRequest niryo_robot_commander/GetIKResponse niryo_robot_commander/JogShiftRequest niryo_robot_commander/JogShiftResponse niryo_robot_commander/PausePlanExecution niryo_robot_commander/RobotCommand niryo_robot_commander/ShiftPose (...) niryo_robot_vision/DebugColorDetectionRequest niryo_robot_vision/DebugColorDetectionResponse niryo_robot_vision/DebugMarkersRequest niryo_robot_vision/DebugMarkersResponse niryo_robot_vision/ObjDetectionRequest niryo_robot_vision/ObjDetectionResponse niryo_robot_vision/TakePictureRequest niryo_robot_vision/TakePictureResponse
You can now comment those two lines. But everytime you connect a new robot you will have to do this step again.
You can also see all services available on MATLAB using “rosservice list” on the command window.
Well done! MATLAB can now use Ned’s ROS messages and services! You are now ready to turn on Ned, connect it to internet and configure the communication between it and MATLAB.
Connect Ned to internet and get its IP address¶
Now that you have all Ned’s messages and services from the “ned_ros” package available on MATLAB, you can connect Ned to internet in order to configure the connexion between it and MATLAB using the ROS Toolbox.
The easiest way to get the IP address of Ned is to use Niryo Studio. You can have all information here: https://docs.niryo.com/product/ned/en/source/software/niryo_studio.html#connecting-ned-to-niryo-studio.
Configure the communication between Ned and MATLAB¶
Now that Ned is connected to internet, you can configure the communication between Ned and MATLAB.
The host computer is your computer with MATLAB, with the IP_HOST_COMPUTER IP address
The robot is Ned with IP_OF_NED IP address
To define that we will use the ‘setenv’ function from the MATLAB ROS Toolbox. You have to add the two lines below on your MATLAB script.
Run the communication between Ned and MATLAB¶
It’s now time to use MATLAB and the ROS Toolbox and communicate with Ned from MATLAB.
Add the line below on your MATLAB script:
ipaddress = "http://IP_0F_NED:11311"; rosinit(ipaddress)