<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Santosh Balaji Selvaraj on Medium]]></title>
        <description><![CDATA[Stories by Santosh Balaji Selvaraj on Medium]]></description>
        <link>https://medium.com/@santoshbalaji?source=rss-a335b8e1e855------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cLl_KVh81Cxm_M_UmOcLdg.jpeg</url>
            <title>Stories by Santosh Balaji Selvaraj on Medium</title>
            <link>https://medium.com/@santoshbalaji?source=rss-a335b8e1e855------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:45:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@santoshbalaji/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Manipulation of robot arm with MoveIt2 — Adding MoveIt Configuration — 3]]></title>
            <link>https://medium.com/@santoshbalaji/manipulation-of-robot-arm-with-moveit2-adding-moveit-configuration-3-7a4246890e6c?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a4246890e6c</guid>
            <category><![CDATA[moveit2]]></category>
            <category><![CDATA[robot-arm]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[manipulationandcontrol]]></category>
            <category><![CDATA[robotics]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 03:52:00 GMT</pubDate>
            <atom:updated>2025-01-29T05:21:16.887Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Manipulation of robot arm with MoveIt2 — Adding MoveIt Configuration — 3</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OooFsf_3a0JTkl8qXFtb-A.png" /><figcaption><strong>What a reader can do after reading this article</strong></figcaption></figure><p><strong>Please note the source code for this tutorial series can be found at this </strong><a href="https://github.com/santoshbalaji/pick_and_place.git"><strong>link</strong></a></p><p>This tutorial is a continuation from <a href="https://medium.com/@santoshbalaji/manipulation-with-moveit2-visualizing-robot-arm-in-simulation-1-8cd3a46d42b4"><strong>previous article 1</strong></a> and <a href="https://medium.com/@santoshbalaji/manipulation-of-robot-arm-with-moveit2-adding-camera-end-effector-and-actuating-the-robot-2-9726a47fd3cd"><strong>previous article 2</strong></a>. So far in our tutorial series we managed to simulate the robot arm in gazebo with camera and vacuum gripper plugins attached. We managed to actuate the robot arm to move from one position to other position as well. The current part will address configuration of MoveIt to control the robot arm. This part will be an overview on getting things configured to run robot arm simulation with MoveIt. The subsequent parts of tutorial will deep dive into different features available in MoveIt. This tutorial assumes moveit2 associated ros2 packages are installed in the system. Later I will try to create a separate article to show installation procedures for moveit2. More information regarding the configuration for MoveIT can be found in this <a href="https://moveit.picknik.ai/main/doc/how_to_guides/moveit_configuration/moveit_configuration_tutorial.html"><strong>official link</strong></a>.</p><p><strong>MoveIt Setup Assistant</strong></p><p>Run the following command to start MoveIt setup assistant. The MoveIt setup assistant allows to create a basic template for configuration files needed to control the robot arm with MoveIt. Follow the instructions listed in the picture below to complete the process.</p><pre>ros2 launch moveit_setup_assistant setup_assistant.launch.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0B081sl2P7oE3YTKGVj_Dw.png" /><figcaption>create/edit configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y-2DL0BjrESBVh96W-xBew.png" /><figcaption>create / edit configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6cVG-oR67-IzntwMiYSXVw.png" /><figcaption>self-collision configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlWmjRLJ6Q9wf2xdxWJ3MA.png" /><figcaption>planning group configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtD57CtrxlQJq3jUD3pNAg.png" /><figcaption>planning group — kinematic chain configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C90jKfg-H5BW8wGULPuHMA.png" /><figcaption>planning group configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YkHj753q3Jp27pK7wwmm6Q.png" /><figcaption>planning group — joint configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FtZsK4d4PTyosee6NPSOg.png" /><figcaption>planning group configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySvssupMwoG1RKKholCMwQ.png" /><figcaption>planning — link configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0LHumhAsGXxYjWNnpVFYAg.png" /><figcaption>planning configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*PyGPdhMNKdzs4DI9TBApNw.png" /><figcaption>ros2 controller configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJ0B5SnmA3qEnaOMuMVdTQ.png" /><figcaption>ros2 controller configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*1VsY5fAZ4aTPeB2R7SgsUQ.png" /><figcaption>moveit controller configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iHx_ftxa1iP9RGy8uVd7YA.png" /><figcaption>moveit controller configuration</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xYjMoTUjiFvuleg8g-30Gg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIzqhQabGNix_IKas_ickA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*IAUt8UyzChe-UyoZY0CAyQ.png" /></figure><p>Add the following file to config folder inside the package created for MoveIT configuration to configure CHOMP planner. This is not added when auto-generating the package by MoveIT setup assistant.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac4208deb388f50efece45f4cdc18edd/href">https://medium.com/media/ac4208deb388f50efece45f4cdc18edd/href</a></iframe><p>Add the following file to config folder inside the package created for MoveIT configuration to configure OMPL based planners. This is not added when auto-generating the package by MoveIT setup assistant.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba6a8f659e5e803aa0b6e8bb0666b371/href">https://medium.com/media/ba6a8f659e5e803aa0b6e8bb0666b371/href</a></iframe><p>The following configuration is to specify which kinematics plugin can be used by MoveIT for computing inverse kinematics. More information on other available kinematics plugin can be found in this <a href="https://moveit.picknik.ai/humble/doc/examples/kinematics_configuration/kinematics_configuration_tutorial.html"><strong>link</strong></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd978a8c4c237652da703af923088602/href">https://medium.com/media/cd978a8c4c237652da703af923088602/href</a></iframe><p>The following configuration is for setting joint position, velocity, acceleration and joint limits to be considered by MoveIT during its planning and execution.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f675aee7a460d87366765c59b71fc0dc/href">https://medium.com/media/f675aee7a460d87366765c59b71fc0dc/href</a></iframe><p>The next configuration is for setting up the ros2 controllers to actuate the robot both in simulation. For controlling a real robot this controller need to modified with the other controllers compatible with the robot. For example UR robot uses scaled joint trajectory controller which has hardware interfaces configured to communicate bidirectionally with the robot.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a93ef9882797139a40eb583aede8c29b/href">https://medium.com/media/a93ef9882797139a40eb583aede8c29b/href</a></iframe><p>The next configuration is for specifying different planning groups present and information on collision configuration for the associated joints.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/680fa5c2bb45f50699eb41864e9e1019/href">https://medium.com/media/680fa5c2bb45f50699eb41864e9e1019/href</a></iframe><p>The next file is for launch configuration to startup moveit related nodes and rviz to visualize and allow planning with moveit visualization plugins.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f784269b8b6f58e621271ed4e37df92/href">https://medium.com/media/1f784269b8b6f58e621271ed4e37df92/href</a></iframe><h3>Launch Instructions</h3><p>The following are the steps required to build and launch the simulation</p><p>Run the following command in your ROS workspace to build the required packages</p><pre>colcon build --packages-select pick_and_place_description pick_and_place_simulation pick_and_place_test_nodes pick_and_place_moveit_config</pre><p>The following command is to launch robot arm simulation in gazebo</p><pre>ros2 launch pick_and_place_simulation start_simulation.launch.py</pre><p>The upcoming command is to launch moveit nodes</p><pre>ros2 launch pick_and_place_moveit_config start_moveit.launch.py</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FKwqCjzaM4qA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DKwqCjzaM4qA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FKwqCjzaM4qA%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b98ec792937f2ef91ba96e2c2e015d26/href">https://medium.com/media/b98ec792937f2ef91ba96e2c2e015d26/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a4246890e6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manipulation of robot arm with MoveIt2 — Adding Camera, End effector and Actuating the robot — 2]]></title>
            <link>https://medium.com/@santoshbalaji/manipulation-of-robot-arm-with-moveit2-adding-camera-end-effector-and-actuating-the-robot-2-9726a47fd3cd?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/9726a47fd3cd</guid>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[robot-arm]]></category>
            <category><![CDATA[manipulationandcontrol]]></category>
            <category><![CDATA[moveit2]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Sun, 04 Aug 2024 18:19:39 GMT</pubDate>
            <atom:updated>2024-08-04T19:16:00.683Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>Manipulation of robot arm with MoveIt2 — Adding Camera, End effector and Actuating the robot — 2</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mMVeHdUJiJMc-YR78p3Czg.png" /><figcaption><strong>What a reader can do after reading this article</strong></figcaption></figure><p><strong>Please note the source code for this tutorial series can be found at this </strong><a href="https://github.com/santoshbalaji/pick_and_place.git"><strong>link</strong></a></p><p>This tutorial is a continuation from this <a href="https://medium.com/@santoshbalaji/manipulation-with-moveit2-visualizing-robot-arm-in-simulation-1-8cd3a46d42b4">previous article</a>. So far we have completed creating a robot arm model and visualized it in Rviz and Gazebo. The current article will continue to:</p><ul><li>Add Depth Camera for getting 3d perception of the environment</li><li>Add Vacuum gripper as end effector for the robot arm for performing pick and place operation</li><li>Actuate the robot by directly passing the Joint Trajectory Controller (<strong>JTC</strong>) commands</li></ul><h4>Adding Gripper Plugin</h4><p>For the current setup we will be doing pick and place using the robot arm. We will be using vacuum gripper which works based on air pressure. On applying air pressure the end effector will grab the object of interest. There is a dedicated <a href="https://github.com/ros-simulation/gazebo_ros_pkgs/blob/ros2/gazebo_plugins/src/gazebo_ros_vacuum_gripper.cpp">vacuum gripper plugin</a> in gazebo to address this scenario. Refer to the <a href="https://github.com/ros-simulation/gazebo_ros_pkgs/blob/ros2/gazebo_plugins/worlds/gazebo_ros_vacuum_gripper_demo.world">link</a> for example on how to use the plugin</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*ja4ra_r8mjqbF1Kw" /><figcaption><strong>Picture of Vacuum gripper</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ca47626d3cb99ef856822de2522c78c/href">https://medium.com/media/4ca47626d3cb99ef856822de2522c78c/href</a></iframe><p><strong>Refer to the </strong><a href="https://github.com/santoshbalaji/pick_and_place/blob/5753c3226c864d6626cda7a11c6842928c40117c/pick_and_place_description/urdf/robot_arm.xacro#L349"><strong>link</strong></a><strong> for the file associated with code snippet</strong></p><ul><li>In the above code snippet at <strong>line 5</strong> we are adding the gripper plugin.</li><li>First at <strong>line 6</strong> we need to specify <strong>which link on the robot</strong> is going to act as gripper. For our case it is going to be <strong>top wrist</strong> which is the last link connected to the end of the robot arm.</li><li>At <strong>line 7 </strong>we specify from <strong>what distance the grasping action</strong> <strong>should begin</strong> in cm.</li><li>At <strong>line 8</strong> we specify <strong>which plane should not be grasped</strong>. For our case the ground plane from gazebo should not have any effect from the grasping action. So we explicitly specify that the ground plane from gazebo should not be taken into the physics computation for grasping effect.</li><li>On running this plugin there will be a <strong>topic “/grasping”</strong> which specifies the grasp status and <strong>service “/switch”</strong> which acts as toggle to enable or disable the grasping via vacuum.</li></ul><h4>Adding Camera Plugin</h4><p>In order to perform pick and place operation of an object the first step involved is to find the position of object of interest. This can usually be 6 pose representing (x, y, z, <em>ψ, θ, φ). </em>For this purpose a <a href="https://github.com/ros-simulation/gazebo_ros_pkgs/blob/ros2/gazebo_plugins/src/gazebo_ros_camera.cpp">depth camera plugin</a> is added to the URDF in-order to simulate the depth perception. Refer to the <a href="https://github.com/ros-simulation/gazebo_ros_pkgs/blob/ros2/gazebo_plugins/worlds/gazebo_ros_depth_camera_demo.world">link</a> for example on how camera plugin can be added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/0*-CoS8dQakdCmp9z_.png" /><figcaption><strong>Picture of Depth Camera</strong></figcaption></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90614accd38fe8d6e45e974f4c3b13f9/href">https://medium.com/media/90614accd38fe8d6e45e974f4c3b13f9/href</a></iframe><p><strong>Refer to the </strong><a href="https://github.com/santoshbalaji/pick_and_place/blob/5753c3226c864d6626cda7a11c6842928c40117c/pick_and_place_description/urdf/robot_arm.xacro#L366"><strong>link</strong></a><strong> for the file associated with code snippet</strong></p><ul><li>In <strong>line 1</strong> we specify which <strong>link of the robot is treated as camera link</strong></li><li>In <strong>line 2</strong> we <strong>add depth camera</strong> and rest of the lines inside the sensor tag represents the <strong>parameters</strong> associated with the camera.</li><li><strong>Line 3</strong> specifies the <strong>rate of output</strong> from the simulated camera (100Hz = 1/100 = 0.01 sec =&gt; 1 frame is sent every 0.01 sec)</li><li><strong>Line 6</strong> specifies the <strong>horizontal field of view</strong> denoting what is the coverage area of output sent from simulated camera</li><li>Line <strong>8, 9, 10</strong> denotes the image output <strong>width, height and format</strong></li><li><strong>Line 15 near</strong> parameter is to specify<strong> minimum distance for camera coverage</strong> is started and <strong>Line 16 far </strong>parameter is to specify <strong>maximum distance for camera coverage</strong></li><li><strong>Line 18–22</strong> is to introduce<strong> noise</strong> for the camera output</li><li><strong>Line 29</strong> is to specify <strong>minimum distance for depth output</strong> from camera coverage and <strong>Line 30</strong> is to specify <strong>maximum distance for depth output</strong> from camera coverage</li><li>In <strong>line 24</strong> we add the <strong>depth camera plugin</strong> in-order to enable the depth perception.</li></ul><h4>Actuating the robot with Joint Trajectory commands</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c5c258d619f30a683f6030ac89f88c9d/href">https://medium.com/media/c5c258d619f30a683f6030ac89f88c9d/href</a></iframe><p><strong>Refer to the </strong><a href="https://github.com/santoshbalaji/pick_and_place/blob/5753c3226c864d6626cda7a11c6842928c40117c/pick_and_place_test_nodes/src/test_sending_trajectory.cpp#L1"><strong>link</strong></a><strong> for the file associated with code snippet</strong></p><ul><li>The above code snippet creates a call to the following action “/joint_trajectory_position_controller/follow_joint_trajectory” with the joint trajectory command values.</li><li>More info on how command can be sent to JTC controller can be found in the following links (<a href="https://control.ros.org/rolling/doc/ros2_controllers/joint_trajectory_controller/doc/userdoc.html">JTC</a>, <a href="https://control.ros.org/rolling/doc/ros2_controllers/joint_trajectory_controller/doc/trajectory.html#joint-trajectory-controller-trajectory-replacement">Preemption Policies</a>)</li></ul><h3>Launch Instructions</h3><p>The following are the steps required to build and launch the simulation</p><p>Run the following command in your ROS workspace to build the required packages</p><blockquote><strong><em>colcon build — packages-select pick_and_place_description pick_and_place_simulation pick_and_place_test_nodes</em></strong></blockquote><p>The following commands are to launch robot arm simulation in gazebo and to test joint trajectory commands for actuating the robot.</p><p>Run the following command to start gazebo simulation</p><blockquote><strong><em>ros2 launch pick_and_place_description start_gazebo.launch.py</em></strong></blockquote><p>Run the following command to start issuing joint trajectory controller commands</p><blockquote><strong><em>ros2 run pick_and_place_test_nodes test_sending_trajectory</em></strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFKnWfxRQbqo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFKnWfxRQbqo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFKnWfxRQbqo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/4953f70e9e6964339423d2bd1c55c692/href">https://medium.com/media/4953f70e9e6964339423d2bd1c55c692/href</a></iframe><p>The following commands are to launch robot arm simulation in gazebo and to test the vacuum gripper</p><p>Run the following command to start gazebo simulation</p><blockquote><strong><em>ros2 launch pick_and_place_simulation start_simulation.launch.py</em></strong></blockquote><p>Run the following command to start and stop the vacuum grasp action</p><blockquote><strong><em>ros2 service call /switch std_srvs/srv/SetBool data:\ true\</em></strong></blockquote><blockquote><strong><em>ros2 service call /switch std_srvs/srv/SetBool data:\ false\</em></strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FCAhkC24YObY%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DCAhkC24YObY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FCAhkC24YObY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/2659c0bd46a7082aaf5d8f8113142c3a/href">https://medium.com/media/2659c0bd46a7082aaf5d8f8113142c3a/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9726a47fd3cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manipulation with MoveIt2 — Visualizing robot arm in simulation — 1]]></title>
            <link>https://medium.com/@santoshbalaji/manipulation-with-moveit2-visualizing-robot-arm-in-simulation-1-8cd3a46d42b4?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/8cd3a46d42b4</guid>
            <category><![CDATA[moveit2]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[robot-arm]]></category>
            <category><![CDATA[ros2]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 05:39:39 GMT</pubDate>
            <atom:updated>2024-08-04T19:08:05.906Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>Manipulation of robot arm with MoveIt2 — Visualizing robot arm in simulation — 1</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H9gSEhIK64GEGRUoIUkq-w.png" /><figcaption><strong>What a reader can do after reading this article</strong></figcaption></figure><p><strong>Please note the source code for this tutorial series can be found at this </strong><a href="https://github.com/santoshbalaji/pick_and_place.git"><strong>link</strong></a></p><p>The series of articles focus on how a robot arm can be controlled using MoveIt2 framework. When it comes to manipulation the following are the components required for its control.</p><ol><li><strong>Real robot (or) Simulation environment</strong> capable of accepting joint configurations as goals which then gets translated to actual robot movement. In return the system needs to provide feedback of its current configuration or state.</li><li><strong>Planners </strong>capable of generating set of joint configurations required to move a robot arm from an existing state to goal state.</li><li><strong>Forward Kinematics — </strong>Algorithm or Math which can help to convert joint configurations (<em>θ1</em>, <em>θ2</em>, <em>θ3</em>, ….., <em>θ</em>n) of robot arm to end effector Cartesian space pose (x, y, z, <em>ψ, θ, φ).</em></li><li><strong>Inverse Kinematics — </strong>Algorithm or Math which can help to convert end effector Cartesian space pose (x, y, z, <em>ψ, θ, φ) </em>to<em> </em>joint<em> </em>configurations (<em>θ1</em>, <em>θ2</em>, <em>θ3</em>, ….., <em>θ</em>n) representing robot arm.</li><li><strong>Collision Checker — </strong>Algorithm capable of checking: self collision which is to check whether any part of robot body collides with any of its other parts, collision with external obstacles.</li><li><strong>Vision system</strong> — Depth or Monocular camera which provide feedback on target of interest to reach or about dynamic obstacles present in the operation space.</li></ol><p>In the later part of tutorial series I will be explaining about the components listed above.Enough of theory for now. Lets dive into making our first robot arm model and try to visualize it !!!!</p><h4><strong>URDF for robot model</strong></h4><p>The first step is to create an URDF representing the Robot model. For this tutorial I have considered using robot model with 4 degrees of freedom.</p><ul><li>First <strong>links </strong>has to be created which requires information related to physical configuration for a part of a robot. For simplicity sake a link can be considered as a metal part which has its dimensions and physics related properties.</li><li>Multiple links can be connected together by means of <strong>joint</strong>. A joint specifies how multiple parts in a robot can be connected and can be actuated. Can it rotate or move in linear axis ? More info related to this on the following link: <a href="https://wiki.ros.org/urdf/XML/joint">https://wiki.ros.org/urdf/XML/joint</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f25ec273ded5cb9fb93158500d212c68/href">https://medium.com/media/f25ec273ded5cb9fb93158500d212c68/href</a></iframe><h4>Configuration for enabling ros2_control</h4><p>The following configuration is to enable usage of <strong>ros2_control</strong> for the above described URDF joints. As mentioned before joints if it is not fixed then a control system is required to manage its actuation. It can be a closed loop or an open loop based control system. In order to enable this ros2_control provides with different control strategies. For our current use case we have taken 4 joints with <strong>revolute</strong> type (rotates across x or y or z — roll or pitch or yaw axis).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4af518e359854e2efb013cb0d67d3160/href">https://medium.com/media/4af518e359854e2efb013cb0d67d3160/href</a></iframe><h4><strong>Launch file for starting the simulation with control system</strong></h4><p>The following launch file starts the below mentioned nodes</p><ul><li><strong>Robot State Publisher</strong> — For broadcasting the robot description (URDF)</li><li><strong>Joint State Broadcaster (From Ros2_Control) </strong>— For broadcasting joint states for all the mobile joints</li><li><strong>Joint Trajectory Controller (From Ros2_Control)</strong> — Control system for managing the actuation of the joints</li><li><strong>Rviz</strong> — For visualizing the robot</li><li><strong>Gazebo Server</strong> — For running simulation with the robot model</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/806a22a0adbbb7320d72cb3a315b1c27/href">https://medium.com/media/806a22a0adbbb7320d72cb3a315b1c27/href</a></iframe><h4>CMakeLists.txt &amp; Package.xml for build</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b02655cc57598a41c8e0886a17242ea8/href">https://medium.com/media/b02655cc57598a41c8e0886a17242ea8/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6805571b90cde3714a16130f52ba00f/href">https://medium.com/media/b6805571b90cde3714a16130f52ba00f/href</a></iframe><h4>Launch Instructions</h4><p>The following are the steps required to build and launch the simulation</p><p>Run the following command in your ROS workspace to build the description package</p><blockquote><strong><em>colcon build — packages-select pick_and_place_description</em></strong></blockquote><p>Run the following command to start gazebo simulation</p><blockquote><strong><em>ros2 launch pick_and_place_description start_gazebo.launch.py</em></strong></blockquote><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgItT5GEGjnE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgItT5GEGjnE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgItT5GEGjnE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/bae53c5a686e96f45d1f6c7dccee76a8/href">https://medium.com/media/bae53c5a686e96f45d1f6c7dccee76a8/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8cd3a46d42b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autonomous mobile robot with ROS2 (Part 2) — URDF & Simulation]]></title>
            <link>https://medium.com/@santoshbalaji/autonomous-mobile-robot-with-ros2-part-2-urdf-simulation-8ccbc52b61cb?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ccbc52b61cb</guid>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Tue, 13 Jun 2023 22:07:42 GMT</pubDate>
            <atom:updated>2023-06-18T12:01:39.976Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Autonomous mobile robot with ROS2 (Part 2) — URDF &amp; Simulation</strong></h3><p>In the <a href="https://medium.com/@santoshbalaji/autonomous-differential-robot-with-ros-and-arduino-48288e142239"><strong>last part of tutorial</strong></a> we have seen how to setup a differential robot which can provide feedback of the movement using ROS 1 and Arduino. In this part we will see how to implement URDF model for the both omni directional drive and differential drive robot and visualize the model in Rviz and Gazebo. <a href="https://github.com/santoshbalaji/haruto_description.git"><strong>You can click on following link to refer to the github package used in the following tutorial</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2Q3RqqbvQ9z64uMvvGwqg.png" /><figcaption><strong>Final outcome of robot model</strong></figcaption></figure><h3><strong>What is URDF and Xacro ?</strong></h3><p>URDF stands for Unified Robot Description Format. It is an XML-based file format used to describe the structure, kinematics, and visual representation of robots in the field of robotics</p><p>Xacro stands for XML Macros. It is an extension of URDF (Unified Robot Description Format) that allows to parameterize and code reuse in robot descriptions. Xacro files are written in XML syntax and are typically used in conjunction with URDF files.</p><h3><strong>Package structure</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*DsvPDareWAJKWjcCLRBapA.png" /></figure><ol><li><strong>launch </strong>— folder contains different launch configurations (standalone only with rviz and simulation with gazebo)</li><li><strong>rviz </strong>— configuration file for visualizing robot model in rviz</li><li><strong>urdf — </strong>contains XML configurations for different parts of robot</li><li><strong>CMakeLists.txt </strong>— cmake build configuration for the package</li><li><strong>package.xml </strong>— dependencies related configuration</li></ol><h3><strong>Implementation of URDF</strong></h3><h4><strong>base.xacro</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c4840c3dfbb20408a81496d1f2081b9/href">https://medium.com/media/8c4840c3dfbb20408a81496d1f2081b9/href</a></iframe><p>In the above file geometry tag with box type is used to create rectangular plate. This base plate is being used at three layers (first_base_link, second_base_link, third_base_link).</p><h4><strong>lidar.xacro</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b49cb220280dd3b37eeb502bc5907da/href">https://medium.com/media/5b49cb220280dd3b37eeb502bc5907da/href</a></iframe><p>A rectangle box type model is added to mock the size of lidar in robot model. This can be replaced with actual STL file of lidar. This is represented as lidar_link in robot model. In the next part of tutorial lidar plugin will be added to simulation to mimic the behavior.</p><h4><strong>motor.xacro</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/618cded5605a74faea8ee2ec844746e1/href">https://medium.com/media/618cded5605a74faea8ee2ec844746e1/href</a></iframe><p>A rectangle box type model is added to mock the size of motor in robot model. This can be replaced with actual STL file of motor. This is represented as front_left_motor_link, front_right_motor_link, back_left_motor_link, back_right_motor_link in robot model.</p><h4><strong>pillar.xacro</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fa392e94ef7de50a6ad1713ec010eaa/href">https://medium.com/media/3fa392e94ef7de50a6ad1713ec010eaa/href</a></iframe><p>A cylinder type model is added to mock the size of pillar in robot model. This can be replaced with actual STL file of pillar. This is represented as first_front_left_pillar_link, first_front_right_pillar_link, first_back_left_pillar_link, first_back_right_pillar_link, second_front_left_pillar_link, second_front_right_pillar_link, second_back_left_pillar_link and second_back_right_pillar_link in robot model.</p><h4><strong>wheel.xacro</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb383fb9a81f4a06ba74d79729d76022/href">https://medium.com/media/eb383fb9a81f4a06ba74d79729d76022/href</a></iframe><p>A cylinder type model is added to mock the size of wheel in robot model. This can be replaced with actual STL file of wheel. For all the above configurations all the specified joints are of fixed type. For the wheel joints they can be of either fixed or continuous type based on the robot model.</p><p>If it is omni directional drive the gazebo planar plugin used only utilizes the base frame hence the wheel joints are of fixed type. On the other hand if it is of differential drive the gazebo differential drive plugin used only utilizes all four wheel joints and so they are of continuous type.</p><p>This is represented as front_left_wheel_link, front_right_wheel_link, back_left_wheel_link and back_right_wheel_link in robot model.</p><h4><strong>robot.xacro</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/056c6167c70a9e9ef61da0e8698f2957/href">https://medium.com/media/056c6167c70a9e9ef61da0e8698f2957/href</a></iframe><p>The above configuration is combination of all parts in robot model. It has base templates, pillars, motors and wheels. Further more it uses gazebo plugin for robot movement. For omni directional robot model gazebo based planar move plugin is used and for differential drive robot model gazebo based differential drive plugin is used.</p><h3><strong>Launch configuration to visualize in Gazebo</strong></h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17362584b3aaa47d4c0400f22caa2f6d/href">https://medium.com/media/17362584b3aaa47d4c0400f22caa2f6d/href</a></iframe><p>The following is the launch sequence for different nodes to start gazebo simulation</p><ol><li><strong>robot_state_publisher node — </strong>to publish robot description from urdf</li><li><strong>gazebo node — </strong>to start an empty gazebo world</li><li><strong>spawn_entity node — </strong>to spawn robot model in gazebo based on data received from robot description. This node also loads required gazebo plugins for the robot. The gazebo node is responsible for publishing transforms data</li><li><strong>rviz node — </strong>for visualizing the robot in rviz. The node is started after model is spawned in gazebo</li></ol><h3><strong>Results</strong></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FhTd9ykmecRg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DhTd9ykmecRg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FhTd9ykmecRg%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d7908f8aa274f79d502a65ec0d6a74c/href">https://medium.com/media/3d7908f8aa274f79d502a65ec0d6a74c/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBXSWMmkk77E%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBXSWMmkk77E&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBXSWMmkk77E%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f87d5d0ad696a0167d732999c1e52287/href">https://medium.com/media/f87d5d0ad696a0167d732999c1e52287/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ccbc52b61cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ROS2 library package setup and Unit testing with Catch2 (Part 2)]]></title>
            <link>https://medium.com/@santoshbalaji/ros2-library-package-setup-and-unit-testing-with-catch2-part-2-85743df786e9?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/85743df786e9</guid>
            <category><![CDATA[ament]]></category>
            <category><![CDATA[colcon]]></category>
            <category><![CDATA[catch2]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[cmake]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Tue, 27 Sep 2022 16:33:33 GMT</pubDate>
            <atom:updated>2022-09-27T16:33:33.286Z</atom:updated>
            <content:encoded><![CDATA[<p>The objective of this article is to provide an understanding on how libraries can be created in ROS2 which can be utilized by other ROS2 packages. In addition to this this article also covers up how to write unit tests using catch2 framework. <a href="https://medium.com/@santoshbalaji/ros2-library-package-setup-and-unit-testing-with-catch2-part-1-697e344f408f"><strong>Part 1</strong></a> of this article will be covering more on how library package is created. Part 2 will be covering on how a ROS2 package can utilize the created library</p><p><strong>Project structure outline</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*D0adsKZWTjpORDhItHLUcA.png" /></figure><p><strong>Process flow for library</strong></p><ol><li>Create header for logic functions under include/try_out/point_checker.hpp</li><li>Add implementation class for logic functions under src/point_checker.cpp</li><li>Create entry point for test class under test/main.cpp</li><li>Add unit tests under test/test_point_checker.cpp</li><li>Create CMakeLists.txt under root project directory</li><li>Create package.xml under root project directory</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/598b4e9457910d19a5162cae4022a49e/href">https://medium.com/media/598b4e9457910d19a5162cae4022a49e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b521c40d8a0afcc9d52e6a4f4e3605e/href">https://medium.com/media/6b521c40d8a0afcc9d52e6a4f4e3605e/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa5bb4ee14c0d9662f447ec12dcacc40/href">https://medium.com/media/fa5bb4ee14c0d9662f447ec12dcacc40/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8c826645b9e5c31499f3e34a5d7b1a5/href">https://medium.com/media/a8c826645b9e5c31499f3e34a5d7b1a5/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6165f1b4d8f7f08d5f1fdefa266aba1e/href">https://medium.com/media/6165f1b4d8f7f08d5f1fdefa266aba1e/href</a></iframe><p>Lets go a bit detailed on cmakelist created above</p><ol><li><strong>add_library </strong>— To create library with specified reference files</li><li><strong>add_executable — </strong>To create executable with specified files</li><li><strong>target_include_directories </strong>— Directories from internal and external packages to be included with the target. Command can be used</li><li><strong>target_link_libraries </strong>— Linking targets with libraries specified</li><li><strong>install directory at destination </strong>— The DIRECTORY form installs contents of one or more directories to a given destination</li><li><strong>install targets at destination</strong> — The TARGETS form specifies rules for installing targets from a project</li><li><strong>ament_add_catch2 </strong>— Creating test targets with test files provided for testing<br><strong>(Ament is a wrapper written over Cmake to simplify some functions for colcon build)</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03d37ba0a8a128b0e3a59f6ea3590276/href">https://medium.com/media/03d37ba0a8a128b0e3a59f6ea3590276/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8a010adb585c770919c1a4b5e3e2952/href">https://medium.com/media/c8a010adb585c770919c1a4b5e3e2952/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*Ai4vVDNWYVR59mItx7RASQ.png" /><figcaption>Test results after execution</figcaption></figure><p><strong>References<br></strong><a href="https://github.com/open-rmf/rmf_utils">https://github.com/open-rmf/rmf_utils</a> (Robotics middleware framework utilities)<br><a href="https://github.com/open-rmf/rmf_traffic">https://github.com/open-rmf/rmf_traffic</a> (Traffic management framework which uses the utility library)<br><a href="https://cmake.org/cmake/help/latest/index.html">https://cmake.org/cmake/help/latest/index.html</a> (Cmake documentation)<br><a href="https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html">https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html</a> (Enhanced version of Cmake for ROS2 packages)</p><p><strong>Source code<br></strong><a href="https://github.com/santoshbalaji/ros2-library-package-medium">https://github.com/santoshbalaji/ros2-library-package-medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85743df786e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ROS2 library package setup and Unit testing with Catch2 (Part 1)]]></title>
            <link>https://medium.com/@santoshbalaji/ros2-library-package-setup-and-unit-testing-with-catch2-part-1-697e344f408f?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/697e344f408f</guid>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[catch2]]></category>
            <category><![CDATA[ament]]></category>
            <category><![CDATA[cmake]]></category>
            <category><![CDATA[colcon]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Tue, 27 Sep 2022 13:53:27 GMT</pubDate>
            <atom:updated>2022-09-27T16:34:08.696Z</atom:updated>
            <content:encoded><![CDATA[<p>The objective of this article is to provide an understanding on how libraries can be created in ROS2 which can be utilized by other ROS2 packages. In addition to this this article also covers up how to write unit tests using catch2 framework. Part 1 of this article will be covering more on how library package is created. <a href="https://medium.com/@santoshbalaji/ros2-library-package-setup-and-unit-testing-with-catch2-part-2-85743df786e9"><strong>Part 2</strong></a> will be covering on how a ROS2 package can utilize the created library</p><p><strong>Project structure outline</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*RYGiIec2nvbc8KJ1z1rtuw.png" /></figure><p><strong>Process flow for library</strong></p><ol><li>Create header for 2d points under include/point.hpp</li><li>Add implementation class for 2d points under src/point.cpp</li><li>Create entry point for test class under test/main.cpp</li><li>Add unit tests under test/test_point.cpp</li><li>Add namespace config for cmake under cmake/try_out_utils-config.cmake.in )</li><li>Create CMakeLists.txt under root project directory (Config of lib is specified here)</li><li>Create package.xml under root project directory</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c26225e68b40d4df3e91b0e4effbf287/href">https://medium.com/media/c26225e68b40d4df3e91b0e4effbf287/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d828e588f94e83051377afdb78e1cf6/href">https://medium.com/media/5d828e588f94e83051377afdb78e1cf6/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa5bb4ee14c0d9662f447ec12dcacc40/href">https://medium.com/media/fa5bb4ee14c0d9662f447ec12dcacc40/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/343fb2909023ca41645b1b8a5a55dffc/href">https://medium.com/media/343fb2909023ca41645b1b8a5a55dffc/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ac0e6904f78f74418cf3864f9ccd743a/href">https://medium.com/media/ac0e6904f78f74418cf3864f9ccd743a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/37d533d68cebdd3108b5cfffc2e92f8d/href">https://medium.com/media/37d533d68cebdd3108b5cfffc2e92f8d/href</a></iframe><p>Lets go a bit detailed on cmakelist created above</p><ol><li><strong>include(GNUInstallDirs)</strong> — To allow usage of cmake install variables</li><li><strong>add_library </strong>— To create library with specified reference files</li><li><strong>target_include_directories </strong>— Directories from internal and external packages to be included with the target</li><li><strong>include(CMakePackageConfigHelpers)</strong> — Helpers functions for creating config files that can be included by other projects to find and use a package</li><li><strong>configure_package_config_file — </strong>configure_package_config_file() should be used instead of the plain <a href="https://cmake.org/cmake/help/latest/command/configure_file.html#command:configure_file">configure_file()</a> command when creating the &lt;PackageName&gt;Config.cmake or &lt;PackageName&gt;-config.cmake file for installing a project or library. It helps making the resulting package relocatable by avoiding hard-coded paths in the installed Config.cmake file</li><li><strong>write_basic_package_version_file </strong>— should be used to create version config file so the external packages on importing this library can perform compatibility check with version provided here</li><li><strong>install directory at destination </strong>— The DIRECTORY form installs contents of one or more directories to a given destination</li><li><strong>install files at destination</strong>— The FILES form specifies rules for installing files for a project. Installs files in the specified destination</li><li><strong>install exports at destination — </strong>The EXPORT form generates and installs a Make file containing code to import targets from the installation tree into another project</li><li><strong>export — </strong>Creates a file &lt;filename&gt; that may be included by outside projects to import targets named by &lt;target&gt;... from the current project&#39;s build tree. This is useful during cross-compiling to build utility executables that can run on the host platform in one project and then import them into another project being compiled for the target platform.(NAMESPACE)Prepend the &lt;namespace&gt; string to all target names written to the file</li><li><strong>install targets at destination with export </strong>— Snippet which installs targets at specified destination. EXPORToption associates the installed target files with an export called &lt;export-name&gt;</li><li><strong>ament_add_catch2 </strong>— Creating test targets with test files provided for testing</li><li><strong>target_link_libraries </strong>— Linking targets with libraries specified<br><strong>(Ament is a wrapper written over Cmake to simplify some functions for colcon build)</strong></li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4f747b533a9c585627ef4557e574c84/href">https://medium.com/media/b4f747b533a9c585627ef4557e574c84/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c50234216c2f82d52fb6ebc5bc065329/href">https://medium.com/media/c50234216c2f82d52fb6ebc5bc065329/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*FGMcpiPf8CCmyaGlH2JNHA.png" /><figcaption>Test results after execution</figcaption></figure><p><strong>References<br></strong><a href="https://github.com/open-rmf/rmf_utils">https://github.com/open-rmf/rmf_utils</a> (Robotics middleware framework utilities)<br><a href="https://github.com/open-rmf/rmf_traffic">https://github.com/open-rmf/rmf_traffic</a> (Traffic management framework which uses the utility library)<br><a href="https://cmake.org/cmake/help/latest/index.html">https://cmake.org/cmake/help/latest/index.html</a> (Cmake documentation)<br><a href="https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html">https://docs.ros.org/en/foxy/How-To-Guides/Ament-CMake-Documentation.html</a> (Enhanced version of Cmake for ROS2 packages)</p><p><strong>Source code<br></strong><a href="https://github.com/santoshbalaji/ros2-library-package-medium">https://github.com/santoshbalaji/ros2-library-package-medium</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=697e344f408f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker containers for web application with high availability (Load balanced)]]></title>
            <link>https://medium.com/@santoshbalaji/docker-containers-for-web-application-infrastructure-a8621e7eea25?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8621e7eea25</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[web-app-development]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Sun, 26 Sep 2021 16:25:15 GMT</pubDate>
            <atom:updated>2022-03-29T16:41:35.720Z</atom:updated>
            <content:encoded><![CDATA[<p>The aim of this article is to explain how to use docker to run a full stack web application. The article code based can be found at the following <a href="https://github.com/santoshbalaji/docker-web-app-medium"><strong><em>link</em></strong></a></p><h4><strong>Prerequisites</strong></h4><p>Basic knowledge in the following: JavaScript, Nodejs, MongoDB, Redis, Load balancers and Docker</p><h4><strong>Architecture Diagram</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*r2PuDFqUQpPrt7MEWbji1w.jpeg" /><figcaption>Architecture diagram for full stack web application presented in this article</figcaption></figure><ul><li>MongoDB (NoSQL database) for storing user information</li><li>Redis (Cache) for caching the user information. It will also assist in faster retrieval of user information.</li><li>Backend application server (Instance 1 &amp; 2) are application servers created using Nodejs which have api for creating and retrieving user information. Two instances are created for load balancing purposes.</li><li>Web UI application server which has UI to show all user information present in the system.</li><li>Nginx (Proxy and Load balancer) acts as proxy server for routing users to web ui and load balancer which routes the api calls from UI to different backend instances.</li></ul><h4><strong>Nodejs backend application</strong></h4><pre><strong><em>server.js</em></strong><br>const express = require(&#39;express&#39;);<br>const cors = require(&#39;cors&#39;);<br>const { promisify } = require(&#39;util&#39;);</pre><pre>const app = express();</pre><pre>// mongodb connection setup<br>const { MongoClient } = require(&#39;mongodb&#39;);<br>const db_client = new MongoClient(&#39;mongodb://localhost:27017&#39;);</pre><pre>// redis connection setup<br>const redis = require(&#39;redis&#39;);<br>const cache_client = redis.createClient(6379);<br>const lrange_cache = promisify(cache_client.lrange).bind(cache_client);<br>const rpush_cache = promisify(cache_client.rpush).bind(cache_client);</pre><pre>async function get_users(req, res)<br>{<br>  try<br>  {<br>    console.log(&#39;get users api accessed&#39;);<br>    // getting user information from redis cache<br>    const users = await lrange_cache(&#39;users&#39;, 0, -1);<br>    for(let i = 0; i &lt; users.length; i++)<br>    {<br>      users[i] = JSON.parse(users[i]);<br>    }<br>    res.send(users);<br>  }<br>  catch(e)<br>  {<br>    console.log(e);<br>    res.send({message: &#39;error in getting users&#39;});<br>  }<br>}</pre><pre>async function create_user(req, res)<br>{<br>  try<br>  {<br>    console.log(&#39;create user api accessed&#39;);<br>    const user = req.body;<br>    const db = db_client.db(&#39;test&#39;);<br>    // setting user information to database<br>    await db.collection(&#39;user&#39;).insertOne(user);<br>    // setting user information to redis cache<br>    await rpush_cache(&#39;users&#39;, JSON.stringify(user));<br>    res.send({message: &#39;new user created&#39;});<br>  }<br>  catch(e)<br>  {<br>    console.log(e);<br>    res.send({message: &#39;error in user creation&#39;});<br>  }<br>}</pre><pre>async function main()<br>{<br>  app.use(cors());<br>  app.use(express.urlencoded({ extended: true }));<br>  app.use(express.json());<br>  await db_client.connect();<br>  // mapping url for api<br>  app.get(&#39;/user&#39;, get_users);<br>  app.post(&#39;/user&#39;, create_user);<br>  // app server is running in port 3000<br>  app.listen(3000, function()<br>  {<br>    console.log(&quot;App is running&quot;);<br>  });<br>}</pre><pre>if(require.main == module)<br>{<br>  main();<br>}</pre><p>The above backend code does the following</p><ul><li>Starts backend app server running in port 3000</li><li>Create user registration and retrieval api</li><li>Stores information in MongoDB and Redis cache</li><li>Retrieval of user information happens direct from Redis cache</li></ul><h4>Nodejs UI server application</h4><pre><strong><em>index.html</em></strong><br>&lt;!DOCTYPE html&gt;<br>&lt;head&gt;<br>  &lt;title&gt;User information&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;table id=”usertable” style=”border: 1px solid black;”&gt;<br>    &lt;tr&gt;<br>      &lt;th&gt;Name&lt;/th&gt;<br>      &lt;th&gt;Country&lt;/th&gt;<br>    &lt;/tr&gt;<br>  &lt;/table&gt;<br>  &lt;script type=”text/javascript”&gt;<br>    // making ajax api call for getting user information<br>    var xmlhttp = new XMLHttpRequest();<br>    // url used is load balanced route<br>    var url = “http://localhost/api/user&quot;;<br>    xmlhttp.onreadystatechange = function()<br>    {<br>       if (this.readyState == 4 &amp;&amp; this.status == 200)<br>       {<br>         let users = JSON.parse(this.responseText);<br>         let user_table = document.getElementById(“usertable”);<br>         for(let i = 0; i &lt; users.length; i++)<br>         {<br>           let user_row = user_table.insertRow(i + 1);<br>           let user_name_cell = user_row.insertCell(0); <br>           let user_country_cell = user_row.insertCell(1);<br>           user_name_cell.innerHTML = users[i][‘name’];<br>           user_country_cell.innerHTML = users[i][‘country’];<br>         }<br>       }<br>    };<br>    xmlhttp.open(“GET”, url, true);<br>    xmlhttp.send();<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><pre><strong><em>server.js</em></strong><br>const express = require(&#39;express&#39;);<br>const app = express();<br>const port = 4000;</pre><pre>app.use(express.static(&#39;public&#39;));<br>// route to return static html files<br>app.get(&#39;/&#39;, (req, res) =&gt;<br>{<br>  res.sendFile(&#39;./public/index.html&#39;, { root: __dirname });<br>});</pre><pre>// ui server is running in port 4000<br>app.listen(port, function()<br>{<br>  console.log(&#39;ui app running&#39;);<br>});</pre><p>The above frontend code does the following</p><ul><li>Make Ajax api call to retrieve users information on opening the page</li><li>The API url used is load balanced route</li></ul><h4><strong>Nginx load balancer configuration</strong></h4><pre>user www-data;<br>worker_processes auto;<br>pid /run/nginx.pid;<br>include /etc/nginx/modules-enabled/*.conf;</pre><pre>events {<br>  worker_connections 768;<br>}</pre><pre>http {<br>  # creating load balancer instance group<br>  upstream backend {<br>    server backend_server_1:3000;<br>    server backend_server_2:3000;<br>  }</pre><pre>server {<br>    listen 80 default_server;<br>    listen [::]:80 default_server;<br>    server_name 127.0.0.1;<br>    client_max_body_size 0;<br>    client_body_buffer_size 128M;<br>           <br>    # redirecting /api route to api call via load balancer<br>    location /api {<br>      proxy_pass <a href="http://backend/">http://backend</a>;<br>    }</pre><pre>    # redirecting all root calls to ui server<br>    location / {<br>      proxy_pass <a href="http://ui_server:3000/">http://ui_server:3000</a>;<br>    }<br>  }<br>}</pre><h4><strong>Docker compose configuration</strong></h4><pre>version: &#39;3.6&#39;<br>services:</pre><pre>  # For MongoDB database container<br>  database:<br>    container_name: medium_database<br>    image: mongo<br>    # Internal docker port 27017 mapped to local port 27017<br>    ports:<br>      - &quot;27017:27017&quot;<br>  <br>  # For redis cache container<br>  cache:<br>    container_name: medium_cache<br>    image: redis<br>    # Internal docker port 6379 mapped to local port 6379<br>    ports:<br>      - &quot;6379:6379&quot;</pre><pre>  # Two same Nodejs docker instances created for load balancers<br>  # For Nodejs backend server container<br>  backend_server_1:<br>    container_name: medium_backend_server_1<br>    image: node<br>    working_dir: /home/node/app<br>    # Mounting the backend code base to docker internal folder<br>    volumes:<br>      - ./backend:/home/node/app<br>    # Internal docker port 3000 mapped to local port 3001<br>    ports:<br>      - &quot;3001:3000&quot;<br>    # This container depends on database and cache container<br>    # The container will start once these dependencies are up<br>    depends_on:<br>     - database<br>     - cache<br>    environment:<br>     - REDIS_HOST=redis://cache:6379<br>     - SWAGGER_PORT=3001<br>     - TZ=Asia/Singapore<br>    # Links are created since we need to connect external containers<br>    # The host URI will be using names provided in the links<br>    links:<br>     - cache:cache<br>     - database:database<br>    # command to start the Nodejs application<br>    command: sh -c &quot;npm install &amp;&amp; npm run start&quot;</pre><pre>  # For Nodejs backend server container<br>  backend_server_2:<br>    container_name: medium_backend_server_2<br>    image: node<br>    working_dir: /home/node/app<br>    # Mounting the backend code base to docker internal folder<br>    volumes:<br>      - ./backend:/home/node/app<br>    # Internal docker port 3000 mapped to local port 3002<br>    ports:<br>      - &quot;3002:3000&quot;<br>    # This container depends on database and cache container.<br>    # The container will start once these dependencies are up <br>    depends_on:<br>      - database<br>      - cache<br>    environment:<br>      - REDIS_HOST=redis://cache:6379<br>      - SWAGGER_PORT=3001<br>      - TZ=Asia/Singapore<br>    # Links are created since we need to connect external containers<br>    # The host URI will be using names provided in the links<br>    links:<br>      - cache:cache<br>      - database:database<br>    # command to start the Nodejs application<br>    command: sh -c &quot;npm install &amp;&amp; npm run start&quot;</pre><pre>  # For Nodejs static file server container (UI)<br>  ui_server:<br>    container_name: medium_ui_server<br>    image: node<br>    working_dir: /home/node/app<br>    # Internal docker port 4000 mapped to local port 3002<br>    ports:<br>      - &quot;3003:4000&quot;<br>    # Mounting the backend code base to docker internal folder<br>    volumes:<br>      - ./client:/home/node/app<br>    # The container depends on backend servers<br>    # The container will be started once these dependencies are up<br>    depends_on:<br>      - backend_server_1<br>      - backend_server_2<br>    # command to start the Nodejs application<br>    command: sh -c &quot;npm install &amp;&amp; npm run start&quot;</pre><pre>  # For nginx server container<br>  proxy_server:<br>    container_name: medium_proxy_server<br>    image: nginx<br>    # mount nginx settings<br>    volumes:<br>      - ./settings/nginx.conf:/etc/nginx/nginx.conf:ro<br>    # Internal docker port 80 mapped to local port 80<br>    ports:<br>      - &quot;80:80&quot;<br>    # container dependencies<br>    depends_on:<br>      - backend_server_1<br>      - backend_server_2<br>      - ui_server<br>    # links to be used in nginx configuration<br>    links:<br>      - backend_server_1:backend_server_1<br>      - backend_server_2:backend_server_2<br>      - ui_server:ui_server<br>    command: [nginx-debug, &#39;-g&#39;, &#39;daemon off;&#39;]</pre><ul><li>The <strong>database</strong> is a docker container for mongodb instance. The mongodb will be running on port 27017.</li><li><strong>Cache </strong>is a docker container for Redis instance. The port used is 6379</li><li><strong>Backend Server 1</strong> and <strong>Backend Server 2 </strong>are docker instances which runs Nodejs backend server. Two instances are created for load balancing purposes. Both the servers will be running on port 3001 and 3002 respectively.</li><li><strong>UI Server </strong>is a docker instance which runs Nodejs server for returning static html files. The server runs on port 3003.</li><li><strong>Proxy Server </strong>is a docker instance which runs Nginx server for load balancer and proxy server purposes</li><li>Refer to inline comments in the code to understand more on specific terms used in docker compose file</li></ul><h4>Conclusion</h4><p>The system obtained after completing this article is as follows</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzSjwktji5CbYTYuMgdNDQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9YjVmW50ymQuJcJ408JcPA.png" /><figcaption>Retrieving created user via ui</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8621e7eea25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Autonomous mobile robot with ROS2 (Part 1)- Arduino and ROS1 with bridge]]></title>
            <link>https://medium.com/@santoshbalaji/autonomous-differential-robot-with-ros-and-arduino-48288e142239?source=rss-a335b8e1e855------2</link>
            <guid isPermaLink="false">https://medium.com/p/48288e142239</guid>
            <category><![CDATA[autonomous-vehicles]]></category>
            <category><![CDATA[roses]]></category>
            <category><![CDATA[arduino]]></category>
            <dc:creator><![CDATA[Santosh Balaji Selvaraj]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 14:45:18 GMT</pubDate>
            <atom:updated>2023-06-20T06:26:07.264Z</atom:updated>
            <content:encoded><![CDATA[<p>In this part we will be exploring more towards how ROS and Arduino are interfaced together and what will the hardware required for achieving the differential robot movement.</p><h3><strong>Connection Diagram</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sMG2dsEEBUy1gqN2BNmOjw.jpeg" /></figure><ol><li>Raspberry Pi powered with SD Card having ubuntu image</li><li>Pi is connected to RPLIDAR A1 via USB (Serial)</li><li>Pi is connected to Sparkfun IMU via I2C</li><li>Arduino Mega 2560 is connected to Pi via USB (Serial)</li><li>Motor driver shield is connected to Arduino board. We are using dual motor driver here to support mecanum drives in future</li><li>Motor with encoders (4 nos) will be connected to motor driver shield</li><li>Final connection will be to power supply. The following are the power requirements: Pi (5v), Arduino Mega 2560 (5v), LIDAR (5v), IMU (3.3v) , Motor (12v), Encoder (5v)</li></ol><h3><strong>Hardware Required</strong></h3><ul><li>Arduino Mega 2560</li><li>Dual Motor driver shield for Mega 2560 with connectors for encoders (<a href="https://www.aliexpress.com/item/4001086592215.html?spm=a2g0s.9042311.0.0.27424c4dNQhLym">Buy from here</a></li><li>DC motors with encoders (4 Nos) <a href="https://www.pololu.com/product/1442">Buy from here</a></li><li>Chassis and differential wheels</li><li>Raspberry pi 4</li><li>SparkFun 9DoF IMU Breakout (<a href="https://www.sparkfun.com/products/15335">Buy from here</a>)</li><li>RPLIDAR A1 (<a href="https://www.slamtec.com/en/Lidar/A1">Buy from here</a>)</li></ul><p><strong>ROS packages used in this tutorial</strong></p><ol><li>rosserial_arduino (<a href="http://wiki.ros.org/rosserial_arduino">Library link</a>)</li></ol><h3><strong>Custom ROS messages used in the tutorial</strong></h3><p>(<a href="https://github.com/santoshbalaji/haruto-msgs.git">git link</a>)</p><p>Input message format accepted by arduino (PWM.msg)</p><pre>int32 front_left_pwm<br>int32 front_right_pwm<br>int32 back_left_pwm<br>int32 back_right_pwm<br>int32 left_state<br>int32 right_state</pre><p>Each pwm specified in the message (front_left_pwm, front_right_pwm …) is for controlling the motor speed. 4 values for 4 motor control with values ranging from (0–255). The left_state and right_state is for controlling the direction of motors on left and right side of the robot with values ranging from (1- forward, 2-reverse and 3-brake)</p><p>Feedback message format from arduino. Creating general file to add any new sensors to this list in future (Reply.msg)</p><pre>Tick tick</pre><p>Encoder message format on feedback (Tick.msg)</p><pre>int64 front_left_tick<br>int64 front_right_tick<br>int64 back_left_tick<br>int64 back_right_tick</pre><p>The values mentioned above denotes the encoder readings returned from each motors respectively. The values will be +ve if the motor rotates in forward direction and -ve if otherwise</p><p>Once the custom messages are created as ROS package, we have to convert them to libraries supported by arduino. You can use the following ROS command or can follow the instructions in the <a href="http://wiki.ros.org/rosserial_arduino/Tutorials/Adding%20Custom%20Messages">link</a></p><pre>rosrun rosserial_arduino make_library.py path_to_arduino_libraries your_message_package</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8lMWtIqMySbtnpVuiwauMQ.jpeg" /><figcaption>Image of Robot (Nicknamed Haruto)</figcaption></figure><h3><strong>Arduino codes</strong></h3><p>(<a href="https://github.com/santoshbalaji/haruto-arduino.git">git link</a>)</p><p><strong>Storage.h</strong></p><p>General header file to store all constant values and shared variable declaration</p><pre>#ifndef Storage_h<br>#define Storage_h</pre><pre>// declaring pins used for encoder and motor control</pre><pre>// Each encoder from motor provides two outputs. One for forward and // another for reverse direction (for four encoders)<br>#define ENCAF 2 <br>#define ENCAR A1  <br>#define ENCBF 3 <br>#define ENCBR 49 <br>#define ENCCF 18 <br>#define ENCCR 31 <br>#define ENCDF 19 <br>#define ENCDR 38</pre><pre>// Each motor requires three pins for control.One for controlling <br>// the speed. Another two for controlling their forward and reverse // direction control<br>#define PWMA 5<br>#define MAF A5<br>#define MAR A4<br>#define PWMB 9<br>#define MBF 43<br>#define MBR 42<br>#define PWMC 12<br>#define MCF 35<br>#define MCR 34<br>#define PWMD 8<br>#define MDF 37<br>#define MDR 36</pre><pre>#include &quot;Arduino.h&quot;<br>#include &lt;ros.h&gt;</pre><pre>extern ros::NodeHandle nh;<br>extern int front_left_pwm, front_right_pwm, back_left_pwm, back_right_pwm, left_state, right_state;</pre><pre>#endif</pre><p><strong>Task.h</strong></p><p>Header file for task module which receives operational instruction from ROS and performs motor control</p><pre>#ifndef Task_h<br>#define Task_h</pre><pre>#include &quot;storage.h&quot;<br>#include &lt;haruto_msgs/PWM.h&gt;</pre><pre>class Task<br>{<br>  public:<br>    Task();<br>    void execute_command();<br>    void activate_ros_spin();<br>};</pre><pre>#endif</pre><p><strong>Task.cpp</strong></p><p>Implementation for task module (Receive ROS instruction and motor control)</p><pre>#include &quot;task.h&quot;</pre><pre>int front_left_pwm, front_right_pwm, back_left_pwm, back_right_pwm, left_state, right_state;<br>ros::NodeHandle nh;<br>void pwm_command(const haruto_msgs::PWM&amp; data);<br>bool state=false;</pre><pre>// Subscribing for motor instructions<br>ros::Subscriber&lt;haruto_msgs::PWM&gt; pwm_sub(&quot;/diff_pwm&quot;, &amp;pwm_command);</pre><pre>Task::Task()<br>{<br>  pinMode(PWMA, OUTPUT);<br>  pinMode(MAF, OUTPUT);<br>  pinMode(MAR, OUTPUT);<br>  pinMode(PWMB, OUTPUT);<br>  pinMode(MBF, OUTPUT);<br>  pinMode(MBR, OUTPUT);<br>  pinMode(PWMC, OUTPUT);<br>  pinMode(MCF, OUTPUT);<br>  pinMode(MCR, OUTPUT);<br>  pinMode(PWMD, OUTPUT);<br>  pinMode(MDF, OUTPUT);<br>  pinMode(MDR, OUTPUT);</pre><pre>nh.initNode();  <br>  nh.subscribe(pwm_sub);<br>}</pre><pre>void Task::execute_command()<br>{<br>  /**<br>   *  Function called in loop to control the robot speed and <br>   *  direction based on the ROS instructions received<br>  */<br>  if(state)<br>  {<br>    // pwm (speed) values are set (0-255)<br>    analogWrite(PWMA, front_left_pwm);<br>    analogWrite(PWMB, front_right_pwm);<br>    analogWrite(PWMC, back_left_pwm);<br>    analogWrite(PWMD, back_right_pwm);</pre><pre>if(left_state == 1)<br>    {<br>      // left motor forward control enabled <br>      nh.loginfo(&quot;left wheels moving in forward direction&quot;);         <br>      digitalWrite(MAF, HIGH);<br>      digitalWrite(MAR, LOW);<br>      digitalWrite(MCF, HIGH);<br>      digitalWrite(MCR, LOW);<br>    }<br>    else if(left_state == 2)<br>    {<br>      // left motor reverse control enabled <br>      nh.loginfo(&quot;left wheels moving in backward direction&quot;);<br>      digitalWrite(MAF, LOW);<br>      digitalWrite(MAR, HIGH);<br>      digitalWrite(MCF, LOW);<br>      digitalWrite(MCR, HIGH);  <br>    }<br>    else<br>    {<br>      // left motor brake enabled (Both the directions are set high            <br>      // to avoid inertia during braking action)<br>      nh.loginfo(&quot;left wheels brake applied&quot;);<br>      digitalWrite(MAF, HIGH);<br>      digitalWrite(MAR, HIGH);<br>      digitalWrite(MCF, HIGH);<br>      digitalWrite(MCR, HIGH);    <br>    }<br>  <br>    if(right_state == 1)<br>    {<br>      // right motor forward control enabled      <br>      nh.loginfo(&quot;right wheels moving in forward direction&quot;);      <br>      digitalWrite(MBF, HIGH);<br>      digitalWrite(MBR, LOW);<br>      digitalWrite(MDF, HIGH);<br>      digitalWrite(MDR, LOW);<br>    }<br>    else if(right_state == 2)<br>    {<br>      // right motor reverse control enabled      <br>      nh.loginfo(&quot;right wheels moving in backward direction&quot;);<br>      digitalWrite(MBF, LOW);<br>      digitalWrite(MBR, HIGH);<br>      digitalWrite(MDF, LOW);<br>      digitalWrite(MDR, HIGH);  <br>    }<br>    else<br>    {</pre><pre>      // right motor brake enabled (Both the directions are set high     <br>      // to avoid inertia during braking action)      <br>      nh.loginfo(&quot;right wheels brake applied&quot;);<br>      digitalWrite(MBF, HIGH);<br>      digitalWrite(MBR, HIGH);<br>      digitalWrite(MDF, HIGH);<br>      digitalWrite(MDR, HIGH);    <br>    }<br>    state = false;<br>  }<br>}</pre><pre>void Task::activate_ros_spin()<br>{<br>  /**<br>   * Function called in loop to run the ROS loop  <br>  */<br>  nh.spinOnce();<br>  // delay added here to maintain synchronization when sending or     <br>  // receiving ROS messages <br>  delay(1);<br>}</pre><pre>void pwm_command(const haruto_msgs::PWM&amp; data)<br>{<br>  /**<br>   * Callback function to receive speed and motor control message   <br>   * from ROS<br>  */<br>  front_left_pwm = data.front_left_pwm;<br>  front_right_pwm = data.front_right_pwm;<br>  back_left_pwm = data.back_left_pwm;<br>  back_right_pwm = data.back_right_pwm;<br>  left_state = data.left_state;<br>  right_state = data.right_state;<br>  state = true;<br>}</pre><p><strong>Feedback.h</strong></p><p>Header file for feedback module which involves in sending sensor feedback over ROS</p><pre>#ifndef Feedback_h<br>#define Feedback_h</pre><pre>#include &lt;Encoder.h&gt;<br>#include &quot;storage.h&quot;<br>#include &lt;haruto_msgs/Tick.h&gt;<br>#include &lt;haruto_msgs/IMU.h&gt;<br>#include &lt;haruto_msgs/Reply.h&gt;</pre><pre>class Feedback<br>{<br>  public:<br>    Feedback();<br>    void broadcast_feedback();<br>};</pre><pre>#endif</pre><p><strong>Feedback.cpp</strong></p><p>Implementation for feedback module</p><pre>#include &quot;feedback.h&quot;</pre><pre>Encoder front_left_encoder(ENCAF, ENCAR), front_right_encoder(ENCBF, ENCBR), back_left_encoder(ENCCF, ENCCR), back_right_encoder(ENCDF, ENCDR);<br>haruto_msgs::Tick tick;<br>haruto_msgs::Reply reply;<br>// Registering publisher to send sensor feedback<br>ros::Publisher feedback_publisher(&quot;diff_feedback&quot;, &amp;reply);<br>long elapsed_time_for_tick = millis();</pre><pre>Feedback::Feedback()<br>{<br>  nh.advertise(feedback_publisher);<br>}</pre><pre>void Feedback::broadcast_feedback()<br>{<br>  /**<br>   * Function to send send sensor feedback over ROS every 100 ms <br>  */<br>  if(millis() - elapsed_time_for_tick  &gt;= 100)<br>  {<br>    // Encoder values set over here for feedback      <br>    tick.front_left_tick = front_left_encoder.read();<br>    tick.front_right_tick = front_right_encoder.read();<br>    tick.back_left_tick = back_left_encoder.read();<br>    tick.back_right_tick = back_right_encoder.read();<br>    <br>    reply.tick = tick;<br>    feedback_publisher.publish(&amp;reply);<br>    <br>    elapsed_time_for_tick = millis();<br>  }<br>}</pre><p><strong>haruto-arduino.ino</strong></p><p>Starting point for Arduino code</p><pre>#include &quot;task.h&quot;<br>#include &quot;feedback.h&quot;</pre><pre>extern Task task;<br>extern Feedback feedback;</pre><pre>void setup()<br>{<br>  // Declare classes<br>  Task task;<br>  Feedback feedback;<br>  Serial.begin(115200);<br>}</pre><pre>void loop()<br>{<br>  // Start looking for motor instructions<br>  task.execute_command();<br>  // Send sensor feedback<br>  feedback.broadcast_feedback();<br>  task.activate_ros_spin(); <br>}</pre><h3><strong>Conclusion</strong></h3><p>This is the first part of the tutorial in which arduino robot control via ROS is completed. The following are the hiccups I had during the development phase.</p><ul><li>Don’t trust arduino to perform lot of ROS operations. Since you can assume it is like single threaded application every incoming and outgoing ROS message introduces delay and it results in losing synchronization with ROS server over serial.</li><li>Arduino does not support Float64 ROS messages assuming the time at which I am writing this tutorial</li><li>Have a better arduino board with more memory. Arduino Mega is preferable</li><li>Buy components from famous branded companies. I have bought motor with encoder for cheaper version first. It resulted in lose of accuracy for encoder readings.</li></ul><p><a href="https://medium.com/@santoshbalaji/autonomous-mobile-robot-with-ros2-part-2-urdf-simulation-8ccbc52b61cb"><strong>Please click on the link for next part of the tutorial series</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48288e142239" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>