Skip to content
Branch: master
Find file History
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
examples Update Modbus documentation Jun 18, 2018
src/niryo_one_modbus Fix Modbus gripper open/close speed Jun 18, 2019
CMakeLists.txt Add Modbus server Dec 15, 2017
README.md Fix Modbus gripper open/close speed Jun 18, 2019
package.xml 2.1.0 Nov 23, 2018
setup.py Add Modbus server Dec 15, 2017

README.md

Niryo One Modbus/TCP Server

The Modbus/TCP server is running on port 5020 by default.

It has been built on top of the pymodbus library.

This enables you to make Niryo One communicate with a PLC, or another computer in the same network.

All 4 Modbus datastores are implemented : Coil, Discrete Input, Holding Register, Input Register. Each datastore has a different set of functionalities. Note that each datastore contains a completely different set of data.

Discrete Input and Input register are READ-ONLY tables. For Niryo One those have been used to keep the robot state.

Coil and Holding Register are READ/WRITE tables. For Niryo One those have been used to give user commands to the robot. Hence, those 2 tables do not contain the robot state, but the last given command.

Address tables start at 0.

Coil

Each address contains a 1bit value.

READ/WRITE (the stored values correspond to the last given command, not the current robot state)

Accepted Modbus functions :

  • 0x01: READ_COILS
  • 0x05: WRITE_SINGLE_COIL

This datastore can be used to set Digital I/O mode and state. Digital I/O numbers used for Modbus:

  • 0 : 1A
  • 1 : 1B
  • 2 : 1C
  • 3 : 2A
  • 4 : 2B
  • 5 : 2C
Address Description
0-5 Digital I/O mode (Input = 1, Output = 0)
100-105 Digital I/O state (High = 1, Low = 0)
200-299 Can be used to store your own variables

Discrete Input

Each address contains a 1bit value.

READ-ONLY

Accepted Modbus functions :

  • 0x02: READ_DISCRETE_INPUTS

This datastore can be used to read Digital I/O mode and state. See Coil section above for digital I/O number mapping.

Address Description
0-5 Digital I/O mode (Input = 1, Output = 0)
100-105 Digital I/O state (High = 1, Low = 0)

Holding Register

Each address contains a 16bit value.

READ/WRITE (the stored values correspond to the last given command, not the current robot state)

Accepted Modbus functions :

  • 0x03: READ_HOLDING_REGISTERS
  • 0x06: WRITE_SINGLE_REGISTER
Address Description
0-5 Joints (mrad)
10-12 Position x,y,z (mm)
13-15 Orientation roll, pitch, yaw (mrad)
100 Send Joint Move command with stored joints
101 Send Pose Move command with stored position and orientation
110 Stop current command execution
150 Is executing command flag
151 Last command result*
200-299 Can be used to store your own variables
300 Learning Mode (On = 1, Off = 0)
301 Joystick Enabled (On = 1, Off = 0)
310 Request new calibration
311 Start auto calibration
312 Start manual calibration
401 Gripper open speed (100-1000)
402 Gripper close speed (100-1000)
500 Select tool from given id **
510 Open gripper with given id
511 Close gripper with given id
512 Pull air vacuum pump from given id
513 Push air vacuum pump from given id

*The "Last command result" gives you more information about the last executed command :

  • 0 : no result yet
  • 1 : success
  • 2 : command was rejected (invalid params, ...)
  • 3 : command was aborted
  • 4 : command was canceled
  • 5 : command had an unexpected error
  • 6 : command timeout
  • 7 : internal error

** Select tool from id : you can find the tools ids here. Send id "0" to detach current tool.

Input Register

Each address contains a 16bit value.

READ-ONLY

Accepted Modbus functions :

  • 0x04: READ_INPUT_REGISTERS
Address Description
0-5 Joints 1-6 (mrad)
10-12 Position x,y,z (mm)
13-15 Orientation roll, pitch, yaw (mrad)
200 Selected tool ID (0 for no tool)
300 Learning Mode activated
301 Joystick enabled
400 Motors connection up (Ok = 1, Not ok = 0)
401 Calibration needed flag
402 Calibration in progress flag
403 Raspberry Pi 3 temperature
404 Raspberry Pi 3 available disk size
405 Raspberry Pi 3 ROS log size
406 Niryo One RPI image version n.1
407 Niryo One RPI image version n.2
408 Niryo One RPI image version n.3
409 Hardware version (1 or 2)

Connect to the Modbus/TCP server with Python, as a client :

You can test the Modbus/TCP server, for example from a remote computer on the same network.

#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient # you need to "pip install pymodbus" 

# Positive number : 0 - 32767
# Negative number : 32768 - 65535
def number_to_raw_data(val):
    if val < 0:
        val = (1 << 15) - val
    return val

def raw_data_to_number(val):
    if (val >> 15) == 1:
        val = - (val & 0x7FFF)
    return val

if __name__ == '__main__':
    address = 'insert the Modbus/TCP server IP address here'
    client = ModbusTcpClient(address, port=5020)
    client.connect()

    # Your code here
    # Check out the pymodbus documentation : http://pymodbus.readthedocs.io/en/latest/index.html

    client.close()
You can’t perform that action at this time.