NexDroid and ROS Integration

Tutorial on integrating the NexDroid system with ROS

Video

We have created a video tutorial on how to connect the NexDroid system to ROS.

NexDroid and ROS Integration - Connection and Usage

Ⅰ. ROS Environment Initialization

·Installation of ROS

This section includes the complete installation steps and solutions to common errors.

1. Set up sources.list

Set up your computer to install software from packages.ros.org.

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

If the download speed is slow, you can configure the Tsinghua mirror as follows:

sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

PS: If the download fails, you can try configuring the Alibaba mirror or Tsinghua mirror for Ubuntu. Below is a configuration scheme for the Alibaba mirror.

  • Backup the source list

    The default sources configured for Ubuntu are not from domestic servers, resulting in slow download and update speeds. First, you need to back up the source list file sources.list

    sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
  • Open the sources.list file for editing

    sudo gedit /etc/apt/sources.list

Edit the /etc/apt/sources.list file and add the Aliyun mirror source at the beginning of the file:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  • Refresh the list

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install build-essential

2. Set up the key

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

3. Install

sudo apt update
sudo apt install ros-melodic-desktop-full

4. Initialize rosdep

If initialization fails, follow step 6 for modification. Complete the initialization and then proceed to configure the environment variables.

sudo rosdep init
rosdep update

5. Set up environment variables

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

6. rosdeq error

Due to server issues, you may encounter the following problem and need to modify the configuration file before continuing

sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.
rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
ERROR: error loading sources list:
('The read operation timed out')
  • Open the file containing the resource download function:
sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py

Add

url="https://ghproxy.com/"+url
1
  • Modify the DEFAULT_INDEX_URL in the /usr/lib/python2.7/dist-packages/rosdistro/__init__.py file

    sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/__init__.py
    DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
    2
  • Modify the addresses in the remaining (4) files, and add https://ghproxy.com/ before the address https://raw.githubusercontent.com/

    $ sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
    //Modify line 36
    $ sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py
    //Modify line 72
    $ sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/rep3.py
    //Modify line 39
    $ sudo gedit /usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py
    //Modify lines 68 and 119
  • Resolve Hit's fifth address error

    sudo gedit /usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
    //Add the following code at line 204 (the first line of the function block)
    gbpdistro_url = "https://ghproxy.com/" + gbpdistro_url
    //Note: The double quotation marks in the proxy address of the original URL are in Chinese. Directly copying and pasting may result in character recognition errors
  • If the error persists, try modifying the

    sudo gedit /etc/resolv.conf

    Comment out the existing nameserver line and add the following two lines:

    nameserver 8.8.8.8 #google domain name server
    nameserver 8.8.4.4 #google domain name server

    Save and exit. Execute

    sudo  apt-get update

Then execute

sudo rosdep init
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize

Solution:

Execute the following command to delete the existing initialization file:

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

Run the following command again

sudo rosdep init

·Installation of ROS function package

sudo apt-get install ros-melodic-moveit
sudo apt-get install ros-melodic-joint-state-publisher
sudo apt-get install ros-melodic-robot-state-publisher
sudo apt install ros-melodic-gazebo-ros-pkgs
sudo apt-get install ros-melodic-gazebo-ros-control
sudo apt-get install  ros-melodic-joint-trajectory-controller

·Creation of ROS workspace

mkdir -p ~/inexbot/src
cd ~/inexbot/src
catkin_init_workspace
cd ../
catkin_make

Modify the ~/.bashrc file:

gedit ~/.bashrc

Add the following line at the end of the file:

source ~/inexbot/devel/setup.bash

Copy all the inexbot function packages to the inexbot/src directory

II. Configuring Moveit and the Robot

​ Before establishing the connection, it is necessary to adjust the rotation directions, joint angle limits, and maximum joint rotation velocity and acceleration for each axis between ROS and the robot to ensure consistency.

​ The robot can be configured through the settings interface on the teach pendant.

​In ROS, you can modify the parameters under the axis and limit tags for each joint angle in the xacro file to achieve consistency in the rotation directions and limits between the model and the robot. Modify the max_velocity and max_acceleration in the qj_config/config/joint_limits file to change the maximum joint rotation velocity and acceleration in the ROS model.

​ If the rotation directions, joint angle limits, and maximum joint rotation velocity and acceleration are not consistent, the teach pendant may report errors such as angle limit exceeded and servo alarm during operation

......
<joint
name="robot_joint2"		<!--Joint name-->
type="revolute">
<origin
  xyz="0 0.18 -0.0525"
  rpy="0 0 0" />
<parent
  link="robot_Link1" />
<child
  link="robot_Link2" />
<axis
  xyz="1 0 0" />    <!--Take 1 as the positive direction and -1 as the negative direction-->
<limit
  lower="-3.14"
  upper="3.14"
  effort="100"
  velocity="1" />  <!--lower is the lower limit of joint angle, upper is the upper limit. ROS uses radians, and the teach pendant uses degrees-->
<dynamics damping="0" friction="1"/>
  </joint>
......
joint_limits:
   robot_joint1:
has_velocity_limits: true
max_velocity: 1
has_acceleration_limits: ture
max_acceleration: 1
<!--max_velocity: Maximum velocity of joint rotation, max_acceleration: Maximum acceleration of joint rotation, expressed in radians-->
......

III. ROS Communication with Controller

Using a 6-axis robot as an example, let's explain how ROS can connect with the NRC robot controller

1. Start the controller

2. Launch the combined simulation environment of Rviz and Gazebo

roslaunch inexbot_qj robot_bringup.launch

3. Add the robot model

Click on "Add" in the bottom left corner of the "Displays" interface, then select "Robot Model" to add the robot model

3
4

4. Start the ros node to connect with the controller

rosrun inexbot_service rostopic_joint5

Ⅳ. Controlling the Robot through MoveIt

1. Set Goal state control

5

​ Click on "Plan" to generate a planned trajectory. The bottom will display the planned time (Time).

6

​ Click on "Execute" to execute the planned trajectory. Alternatively, you can click on "Plan&Execute" to plan and execute immediately

2. Control through dragging the planner

​ Drag the green ball on the front end of the planner. When the cursor is placed on the ball, a 3D coordinate will appear below. Drag it to the desired point, then click on "Plan" to generate a planned trajectory. Click on "Execute" to execute the trajectory. Alternatively, you can click on "Plan&Execute" to plan and execute immediately.

7

Ⅴ. Controlling the Robot through C++ Programming

1. Create a ROS package to store the program files

cd ~/inexbot/src
catkin_create_pkg inexbot_code std_msgs rospy roscpp
cd ../
catkin_make

2. Joint space planning

Create moveit_joint_demo.c

Place the file in the~/inexbot/src/inexbot_code/src directory

//moveit_joint_demo.c
#include <ros/ros.h>
#include <moveit/move_group_interface/move_group_interface.h>

int main(int argc, char **argv)
{
//ros initialization
ros::init(argc, argv, "moveit_joint_demo");
ros::AsyncSpinner spinner(1);
spinner.start();

//manipulator is the planning group set up through moveit
moveit::planning_interface::MoveGroupInterface arm("manipulator");

//allowable error
arm.setGoalJointTolerance(0.001);
//maximum acceleration
arm.setMaxAccelerationScalingFactor(0.2);
//maximum velocity
arm.setMaxVelocityScalingFactor(0.2);

// Set the goal_state to control the robot arm to move back to the home position
// 'home' is a pre-defined position in moveit
arm.setNamedTarget("home");
//execute the motion
arm.move();
sleep(1);
//set the angles of the six axes in joint space
double targetPose[6] = {0.391410, -0.676384, -0.376217, 0.0, 1.052834, 0.454125};
std::vector<double> joint_group_positions(6);
joint_group_positions[0] = targetPose[0];
joint_group_positions[1] = targetPose[1];
joint_group_positions[2] = targetPose[2];
joint_group_positions[3] = targetPose[3];
joint_group_positions[4] = targetPose[4];
joint_group_positions[5] = targetPose[5];

arm.setJointValueTarget(joint_group_positions);
arm.move();
sleep(1);

// Control the robot arm to move back to the home position
arm.setNamedTarget("home");
arm.move();
sleep(1);

ros::shutdown();

return 0;
}

Modify CMakeLists.txt file

Add the following lines above the install tag:

add_executable(moveit_joint_demo src/moveit_joint_demo.cpp)
target_link_libraries(moveit_joint_demo ${catkin_LIBRARIES})
#############
## Install ##
#############

Compile the code

cd ~/inexbot
catkin_make

Run

rosrun inexbot_code moveit_joint_demo

文档反馈

NexDroid and ROS Integration - iNexBot