[Linux] 6-Axis Robot Construction Guide Using ROS2 Part 2

2 minute read

It’s been two months since Part 1..
I kept putting off this post, and two months have already passed.

In Part 1, we finished assembling the robot frame.
Actually, I already downloaded the completed package source code in Part 1 to position the motors.
I will proceed by explaining the package source code.

Bill of Materials (BOM)

The materials are as follows:

- Odroid C4       ... (x1)
- MG996R          ... (x6)
- PCA9685         ... (x1)
- Robot arm       ... (x1)

ROS2

Finally, let’s use the assembled robot arm with ROS2.

ROS2 Package Structure

Since the PCA9685 package is provided in Python, the ROS package was also created using Python.
Detailed explanations of the source code will be provided in future posts as related topics arise.

Check the code downloaded in Part 1.

$ cd ros2_axis6
$ tree -L 2
.
├── LICENSE-APACHE
├── LICENSE-MIT
├── README.md
├── axis6
│   ├── __init__.py
│   ├── commander.py
│   ├── operator.py
│   └── state_publisher.py
├── gif
│   └── axis6-test.gif
├── how2flow_interfaces
├── images
│   ├── axis6_circuit.png
│   └── rviz.png
├── launch
│   └── display.prototype.py
├── libgpiod.py
├── meshes
│   ├── axis1.dae
│   ├── axis2.dae
│   ├── axis3.dae
│   ├── axis4.dae
│   ├── axis5.dae
│   ├── base_link.dae
│   ├── box1.dae
│   ├── box2.dae
│   ├── box3.dae
│   ├── box4.dae
│   ├── cylinder1.dae
│   ├── end_effector.dae
│   ├── frame1-1.dae
│   └── frame2-1.dae
├── package.xml
├── preinstall.sh
├── requirements.txt
├── resource
│   └── axis6
├── rviz
│   ├── ros2_axis6-test.rviz
│   └── ros2_axis6.rviz
├── setup.cfg
├── setup.py
├── test
│   ├── test_copyright.py
│   ├── test_flake8.py
│   └── test_pep257.py
├── udev
│   └── rules.d
└── urdf
    └── prototype.urdf

In a ROS2 package, the package.xml file specifies the basic configuration.
Check the package.xml file.

$ vi package.xml
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>axis6</name>
  <version>0.0.0</version>
  <description>Control 6-axis robot with pca9685 (motor: MG996R)</description>
  <maintainer email="steve@how2flow.net">how2flow</maintainer>
  <license>Apache 2.0, The MIT</license>

  <depend>rclpy</depend>
  <depend>sensor_msgs</depend>
  <depend>how2flow_interfaces</depend>

  <test_depend>ament_copyright</test_depend>
  <test_depend>ament_flake8</test_depend>
  <test_depend>ament_pep257</test_depend>
  <test_depend>python3-pytest</test_depend>

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

The build uses the rclpy method, and two data interfaces are used: sensor_msgs and how2flow_interfaces.

sensor_msgs is a standard interface provided by ROS2.
It is typically built and available by default when you install ROS2.

how2flow_interfaces is a custom interface I created.
It must be downloaded separately and built alongside the ROS package.

Check the setup.py file.

$ vi setup.py
  1 from setuptools import setup
  2 from glob import glob
  3
  4 package_name = 'axis6'
  5
  6 setup(
  7     name=package_name,
  8     version='0.0.0',
  9     packages=[package_name],
 10     data_files=[
 11         ('share/ament_index/resource_index/packages',
 12             ['resource/' + package_name]),
 13         ('share/' + package_name, ['package.xml']),
 14         ('share/' + package_name + '/launch/', glob('launch/*.py')),
 15         ('share/' + package_name + '/meshes/', glob('meshes/*.dae')),
 16         ('share/' + package_name + '/rviz/', glob('rviz/*.rviz')),
 17         ('share/' + package_name + '/urdf/', glob('urdf/*.urdf')),
 18     ],
 19     install_requires=['setuptools'],
 20     zip_safe=True,
 21     maintainer='how2flow',
 22     maintainer_email='steve@how2flow.net',
 23     description='Control 6-axis robot with pca9685 (motor: MG996R)',
 24     license='Apache 2.0, The MIT',
 25     tests_require=['pytest'],
 26     entry_points={
 27         'console_scripts': [
 28             'commander = axis6.commander:main',
 29             'operator = axis6.operator:main',
 30             'state_publisher = axis6.state_publisher:main',
 31         ],
 32     },
 33 )


The data_files list on line 10 contains the files that are the actual targets for installation.
In Linux, “install” generally means
copying and pasting the final outputs to their appropriate paths.

The console_scripts section on line 27 is where ROS2 nodes are defined.
This is where you specify information for the nodes to be included during the build.

Source code review will continue in Part 3…

Leave a comment