1,创建工作空间,并catkin_make编译
mkdir -p ~/ros_env8/src
cd ~/ros_env8
catkin_make
打开用户配置文件
gedit ~/.bashrc
在文件末尾加入以下代码
保存之后
source ~/.bashrc
2,进入工作空间下面的src目录下,创建功能包
cd src
catkin_create_pkg begin3 std_msgs rospy roscpp
3,在begin3这个功能包下面创建两个文件夹 urdf launch
4,在urdf文件夹中新建一个mrobot_aa.urdf
<?xml version="1.0" ?>
<robot name="jubot">
<!--base_car-->
<link name="base_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<geometry>
<cylinder radius="0.20" length="0.16"/>
</geometry>
<material name="yellow">
<color rgba="1 0.4 0 1"/>
</material>
</visual>
</link>
<!--left_wheel-->
<joint name="left_wheel_joint" type="continuous">
<origin xyz="0.0 0.19 -0.05" rpy="0.0 0.0 0.0"/>
<parent link="base_link"/>
<child link="left_wheel_link"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="left_wheel_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="1.5707 0.0 0.0"/>
<geometry>
<cylinder radius="0.06" length="0.025"/>
</geometry>
<material name="white">
<color rgba="1 1 1 0.9"/>
</material>
</visual>
</link>
<!--right_wheel-->
<joint name="right_wheel_joint" type="continuous">
<origin xyz="0.0 -0.19 -0.05"/>
<parent link="base_link"/>
<child link="right_wheel_link"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="right_wheel_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="1.5707 0.0 0.0"/>
<geometry>
<cylinder radius="0.06" length="0.025"/>
</geometry>
<material name="white">
<color rgba="1 1.0 1.0 0.9"/>
</material>
</visual>
</link>
<!--front_caster-->
<joint name="front_caster_joint" type="continuous">
<origin xyz="0.18 0.0 -0.095" rpy="0.0 0.0 0.0"/>
<parent link="base_link"/>
<child link="front_caster_link"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="front_caster_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<geometry>
<sphere radius="0.015"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.95"/>
</material>
</visual>
</link>
<!--back_caster-->
<joint name="back_caster_joint" type="continuous">
<origin xyz="-0.18 0.0 -0.095" rpy="0.0 0.0 0.0"/>
<parent link="base_link"/>
<child link="back_caster_link"/>
<axis xyz="0.0 1.0 0.0"/>
</joint>
<link name="back_caster_link">
<visual>
<origin xyz="0.0 0.0 0.0" rpy="0.0 0.0 0.0"/>
<geometry>
<sphere radius="0.015"/>
</geometry>
<material name="black">
<color rgba="0.0 0.0 0.0 0.95"/>
</material>
</visual>
</link>
</robot>
5,在launch这个文件夹下新建一个bbb.launch文件
在bbb.launch文件中写入以下代码
<launch>
<param name="robot_description" textfile="$(find begin3)/urdf/mrobot_aa.urdf"/>
<param name="gui" value="true"/>
<node name="joint_state_publisher_gui"
pkg="joint_state_publisher_gui"
type="joint_state_publisher_gui" />
<node name="joint_state_publisher"
pkg="joint_state_publisher"
type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher"
type="robot_state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d $(find begin3)/config/mrobot_urdf.rviz"
required="true" />
</launch>
6,修改package.xml文件
<build_depend>urdf</build_depend>
<build_depend>xacro</build_depend>
<build_export_depend>urdf</build_export_depend>
<build_export_depend>xacro</build_export_depend>
<exec_depend>urdf</exec_depend>
<exec_depend>xacro</exec_depend>
7,修改CMakeLists.txt文件
第一处修改
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
urdf
xacro
)
第二处修改
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES begin3
CATKIN_DEPENDS roscpp rospy std_msgs urdf xacro
# DEPENDS system_lib
)
8,进入launch文件夹下,启动模型文件
roslaunch begin3 bbb.launch
最下面有个Add按钮,点击它,会进入这个界面
点击RobotModel,即可选择自己的模型文件