Add change perceptual capabilities - enriquecoronadozu/RIZE GitHub Wiki

You can use NEP, NEP-ROS-rosbridge or ROS-rosbridge to update the current perceptual state of your robot. For this, it is needed to publish messages in the JavaScript Object Notation (JSON) format.

Option 1: Using NEP

Advantages:

  • This is the default and easier option
  • Better performance for localhost and remote (in LAN) communication than the other options requiring rosbridge
  • End-user does not need to install ROS or other complex robotics middleware in their PCs
  • Can be integrated to python code using: (i) ROS; (ii) other robotics middleware; (iii) no middleware
  • Works for modules running on Windows 7-10, OSX 10.x and many Linux distributions (e.g. Ubuntu 14-20)
  • Connect modules in Python 2, Python 3, Java (including Android), C# (including Unity), MATLAB/Octave, Node.js
  • This option is already available when RIZE is installed. Therefore, there are no additional steps for end users or developers.
  • Same code for Python 2 and Python 3

Additional notes

  • This option was designed to enable end-user to install and launch robotics modules by their own even without the help of professional programmers/ robotics engineers

Example of how to publish a perceptual input to RIZE using NEP

import nep                                  # Import nep library
node = nep.node('python_sender')            # Define node name
pub = node.new_pub('/blackboard','json')    # Define topic and message type a JSON

.... # your code

# An example of message indicating that robot was touched in its head
msg = {'primitive':'touched', 'input':{"head":1}, "robot":"Fetch"}	

# An example of message indicating that robot now is not touched in its head
msg = {'primitive':'touched', 'input':{"head":0}, "robot":"Fetch"}	

pub.publish(msg)		# Send message

Explanation

This option will directly connect a Python 2 or Python 3 module to RIZE using the ZMQ (portable, usable and high-performance sockets) back-end. A NEP publisher will be registered and configurated to send JSON messages in the /blackboard topic. Messages must be defined as python dictionaries. Then, pub.publish will send messages to RIZE when needed.

Option 2: Using NEP-ROS-rosbridge

Advantages

  • Almost the same code can be used to send messages to RIZE using NEP, ROS 1.0 or ROS 2.0
  • For ROS 1.0 and ROS 2.0, python dictionaries are transformed to JSON

Additional notes when using ROS 1.0 or ROS 2.0

  • In this option, a skilled user need to install Ubuntu (for ROS 1.0) and ROS (1.0 or 2.0) in the target PC, as well as launch, required software components (e.g. roscore and rosbridge_suite)

  • This option can be better suited for academic projects where all software components will be executed in PCs of a robotics laboratory (using Ubuntu), rather in the end-user devices.

  • In RIZE it is possible to set the IP of the computer executing the rosbridge_server. This enables to execute RIZE in Windows or OSX and the robot components in Ubuntu (for developers using ROS). However, performance will be constrained to the rosbridge_suite capabilities and Wifi network.

Example of how to publish a perceptual input to RIZE using NEP-ROS 1.0

import nep                                  # Import nep library
node = nep.node('python_sender', "ROS")     # Define node name in ROS
pub = node.new_pub('/blackboard','json')    # Define topic and message type a JSON

.... # your code

# An example of message indicating that robot was touched in its head
msg = {'primitive':'touched', 'input':{"head":1}, "robot":"Fetch"}	

# An example of message indicating that robot now is not touched in its head
msg = {'primitive':'touched', 'input':{"head":0}, "robot":"Fetch"}	

pub.publish(msg)		# Send message

Explanation

The code is almost the same that using option 1. The main difference is in the nep.node function, which additional parameter enables to use ROS as back-end; therefore, using TCP/IP ROS sockets. Therefore, nep.node will create a ROS 1.0 node and node.new_pub will create a ROS 1.0 publisher. The topic must be defined as /blackboard. The pub.publish function will publish the JSON value (python dictionary) in ROS as a string. You need to execute the rosbridge server to communicate with RIZE.

Example of how to publish a perceptual input to RIZE using NEP-ROS 2.0

import nep                                  # Import nep library
node = nep.node('python_sender', "ROS2")    # Define node name in ROS 2.0
pub = node.new_pub('/blackboard','json')    # Define topic and message type a JSON

.... # your code

# An example of message indicating that robot was touched in its head
msg = {'primitive':'touched', 'input':{"head":1}, "robot":"Fetch"}	

# An example of message indicating that robot now is not touched in its head
msg = {'primitive':'touched', 'input':{"head":0}, "robot":"Fetch"}	

pub.publish(msg)		# Send message

Explanation

In this case, a ROS 2.0 publisher is created.

Option 3: Using ROS-rosbridge

Advantages

  • Can provide more flexibility to ROS users

Additional notes

  • The same additional notes that Option 2 Using NEP-ROS-rosbridge
  • Developers need to use some JSON library to transform a python dictionary to string and then publish this string

Steps:

  • Create a ROS (1.0 or 2.0) publisher with std_msgs/String as message type and /blackboard as topic name
  • Define your message as python dictionary. Example:
msg = {'primitive':'touched', 'input':{"head":1}, "robot":"Fetch"}
  • Transform this python dictionary to string
  • Publish this new string using ROS