How to create a new component?¶
Summary
- Information about how to create a new component.
- module.yaml definition
What can be integrated as a component?¶
Technically, each ROS package is susceptible to be integrated as a component in drag&bot. Components are thought to provide an interface to hardware or software algorithms, e.g. a robot driver, a computer vision component or a program library.
Component structure¶
Each drag&bot component requires to have a module_config directory containing at least one module_X.yaml. Those YAML files describe which ROS launch script will be initialized, its description and the different parameters which can be configured. Some components can have different variations and therefore if more than one module_X.yaml exists, all of them will be selectable in the component manager tab of drag&bot Studio. This is for example the case of the UR driver, where the same component allows to use UR3, UR5 and UR10 robots.
YAML fields:
- package: the name of the corresponding ROS package
- name: displaying name in drag&bot
- description: extra information about the component
- type: semantic categorization of the component. This follows an hierarchical description like a directory in linux. Typical categorization is driver/robot/name_of_the_robot
- roslaunch: name of the ROS launch file which will be started with the component.
- rosshutdown (optional): name of the ROS launch file which will be started when the component is stopped or before the configuration is updated. It's purpose is to clear the components ROS parameters from the ROS Parameter Server.
- configuration: a list of variables which can be configured. These variables are passed to the ROS launch file as input arguments (arg).
- nodes: ROS nodes which are started and monitored with the component.
- status_topic: name of the topic which publishes the status of the component.
- block_list (optional): list of services or topics that are block based on access level. More Information about access levels
- wizards (optional): a list of wizard definitions
Configuration variables contained in configuration tag follow this structure:
- id: name of the variable
- namespace: left empty
- name: displaying name in drag&bot
- description: extra information
- datatype: drag&bot uses this tag to parse and limit the entered values for this variable. Accepted values are: string, int, float, bool, select.
- default: default value of the variable. This is defined as string.
Nodes:
- node_callerid: name of the node in ROS
- type: ROS node file name
Blocklist:
- local_only: contains a list of services and/or a list of topics that are only available on devices with local access level
- services: list of service names
- topics: list of topic names
- remote_only: contains a list of services and/or a list of topics that are only available on devices with remote access level and higher ( = remote & local )
- services: list of service names
- topics: list of topic names
Wizards (how to create a component wizard)
- name: The name of this wizard. This name will be used where ever the wizard will be available.
- tag: The tag of the custom-element.
- file: The filepath of the html element relative to the component base. (e.g. wizards/my-wizard.html)
- dataType (optional): The parameter dataType which can be parameterized by this wizard
- use_in (optional): A list of values where the wizard can be used. Possible values are 'operator_panel' and 'operator_cockpit'.
For example, the module_ur3.yaml contains the following data:
package: ur_driver
name: "Universal Robot Model 3"
description: "Universal Robot Model 3"
type: driver/robot/ur/3
roslaunch: ur3.launch
rosshutdown: stop.launch
configuration:
- id: ip
namespace: ''
name: 'Robot IP'
description: 'The IP address of the robot'
datatype: string
default: '127.0.0.1'
- id: sim
namespace: ''
name: 'Simulation'
description: 'True when using the UR simulation'
datatype: bool
default: 'true'
nodes:
- node_callerid: /ur_driver
type: ur_driver
status_topic: /ur_driver/status
A component should publish a ROS topic peridically indicating its health status. The message can be found in this public github repository (ComponentStatus.msg). Please check the following examples to see how status is published. Also be aware, that the status topic indicated in module_x.yaml must be the same.
Adding Function Blocks to he component¶
Functions blocks can be packed in a component inside fnb directory. This directory is optional and only required if function blocks are attached to the component.
Once the component is installed in drag&bot, if the component includes function blocks, then you can find them in a new tab as it is indicated in Import Function Blocks page.
Examples¶
drag&bot provides two components as public examples. You need to clone each of them in your ROS overlay workspace (Where to find the overlay workspace?) in order to install them in drag&bot. During restart of drag&bot the components will be compiled and included automatically in the component list.
In order to understand the examples some ROS and programming knowledge is recommended.
dnb_component_example - Add two numbers¶
Download
This component can be found here in the drag&bot public Github .
The dnb_component_example was created for teaching purposes. A ROS node programmed in Python provides a ROS service for adding two numbers. It also includes a packaged function block in the fnb directory, which can be imported in drag&bot Studio.
The component has a couple of configuration variables. Only Sum offset and Use offset are relevant for the calculation.
- Sum offset: a third value to add together with the inputs of the function block.
- Float example: unused
- String example: unused
- Selector example: unused
- Use offset: activates or deactivates the offset for the sum result.
The ROS launch file start.launch passes the arguments as parameters to the ROS node. The ROS node also publishes its status through the status topic. This is not compulsory, but recommended for letting drag&bot know the health of a component.
The included function block called AddTwoNumbers has two floats as inputs and produces a float number as output. These two numbers are added together with the offset to produce the result.
usb_cam - Generic USB camera driver¶
Download
This component can be found here in the drag&bot public Github .
The usb_cam component is the generic USB camera driver forked from the official ROS repository. It is programmed in C++. Now, the component includes a yaml file which makes it visible to drag&bot when located in dnb_catkin_ws/src directory.
Component configuration variables included in the module_usb_cam.yaml:
- Video device: the linux video device file located in /dev
- Width: pixel width
- Height: pixel height
Once the component is running, it publishes a topic containing the picture. This topic is visible in drag&bot Studio, for example, in the Camera tab. Also localization vision function blocks can use this topic for the localization.