1. Home
  2. Docs
  3. Niryo One documentation
  4. Tutorials
  5. Set-up Matlab

Set-up Matlab

Note
This tutorial is designed for Niryo One users. If you are using Ned, please find the new tutorial here.

Objectives

The purpose of this document is to prepare the MATLAB work environment in order to use it for all of our future MATLAB curriculum.

                   NB: This part is very important. It is therefore necessary to follow these steps.

What you will need

  1. A Niryo One
  2. Ubuntu or Windows (with Windows, it will be necessary to install the software PuTTY at the following address https://www.putty.org/)
  3. MATLAB (2014 version or more recent ones)
  4. ROS Toolbox Add ons and ROS Toolbox interface for ROS custom Messages

Installation of add-ons

First of all, it is necessary to install the following add-ons by downloading them from MATLAB (add the links below):

      • ROS Toolbox
      • ROS Toolbox interface for ROS Custom Messages

Preparing the working environment for the Niryo One

  • Creating Niryo One messages from the ROS package

In order to control your Niryo One with MATLAB, it is essential to generate MATLAB interfaces for the Niryo One messages and ROS services. You can generate these interfaces from the “niryo_one_ros” package available on our Github.

The steps to follow are:

  • After downloading the package, get the full path of your “niryo_one_master” folder.
  • Open a new MATLAB session.
  • Specify the path to your folder by following this example:
folderpath = “D:niryo_one_ros-master”
  • In order to generate messages for MATLAB, use the rosgenmsg command as shown below:
rosgenmsg(folderpath) 
  • Follow the three steps indicated at the exit of rosgenmsg:
5.      Checking subfolder "A" for custom messages.

6. 

7.       Checking subfolder "B" for custom messages.

8.

9.       Checking subfolder "C" for custom messages.

10.    

11.     Building custom message files for the following packages:

12.    A

13.    B

14.    C

15.

16.     

17.     Generating MATLAB classes for message packages in 

18.     C:MATLABcustom_msgsmatlab_genjar

19.

20.     Loading file A-1.0.jar.

21.     Generating MATLAB code for A/DependsOnB message type.

22.    Generating MATLAB code for B/Standalone message type. 2

23.

24.    Loading file B-1.0.jar.

25.

26.    Loading file C-1.0.jar.

27.    Generating MATLAB code for C/DependsOnB message type. 

28.

29.    To use the custom messages, follow these steps:

30.

31.     1. Edit javaclasspath.txt, add the following file locations as new lines, and 

32.     save the file: 

33.

34.     C:MATLABcustom_msgsmatlab_genjarA-1.0.jar

35.     C:MATLABcustom_msgsmatlab_genjarB-1.0.jar

36.     C:MATLABcustom_msgsmatlab_genjarC-1.0.jar

37.

38.     2. Add the custom message folder to the MATLAB path by executing: 

39. 

40.     addpath('C:MATLABcustom_msgsmatlab_genmsggen')

41.      savepath

42.

43.      3. Restart MATLAB and verify that you can use the custom messages. 

44.     Type "rosmsg list" and ensure that the output contains the generated 

45.      custom message types. 

46.

1. Open "javasclasspath.txt" (the path to this file is in the MATLAB terminal log) and add the new lines given by MATLAB.

2. Add this new path:

addpath('E:Niryo one- TP Matlabniryo_one_rosmatlab_genmsggen')

savepath

3. Restart MATLAB.

  • To ensure that these steps are successful, type the command below in MATLAB:
rosmsg list
  • Find messages from Niryo One in the output of your command:
niryo_one_msgs/CloseGripperRequest

niryo_one_msgs/CloseGripperResponse

niryo_one_msgs/DigitalIOState

niryo_one_msgs/GetDigitalIORequest

niryo_one_msgs/GetDigitalIOResponse

niryo_one_msgs/GetIntRequest

niryo_one_msgs/GetIntResponse

niryo_one_msgs/GetSequenceListRequest

niryo_one_msgs/GetSequenceListResponse

niryo_one_msgs/HardwareStatus

niryo_one_msgs/JoystickJointsAction

……………………..

Network configuration for a single robot  

In order to configure the network for a single robot, you need to follow these steps:

  • Find the username and IP address of your MATLAB PC. For this:

1. Open the cmd terminal and type the command:

hostname 

Example: Username of the PC : « WINDOWS-NIRYO ».

2. In the same terminal, type the command “ipconfig”:

ipconfig 

The IPv4 Address line therefore indicates the IP address of your PC. Here, the IP address is: 192.168.1.156.

Note: The IP address of your robot and the IP address of your PC must have the same subnet mask: 255.255.255.0. If this is not the case, it is important to connect your robot as well as your PC to the same network. 

  • Connect your Niryo One to Wifi then note its IP address (use Niryo One Studio and follow the steps in the User Manual). 

Example: IP address of the Niryo One: 192.168.1.118

N.B. The Niryo One username is by default "niryo-desktop".

  • Add usernames with IP addresses to the hosts file on your Windows PC. For this: 

1. Find Notepad in the "Start" menu and right click on it.

2. Select "Run as administrator".

3. In the notepad, click on "Open" in "File".

4. Open the "host" file in Windows Explorer using the path: C:WindowsSystem32driversetc 

5. Add usernames with the IP addresses found previously at the end of the hosts file and save the changes.

Example: 

192.168.1.118 niryo-desktop 

192.168.1.156 WINDOWS-NIRYO

  • Add usernames with IP addresses to the Niryo One hosts file. For this: 

1. Connect to the Niryo One via PuTTY (see https://niryo.com/docs/niryo-one/developer-tutorials/connect-to-the-raspberry-pi-3-via-ssh/).

2. Open the hosts file and type: 

sudo nano /etc/hosts

3. Add the usernames with the IP addresses found previously.

Example: 

192.168.1.118 niryo-desktop 

192.168.1.156 WINDOWS-NIRYO

4. Restart the Niryo One

sudo reboot now 

5. Check the previous configurations

6. Open MATLAB and ping the Niryo One IP address

Example:

!ping 192.168.1.118

Pinging <192.168.1.118> with 32 bytes of data: 

Reply from <192.168.1.118>: bytes=32 time=6ms TTL=64 

Reply from <192.168.1.118>: bytes=32 time=4ms TTL=64 

Reply from <192.168.1.118>: bytes=32 time=4ms TTL=64 

Reply from<192.168.1.118>: bytes=32 time=4ms TTL=6

N.B : find more information here: http://wiki.ros.org/ROS/NetworkSetup.

Network configuration for two Niryo One

In order to configure the network for two Niryo One, you need to follow these steps:

  • Connect the first Niryo One to Wifi and note its IP address (use Niryo One Studio and follow the steps in the User Manual). 

Example: Niryo One IP address: 192.168.1.118

  • Connect the second Niryo One to the same Wifi and note its IP address.

Example: IP address of the Niryo One: 192.168.1.136

N.B : Username for every Niryo One defaults to "niryo-desktop". In order to be able to use 2 robots with MATLAB you must change the hostname of one of the robots. We will admit that the name of the first robot will remain "niryo-desktop" and the name of the second robot will be "niryo-desktop-2".

To change your robot's username, follow the steps below. 

  • Find the username and IP address of your MATLAB PC. 
  • Open the cmd terminal and type:
hostname

Example: PC’s username: “WINDOWS NIRYO”.

  • Type on the same terminal:
ipconfig

PC IP Address : 192.168.1.156

N.B : The robot's IP address and the PC's IP address must have the same subnet mask: 255.255.255.0. If this is not the case, it’s necessary to connect the robot and the PC to the same network. 

  • Add usernames with IP addresses to the hosts file on your Windows PC. For this: 

1. Find notepad in the start menu and right click on it.

2. Select “Execute as administrator“.

3. In the notepad, click on "Open" in "File".

4. Open the "host" file in Windows Explorer using the path: C:Windows System32driversetchosts.

5. Add usernames with the IP addresses found previously at the end of the hosts file and save the changes:

Exemple : 

192.168.1.118 niryo-desktop 

192.168.1.136 niryo-desktop-2 

192.168.1.156 WINDOWS-NIRYO

  • Add usernames with IP addresses to the hosts file for your first Niryo One. For this: 

1. Connect to the Niryo One via PuTTY (see https://niryo.com/docs/niryo-one/developer-tutorials/connect-to-the-raspberry-pi-3-via-ssh/).

2. Open the hosts file then type: 

sudo nano /etc/hosts

3. Add usernames with the IP addresses found previously.

Example: 

192.168.1.118 niryo-desktop 

192.168.1.156 WINDOWS-NIRYO

4. Restart the robot: 

sudo reboot now
  • For your second robot, it’s necessary to change its username and add usernames with the IP addresses to the hosts file. For this : 

1. Connect to the Niryo One via PuTTY (see https://niryo.com/docs/niryo-one/developer-tutorials/connect-to-the-raspberry-pi-3-via-ssh/

2. Open the hostname file then type: 

sudo nano /etc/hostname

3. Replace the name "niryo-desktop" by "niryo-desktop-2" or by the name you previously chose

4. Save changes and close (ctrl + x).

5. Open the hosts file then type: 

sudo nano /etc/hosts

6. Add usernames with the IP addresses found previously.

Example: 

192.168.1.118 niryo-desktop 

192.168.1.156 WINDOWS-NIRYO

7. Restart the robot:

sudo reboot now

8. Check the previous configurations: 

    • Open MATLAB and ping the IP address of the first Niryo One

Example: 

!ping 192.168.1.118

 

Pinging <192.168.1.118> with 32 bytes of data: 

Reply from <192.168.1.118>: bytes=32 time=6ms TTL=64 

Reply from <192.168.1.118>: bytes=32 time=4ms TTL=64 

Reply from <192.168.1.118>: bytes=32 time=4ms TTL=64 

Reply from<192.168.1.118>: bytes=32 time=4ms TTL=64

  • Open MATLAB and ping the IP address of the second Niryo One.

Example:

!ping 192.168.1.136

Pinging <192.168.1.118> with 32 bytes of data: 

Reply from <192.168.1.118>: bytes=32 time=6ms TTL=64 

Reply from <192.168.1.118>: bytes=32 time=4ms TTL=64 

Reply from <192.168.1.118>: bytes=32 time=4ms TTL=64 

Reply from<192.168.1.118>: bytes=32 time=4ms TTL=64

N.B. Find more information here http://wiki.ros.org/ROS/NetworkSetup.

In order to configure matlab in ethernet or network, go to the Matlab site by clicking here: https://fr.mathworks.com.

How can we help?