Chapter I ROS Foundation
1.ROS installation
http://wiki.ros.org/kinetic/Installtion/Source
http://wiki.ros.org/kinetic/Installtion/Ubuntu
2. install rosinstall
$ sudo apt-get install python-rosinstall
3. create a catkin workspace:
~$ mkdir -p ~/catkin_ws/src ~$ cd ~/catkin_ws/src ~/catkin_ws/src$ catkin_init_workspace ~/catkin_ws/src$ cd .. ~/catkin_ws$ catkin_make
4. load the source file setup bash
~/catkin_ws$ source ~/catkin_ws/devel/setup.bash ~/catkin_ws$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
View workspace: ~/catkin_ws$ echo $ROS_PACKAGE_PATH
5.ROS function package
http://wiki.ros.org/Packages
Command:
-
rospack is used to obtain the information of a function package
$ rospack help | less
-
roscd switch ROS directory
$ roscd turtlesim
-
rosls lists the directories and files under a function package directory
$ rosls turtlesim
-
rospack find returns the path of the function pack with the specified name
$ rospack find turtlesim
6.ros node, topic and message
-
rosnode list lists the running nodes
-
rostopic list lists topics related to running nodes
Using help rosnode -h
rosnode list -h
7.ROS robot simulation program
- rosrun finds and starts the required node in the function package
- rosmsg displays information about related messages
- rosservice displays the running time of nodes and transfers data between nodes in request / response mode
- rosparam gets or sets node parameter values
Start ROS Node Manager | roscore |
---|---|
Start node | rosrun turtlesim turtlesim_node |
List active nodes | rosnode list |
View the publishing topics, subscription services and service related content of the /turnlesim node | rosnode info /turtlesim |
View the topic of /turnlesim node | rostopic list |
View the topic type of the topic | rostopic type /turtle1/color_sensor |
View message types | rosmsg list |
View the specific contents of ROS message types | rosmsg show turtlesim/Color |
View the value of turtle background color | rostopic echo /turtle1/color_sensor |
8. control tortoise movement
- Start the node manager and start turnlesim_ node
$ roscore $ rosrun turtlesim turtlesim_node
-
turtlesim_node subscription /turtle 1/cmd_ Vel topics can be accessed through /turnle1/cmd_ Vel sends messages to control turtle movement
-
Determine the message type of the topic
$ rostopic type /turtle1/cmd_vel
The message type is twist from geometry_msgs Feature Pack geometry_msgs/Twist
-
Control the tortoise to make circular motion
$ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0,0.0,0.0]' '[0.0 0.0 1.8]'
Control the tortoise to make circular motion at a linear speed of 2m/s and an angular speed of 1.8 radians /s
Numerical parameter reference http://wiki.ros.org/ROS/YAMLCommandLine
-
Keyboard control_ teleop_ key
-
Parameter server of turnlesim
Rosparam listlist the parameter list of the /turnlesim node
rosparam get / get the values of all parameters on the entire parameter server
-
Change the color of turtle background to red rosparam set background_b 0
$ rosparam set background_g 0 $ rosparam set background_r 0 $ rosservice call /clear
- ROS service controlling tortoise movement
Get the turtle's location information through the /turtle 1/pose topic
$ rostopic type /turtle1/pose $ rosmsg show turtlesim/Pose
Obtain the tortoise's position coordinates, azimuth angle and speed parameters
$ rostopic echo /turtle1/pose
Using rossevice remote control port to move tortoise
$ rosservice call /turtle1/teleport_absolute 1 1 0
More commands http://wiki.ros.org/ROS/CommandLineTools
Chapter 2 build a simulated two wheeled ROS robot
rviz is an acronym for ROS visualization, viewing simulated robot models, sensor logs from robot sensors, and replaying recorded sensor information
1. install rviz
http://wiki.ros.org/rviz/Tro-ubleshooting
Questions page of ROS Forum http://answers.ros.org/questions/
- Check for installation
~$ roscore ~$ rosrun rviz rviz
Install $sudo apt get install ROS kinetic rviz
User guide http://wiki.ros.org/rviz/UserGuide
2. generate and build ROS function package
Creating a catkin workspace in Chapter 1:
~$ mkdir -p ~/catkin_ws/src ~$ cd ~/catkin_ws/src ~/catkin_ws/src$ catkin_init_workspace ~/catkin_ws/src$ cd .. ~/catkin_ws$ catkin_make ~/catkin_ws$ source ~/catkin_ws/devel/setup.bash ~/catkin_ws$ echo "source ~/catkin_ws/src:opt/ros/noetic/share" ~/catkin_ws$ echo $ROS_PACKAGE_PATH /home/zrf/catkin_ws/src:/opt/ros/noetic/share
Switch to the catkin workspace | ~/catkin_ws$ cd src/ |
---|---|
Generate ROS function package ros_robotics | ~/catkin_ws/src$ catkin_create_pkg ros_robotics |
~/catkin_ws/src$ cd ... | |
~/catkin_ws$ catkin_make |
Example catkin_ create_ pkg <package_ name> [depend1] [depeng2]
3. build robot URDF
URDF is a specially defined XML format file, which is specially used to describe the abstract model of the robot build level. Xacro is an XML macro command language, which can help users reduce duplicate information in the file.
In ROS_ Generate /urdf directory under robotics function package
~/catkin_ws$ cd src/ ~/catkin_ws/src$ cd ros_robotics/ ~/catkin_ws/src/ros_robotics$ mkdir urdf ~/catkin_ws/src/ros_robotics$ cd urdf/
-
Describing the robot model, two basic URDF components define a tree structure.
The link component describes the physical properties of the rigid body (dimension, initial position, color, etc.)
The joint component describes the kinematics and dynamic properties of the connection (connected connecting rod, joint type, axis of rotation, resultant force of friction and damping, etc.)
~/catkin_ws/src/ros_robotics/urdf/dd_robotics.urdf:
<?xml version="1.0"?> <robot name ="dd_robot"> <!-- Base Link --> <link name ="base_link"> <visual> <origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/> <geometry> <box size="0.5 0.5 0.25"/> </geometry> </visual> </link> </robot>
It contains a link component whose visual shape is a rectangular box with length, width and height of 0.5m, 0.5m and 0.25m. The center of the box is located at the initial origin (0, 0, 0), and there is no rotation in the three axes of pitch, pitch and yaw. The connecting rod assembly is named base_link.
- Roslaunch: a startup tool provided by ROS. Simplify the startup of multiple ROS nodes and the parameter setting of the ROS parameter server
~/catkin_ws/src/ros_robotics/launch/ddrobot_rviz.launch:
<?xml version='1.0'?> <launch> <!-- values passed by command line input --> <arg name="model" /> <arg name="gui" default="False"/> <!-- set these parameters on Parameters Server --> <param name="robot_description" textfile="$(find ros_robotics)/urdf/$(arg model)" /> <param name="use_gui" value="$(arg gui)" /> <!-- Start 3 nodes --> <node name="joint_state_publisher_gui" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui" /> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /> <node name="rviz" pkg="rviz" type="rviz" args="-d $(find ros_robotics)/urdf.rviz" required="true" /> <!-- (required = "true") if rviz dies, entire roslaunch will be killed --> </launch>
View the robot model in Rviz:
(1) load the model set in the command line to the parameter server
(2) start the node that has published the JointState and transformation
(3) start using urdf Rviz file configured rviz
$ roslaunch ros_robotics ddrobot_rviz.launch model:=dd_robot.urdf
Example roslaunch <package_ name> <file. launch>
-
Robot Description: robot_description is the name of the ROS parameter stored in the URDF file, which is stored in the parameter server. The description of the connecting rod assembly and the joint assembly and the connection mode of the two are also stored in the robot description.
-
Add wheels, add casters, add colors, add collision attributes, add physical attributes.
*~/catkin_ws/src/ros_robotics/urdf**/dd_robotics6.urdf:*
<?xml version='1.0'?> <robot name="dd_robot"> <!-- Base Link --> <link name="base_link"> <visual> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <box size="0.5 0.5 0.25"/> </geometry> <material name="blue"> <color rgba="0 0.5 1 1"/> </material> </visual> <!-- Base collision, mass and inertia --> <collision> <origin xyz="0 0 0" rpy="0 0 0" /> <geometry> <box size="0.5 0.5 0.25"/> </geometry> </collision> <inertial> <mass value="5"/> <inertia ixx="0.13" ixy="0.0" ixz="0.0" iyy="0.21" iyz="0.0" izz="0.13"/> </inertial> <!-- Caster --> <visual name="caster"> <origin xyz="0.2 0 -0.125" rpy="0 0 0" /> <geometry> <sphere radius="0.05" /> </geometry> </visual> <!-- Caster collision, mass and inertia --> <collision> <origin xyz="0.2 0 -0.125" rpy="0 0 0" /> <geometry> <sphere radius="0.05" /> </geometry> </collision> <inertial> <mass value="0.5"/> <inertia ixx="0.0001" ixy="0.0" ixz="0.0" iyy="0.0001" iyz="0.0" izz="0.0001"/> </inertial> </link> <!-- Right Wheel --> <link name="right_wheel"> <visual> <origin xyz="0 0 0" rpy="1.570795 0 0" /> <geometry> <cylinder length="0.1" radius="0.2" /> </geometry> <material name="darkgray"> <color rgba=".2 .2 .2 1"/> </material> </visual> <!-- Right Wheel collision, mass and inertia --> <collision> <origin xyz="0 0 0" rpy="1.570795 0 0" /> <geometry> <cylinder length="0.1" radius="0.2" /> </geometry> </collision> <inertial> <mass value="0.5"/> <inertia ixx="0.01" ixy="0.0" ixz="0.0" iyy="0.005" iyz="0.0" izz="0.005"/> </inertial> </link> <!-- Right Wheel joint --> <joint name="joint_right_wheel" type="continuous"> <parent link="base_link"/> <child link="right_wheel"/> <origin xyz="0 -0.30 0" rpy="0 0 0" /> <axis xyz="0 1 0" /> </joint> <!-- Left Wheel --> <link name="left_wheel"> <visual> <origin xyz="0 0 0" rpy="1.570795 0 0" /> <geometry> <cylinder length="0.1" radius="0.2" /> </geometry> <material name="darkgray"> <color rgba=".2 .2 .2 1"/> </material> </visual> <!-- Left Wheel collision, mass and inertia --> <collision> <origin xyz="0 0 0" rpy="1.570795 0 0" /> <geometry> <cylinder length="0.1" radius="0.2" /> </geometry> </collision> <inertial> <mass value="0.5"/> <inertia ixx="0.01" ixy="0.0" ixz="0.0" iyy="0.005" iyz="0.0" izz="0.005"/> </inertial> </link> <!-- Left Wheel joint --> <joint name="joint_left_wheel" type="continuous"> <parent link="base_link"/> <child link="left_wheel"/> <origin xyz="0 0.30 0" rpy="0 0 0" /> <axis xyz="0 1 0" /> </joint> </robot>
$ roslaunch ros_robotics ddrobot_rviz.launch model:=dd_robot6.urdf
Move the wheel (start GUI interface)
$ roslaunch ros_robotics ddrobot_rviz.launch model:=dd_robot6.urdf gui:=True
tf and robot_state_publisher:
Node robot_state_publisher subscribed to JointState messages and published robot status messages to the tf coordinate transformation library, which maintains the relationship between the coordinate system of each element in the system and time. Node robot_state_publisher receives the joint component angle of the robot as input, calculates the 3D pose of the robot connecting rod component, and publishes the pose results.
Physical attribute reference http://en.wikipedia.org/wiki/List_of_moments_of_inertia
URDF tool:
-
Installation tools $sudo apt get install liburdfdom tools
-
Check whether the syntax of the URDF file is correct check_urdf:
~/catkin_ws/src/ros_robotics/urdf$ check_urdf dd_robot6.urdf
-
Generate the graphviz chart corresponding to the URDF file and a pdf format chart file urdf_to_graphiz:
~/catkin_ws/src/ros_robotics/urdf$ urdf_to_graphiz dd_robot6.urdf -
Open Pdf file $evince dd_robot.pdf
Gazebo
Free open source robot simulation environment
1. install Gazebo
http://answers.gazebosim.org/questions/
Questions page of ROS Forum http://answers.ros.org/questions/
Installation guide http://gazebosim.org/tutorials?cat=install
user 's manual http://gazebosim.org/tutorials
Check for installation
$ gazebo
Terminate gazebo $rosnode list
$rosnode kill -a
Starting gazebo with roslaunch $roslaunch gazebo_ ros empty_ world. launch
gazebo model validation:
gz sdf -p dd_robot.gazebo
PX4 installation:
git clone https://github.com/PX4/PX4-Autopilot.git --recursive
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
bash ./PX4-Autopilot/Tools/setup/ubuntu.sh
cd PX4-Autopilot
make px4_fmu-v3_default