1. Home
  2. Docs
  3. Yonohub
  4. Tutorials
  5. Create ROS2-Based Block

Create ROS2-Based Block

In this tutorial, you will be able to develop a ROS2-based YonoArc block that is written in Python. This block takes an image as input, performs semantic segmentation on it, then publish the image masked with the segmentation classes as an output. we will use a ready ROS2 package from this Github repo.

 Building the block’s environment.

  1. Open YonoEBuilder from Yonohub main view.
  2. At the top right click on “Create environment”.
  3. Let’s give the environment name, description and version number.
  4. Navigate to the “Requirments” tab.
  5. Choose “Ubuntu 18.04, CPU, Python 3, ROS2” as the Base image.
  6. Let’s install our block dependencies. in our case, we need “OpenCV, imutils, cv_bridge” we can install them like the screenshot then press “Express Build”.
  7. Wait until the status of the Environment becomes Released.

Now we have our block environment, let’s start building the block itself.

Create ROS2 Workspace.

  1. Click the Jupyter Notebook icon on Yonohub’s main view.
  2. Select the environment we have just built in the previous steps.
  3. Under the General tab, select C1 since we only need Jupyter Notebook to develop the block.
  4. Click Express Launch. Wait until Jupyter Notebook finishes loading.
  5. Once Jupyter Notebook is running, click its icon then click the Web UI URL.
  6. Start the Terminal by clicking New >> Terminal.
  7. Let’s source ROS2 installation by executing the following command in the terminal
  8. Run the following command in the same terminal to create the ROS2 workspace.
  9. let’s clone our ROS2 package from GitHub inside the src folder of our ROS2 workspace.
  10. We have our ROS2 workspace ready by now, let’s save it on our YonoDrive and close Jupyter.

Create YonoArc Project.

  • Click the YonoArc icon on Yonohub’s main view.
  • Click the + button at the upper-left corner then click Block Manager.

Or you can access it directly from this link. https://app.yonohub.com/blockbuilder/

At the top-right, click “Create project” and set the attributes of the project as follows. (note: don’t forget to choose the environment we built in the previous steps. in my case, it’s called “opencv_ROS2”).

Select the project and click Build. Select C1 as the resource model and Click Build. Wait until the status of the project becomes Release Ready.

The next step is to configure the block properties, ports and resources.

  • Navigate to the Blocks tab and select the “Semantic Segmentation ROS2” project from the drop-down list.
  • Select “Unreleased” from the project version drop-down since this new version has not been released yet.
  • Click the “semantic_segmentation/segment” entry that appears in the left sidebar to select the ROS2 node we wish to use.

Let’s fill the block name, description and choose a suitable toolbox and Minimum Resources.

Now we are ready to define the block’s ports. as we mentioned at the beginning the block has one input port and one output port and both of the message type “sensor_msgs/Image”.

what about the ROS Name? This is the name of the topic used in the ROS node. we can know them from the node source code.

input port would map to the topic the node is subscribed to. the output port would map to the node’s publishing topic.

After defining the two ports we should have the following.


Now everything is ready. Click “Save” at the upper-left corner of the block information. You can see that the name of the block has changed on the left sidebar to Splitter, the block name you specified.

Let’s release the project.

  • Navigate to the Projects tab.
  • Select the project and click Release.
  • Set the version to 0.1.0 and click Release.

After releasing the block you can drag and drop it in one of your pipelines.

Congratulation now you have a ROS2 based YonoArc block for semantic segmentation