[Top-up] Ros exploration Summary (6) -- Simulation Using smartcar

Source: Internet
Author: User

In our previous blog, we used rviz to simulate turtlebot and used the urdf file to create our own robot smartcar. This blog is to combine the two, use the smartcar robot to simulate in rviz.

I. Complete Models Previously, we used urdf file format models. In many cases, Ros does not support urdf files very well. Using macro-defined. xacro files has better compatibility and scalability. Therefore, we recompile the previous urdf file into a. xacro file.
The. xacro file consists of three parts:
1. Robot subject
<? XML version = "1.0"?> <Robot name = "smartcar" xmlns: xacro = "http://ros.org/wiki/xacro"> <property name = "m_pi" value = "3.14159"/> <! -- Macro for smartcar body. including gazebo extensions, but does not include Kinect --> <include filename = "$ (find smartcar_description)/urdf/gazebo. urdf. xacro "/> <property name =" base_x "value =" 0.33 "/> <property name =" base_y "value =" 0.33 "/> <xacro: macro name = "smartcar_body"> <Link name = "base_link"> <inertial> <origin XYZ = "0 0 0.055"/> <mass value = "1.0"/> <inertia ixx = "1.0" ixy = "0.0" ixz = "0.0" iyy = "1.0" iyz = "0.0" Izz = "1.0"/> </inertial> <visual> <geometry> <box size = "0.25. 16. 05 "/> </geometry> <origin RPY =" 0 0 0 "XYZ =" 0 0 0.055 "/> <material name =" blue "> <color rgba =" 0 0. 8 1 "/> </material> </visual> <collision> <origin RPY =" 0 0 0 "XYZ =" 0 0 0.055 "/> <geometry> <box size = "1. 0.25. 16. 05 "/> </geometry> </collision> </link> <Link name =" left_front_wheel "> <inertial> <origin XYZ =" 0.08 0.08 0.025 "/> <mass value = "0.1"/> <inertia ixx = "1.0" ixy = "0.0" ixz = "0.0" iyy = "1.0" iyz = "0.0" Izz = "1.0 "/> </inertial> <visual> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> <material name =" black "> <color rgba =" 0 0 0 1 "/> </material> </visual> <collision> <origin RPY = "0 1.57075 1.57075" XYZ = "0.08 0.08 0.025"/> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> </collision> </link> <joint name =" left_front_wheel_joint "type =" continuous "> <axis XYZ =" 0 0 1 "/> <parent link =" base_link "/> <Child Link =" left_front_wheel "/> <origin RPY =" 0 1.57075 1.57075 "XYZ =" 0.08 0.08 0.025 "/> <limit effort = "100" velocity = "100"/> <joint_properties damping = "0.0" friction = "0.0"/> </Joint> <Link name = "right_front_wheel"> <inertial> <origin XYZ = "0.08-0.08 0.025"/> <mass value = "0.1"/> <inertia ixx = "1.0" ixy = "0.0" ixz =" 0.0 "iyy =" 1.0 "iyz =" 0.0 "Izz =" 1.0 "/> </inertial> <visual> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> <material name =" black "> <color rgba =" 0 0 0 1 "/> </material> </visual> <collision> <origin RPY = "0 1.57075 1.57075" XYZ = "0.08-0.08 0.025"/> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> </collision> </link> <joint name =" right_front_wheel_joint "type =" continuous "> <axis XYZ =" 0 0 1 "/> <parent link =" base_link "/> <Child Link =" right_front_wheel "/> <origin RPY =" 0 1.57075 "XYZ =" 1.57075-0.08 0.08" /> <limit effort = "100" velocity = "100"/> <joint_properties damping = "0.0" friction = "0.0"/> </Joint> <Link name = "left_back_wheel "> <inertial> <origin XYZ ="-0.08 0.08 0.025 "/> <mass value =" 0.1 "/> <inertia ixx =" 1.0 "ixy =" 0.0 "ixz = "0.0" iyy = "1.0" iyz = "0.0" Izz = "1.0"/> </inertial> <visual> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> <material name =" black "> <color rgba =" 0 0 0 1 "/> </material> </visual> <collision> <origin RPY = "0 1.57075 1.57075" XYZ = "-0.08 0.08 0.025"/> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> </collision> </link> <joint name =" left_back_wheel_joint "type =" continuous "> <axis XYZ =" 0 0 1 "/> <parent link =" base_link "/> <Child Link =" left_back_wheel "/> <origin RPY =" 0 1.57075 1.57075 "XYZ ="-0.08 0.08 0.025" /> <limit effort = "100" velocity = "100"/> <joint_properties damping = "0.0" friction = "0.0"/> </Joint> <Link name = "right_back_wheel "> <inertial> <origin XYZ ="-0.08-0.08 0.025 "/> <mass value =" 0.1 "/> <inertia ixx =" 1.0 "ixy =" 0.0 "ixz = "0.0" iyy = "1.0" iyz = "0.0" Izz = "1.0"/> </inertial> <visual> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> <material name =" black "> <color rgba =" 0 0 0 1 "/> </material> </visual> <collision> <origin RPY = "0 1.57075 1.57075" XYZ = "-0.08-0.08 0.025"/> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> </collision> </link> <joint name =" right_back_wheel_joint "type =" continuous "> <axis XYZ =" 0 0 1 "/> <parent link =" base_link "/> <Child Link =" right_back_wheel "/> <origin RPY =" 0 1.57075 "XYZ ="-1.57075-0.08 0.08 "/> <limit effort =" 100 "velocity =" 100 "/> <joint_properties damping =" 0.0 "friction =" 0.0 "/> </Joint> <Link name =" head "> <inertial> <origin XYZ =" 0.08 0 0.08 "/> <mass value =" 0.1 "/> <inertia ixx =" 1.0 "ixy =" 0.0 "ixz = "0.0" iyy = "1.0" iyz = "0.0" Izz = "1.0"/> </inertial> <visual> <geometry> <box size = ". 02. 03. 03 "/> </geometry> <material name =" white "> <color rgba =" 1 1 1 "/> </material> </visual> <collision> <origin XYZ = "0.08 0 0.08"/> <geometry> <cylinder length = ". 02 "radius =" 0.025 "/> </geometry> </collision> </link> <joint name =" tobox "type =" fixed "> <parent link =" base_link "/> <Child Link =" head "/> <origin XYZ =" 0.08 0 0.08 "/> </Joint> </xacro: macro> </robot>

2. gazebo attributes

<? XML version = "1.0"?> <Robot xmlns: controller = "http://playerstage.sourceforge.net/gazebo/xmlschema/#controller" xmlns: interface = "http://playerstage.sourceforge.net/gazebo/xmlschema/#interface" xmlns: Sensor = "http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor" xmlns: xacro = "http://ros.org/wiki/xacro" name = "smartcar_gazebo"> <! -- Asus xtion pro camera for simulation --> <! -- Gazebo_ros_wge100 plugin is in kt2_gazebo_plugins package --> <xacro: macro name = "smartcar_sim"> <gazebo reference = "base_link"> <material> gazebo/blue </material> </gazebo> <gazebo reference = "right_front_wheel"> <material> gazebo/flatblack </material> </gazebo> <gazebo reference = "regular"> <material> gazebo/flatblack </material> </gazebo> <gazebo reference = "regular"> <material> gazebo/flatblack </material> </gazebo> <gazebo reference = "regular"> <material> gazebo/flatblack </material> </gazebo> = "head"> <material> gazebo/White </material> </gazebo> </xacro: macro> </robot>

3. Main File

 
<? XML version = "1.0"?> <Robot name = "turtlebot" xmlns: Sensor = "http://playerstage.sourceforge.net/gazebo/xmlschema/#sensor" xmlns: controller = "http://playerstage.sourceforge.net/gazebo/xmlschema/#controller" xmlns: interface = "http://playerstage.sourceforge.net/gazebo/xmlschema/#interface" xmlns: xacro = "http://ros.org/wiki/xacro"> <include filename = "$ (find smartcar_description)/urdf/smartcar_body.urdf.xacro"/> <! -- Body of smartcar, with plates, standoffs and create (including SIM sensors) --> <smartcar_body/> </robot>

Ii. lanuch File

Start the node and simulator in the launch file.
<Launch> <Param name = "/use_sim_time" value = "false"/> <! -- Load the urdf/xacro model of our robot --> <Arg name = "urdf_file" default = "$ (find xacro)/xacro. py' $ (find smartcar_description)/urdf/smartcar. urdf. xacro '"/> <Arg name =" Gui "default =" false "/> <Param name =" robot_description "command =" $ (ARG urdf_file) "/> <Param name =" use_gui "value =" $ (arg gui) "/> <node name =" arbotix "PKG =" arbotix_python "type =" driver. PY "output =" screen "> <rosparam file =" $ (find smartc Ar_description) /config/smartcar_arbotix.yaml "command =" LOAD "/> <Param name =" Sim "value =" true "/> </node> <node name =" joint_state_publisher "PKG =" export "type =" joint_state_publisher "> </node> <node name =" robot_state_publisher "PKG =" robot_state_publisher "type =" state_publisher "> <Param name =" publish_frequency "type =" double "value =" 20.0 "/> </node> <! -- We need a static Transforms for the wheels --> <node PKG = "TF" type = "static_transform_publisher" name = "odom_left_wheel_broadcaster" ARGs = "0 0 0 0 0 0/base_link/ left_front_link 100 "/> <node PKG =" TF "type =" static_transform_publisher "name =" inline "ARGs =" 0 0 0 0 0 0/base_link/right_front_link 100 "/> <node name = "rviz" PKG = "rviz" type = "rviz" ARGs = "-d $ (find smartcar_description) /urdf. VCG "/> </launch>

Iii. Simulation Test

Run lanuch to see the rviz ROBOT:
 
Roslaunch smartcar_display.rviz.launch


Publish an action message.

 
Rostopic pub-R 10/cmd_vel geometry_msgs/Twist '{linear: {X: 0.5, Y: 0, Z: 0}, angular: {X: 0, Y: 0, z: 0.5 }}'

Iv. node relationship

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.