Control any Robotic Arm with ROS
Make any Robot Arm work with ROS and MoveIt!
The Robot Operating System
The Robot Operating System (ROS) has been heralded as one of the greatest advancements in Robotics. Historically, robotic innovation has had a fairly high barrier to entry. If you wanted to develop a robot, you had to build a complete system: a physical device, of course, but also the control systems, interface, and inspection tools required to get the robot up and running as a test platform.
Enter ROS: the ultimate robotics middleware. You now have a complete ecosystem to get your robot up and running with powerful tools at your disposal.
In this tutorial, we would be using MoveIt!, a powerful motion planning framework which has many features to control a robotic arm.
Find out more about MoveIt, here.
Robot Arm — CAD files and URDF
This tutorial can make use of any robot arm design files available on the internet in CAD neutral format (such as STL). Alternatively, one can design it from scratch using any of the popular CAD software packages such as SolidWorks.
ROS and MoveIt however, require our files to be in URDF. The Unified Robotic Description Format (URDF) is an XML file format used in ROS to describe all elements of a robot. It lists all the kinematic properties of the links and joints in a chain from base to tip. ROS also accepts .xacro files which are very similar to urdf and are easier to write.
Fortunately, due to a few talented ROS developers, there exists a convenient plugin in Solidworks to export our assembly in URDF format.
General Workflow
The workflow for creating a MoveIt compatible ROS package from the CAD model is depicted below
Want to read this story later? Save it in Journal.
For this tutorial, you may either download a SolidWorks assembly off the internet, or download any URDF directly off sites like GitHub. One such URDF can be found here.
Generate URDF — SolidWorks
Assuming you have your model completely set up as a SolidWorks assembly, we now use the SolidWorks to URDF Exporter.
Set the position of your joints as you would like them exported. This is important as you would define your joints with respect to this pose.
Click “File>Export to URDF”
A URDF file is basically a link chain from base>tip, defined in XML and are connected by joints. So we build this tree manually by configuring each link in that order. This is a one time setup to save the configuration.
Each URDF has only one base link. The joint configurations are disabled for this one link because there doesn’t exist a joint to a higher level link. You only need to name the link, select its components and create its child links.
Each subsequent link has a name, a joint name which connects it to its parent link and other properties. We find that, if the joints and axes are properly defined in the model, then choosing the Reference Coordinate System and Axes can be skipped as we can automatically generate those fields. Select the joint type based on the joint in the robot. We keep adding child links until we complete the chain. You can select any link you’ve already added to change its properties.
Building URDF
Once the link is configured, select Preview and Export to bring up the build options to customise the properties of each joint. Here, we can set the properties of the joint based on our actuator such as the joint limits, effort and the velocity of the joint.
Clicking next will take you to the link properties. If required, one can give additional properties such as change the origins of different sections, change the moment of inertia tensor, mass or can change visual attributes like colour, texture and mesh detail.
Now you have the option of exporting the URDF package with or without meshes. Meshes are basically visual elements that are viewable in ROS.
The built package will contain directories for meshes, textures and robots. It will also contain a ROS package.xml (manifest) file so you can use this as a ROS package by just copying it to your ROS system. The path locations in the URDF are relative to the package itself. Use proper ROS package names to avoid errors.
Installing ROS and MoveIt
This step would require both ROS and MoveIt to be installed. This tutorial uses ROS Melodic, which runs on Ubuntu 18.04.
From here-on, the tutorial assumes you have Ubuntu 18.04 installed.
Installing ROS has been very well documented — here. The installation is easy enough but it’s imperative that one does not miss any steps.
Steps for installing MoveIt can be found — here. This downloads the stable LTS version. The latest branch, which is being actively developed can be installed here.
Importing the robot model in ROS
Importing the Robot Model into ROS would involve creating a Robot Configuration package which is used by MoveIt. There’s a tutorial in the MoveIt docs for creating a package but it’s slightly technical.
We use the MoveIt Setup Assistant to create a ROS package. It creates a configuration package with all the required files.
Move the urdf folder into the ~/ws_moveit/src folder of your MoveIt workspace. Fire up a terminal:
vinaylanka@vinaylanka:~$ cd ws_moveit
vinaylanka@vinaylanka:~/ws_moveit$ catkin build
...
vinaylanka@vinaylanka:~/ws_moveit$ source devel/setup.bash
While running catkin build, a few machines may hang due to insufficient memory by all the tasks running on seperate threads. To avoid this, set a safe limit as a flag to the build command — ‘ -j4’. Building and sourcing the workspace would setup all the files required for creating a configuration package. To start the MoveIt Setup Assistant:
roslaunch moveit_setup_assistant setup_assistant.launch
Create New MoveIt Configuration Package > Browse > Navigate to the urdf file in the folder you shifted to the workspace.
Step 1. Generate Self Collision Matrix — This basically checks all the pairs of links never in collision to skip while searching for an IK solution. Higher densities require more computation time while lower densities have a higher possibility of disabling pairs that should not be disabled.
Click on Self-Collisions in the pane > Generate Collision Matrix button.
Step 2. Add Virtual Joints — Virtual joints are used primarily to attach the robot to the world. Some urdf files usually have a fixed joint with the world frame and base link. If your urdf does not have a joint connecting it to the world frame(SolidWorks generated models generally do not), create a virtual joint.
Click on Virtual Joints in the pane > Add Virtual Joint > Select the child link as your base link and name the parent frame as “world” > Save.
Step 4. Add Planning Groups — Planning groups are used for semantically describing different parts of your robot, such as defining what an arm is, or an end effector. They help the kinematics planner only focus on a part of the robot to plan and execute robot motion.
Click on the Planning Groups in the pane > Add Group. Name the group and leave the other values as is. Click on Add Joints and add all the joints(Including the virtual joint) to the right side and Save.
If you have to add an end effector group, do the same but instead of Add Joints, click on Add Links to add the end-effector links.
Step 5: Add Robot Poses — This pane allows us to add custom poses for our robot. A pose is a named set of joint values.
Click on Robot Poses Pane > Add Pose. Name a pose and use the sliders to define a pose for the robot.
Now is a good time to check whether all the joints are actuated properly in the urdf and test the joint limits.
Step 6. Define End Effectors — This pane allows us to define the end-effector group made earlier as an end effector in MoveIt configuration.
Click on End effectors pane > Add end effector. Select the group defined earlier and the parent link. (The link it is connected to in the robot).
Step 7. Add Author Information and Generate Configuration Package —
Add your name and email id in the author information pane. This is useful for publishing purposes.
The one last step would be to generate the configuration files. Click on Configuration Files pane > Choose a location. I’d suggest placing the package in the same ~/ws_moveit/src directory. Create a new folder for the package and select that folder. The final path should be:
~/ws_moveit/src/<your_package_name>
Click on the Generate Package button. The Setup Assistant will now generate and write a set of launch and config files into the directory of your choosing. All the generated files will appear in the Generated Files/Folders tab and you can click on each of them for a description of what they contain.
We’ve reached the end of the tutorial. A short note on what the other panes in the setup assistant mean can be found below.
Passive Joints / 3D Perception / Gazebo Sim / ROS Control
These panes don’t need to be configured for this tutorial and can be skipped. However they are explained briefly below.
Passive Joints define the joints that do not have any actuation(A motor connected), so that there’s no need to publish joint values to such a joint. This tells the planners that they cannot (kinematically) plan for these joints because they can’t be directly controlled.
3D Perception is used to configure 3D point cloud sensors to enable the perception pipeline. This allows MoveIt to take 3D sensor readings into account using octomap.
Gazebo Simulation tab can be used to help you simulate your robot with Gazebo by generating a new Gazebo compatible urdf if needed.
ROS Control allows us to define and control custom controllers with a set of packages. If your robot has a custom controller use this pane to setup the simuated controllers to actuate the joints of your robot.
Wrapping things up
For using the package we need to build the workspace again as a new package was added to it. Fire up a terminal:
vinaylanka@vinaylanka:~$ cd ws_moveit
vinaylanka@vinaylanka:~/ws_moveit$ catkin build
...
vinaylanka@vinaylanka:~/ws_moveit$ source devel/setup.bash
To verify if everything worked, run:
vinaylanka@vinaylanka:~$ roslaunch <your_robot_pkg> demo.launch
If everything works, Congratulations!! — You are now done generating the configuration files you need for MoveIt.
To start motion planning with MoveIt, start off with this tutorial.
📝 Save this story in Journal.
👩💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.