ros 学习记录(二)URDF小车运动控制

发布于:2024-05-10 ⋅ 阅读:(23) ⋅ 点赞:(0)

URDF小车运动控制

上文,想用键盘控制小车在Gazebo中移动。

准备工作

名称 版本
ROS Noetic
Gazebo 11.11.0

创建 robot_xacro.launch

通过运行这个launch文件,可以启动Gazebo仿真环境,并在仿真环境中加载和控制机器人模型。

cd ~/roboT_four/src/robot_model_pkg_zoe/launch
touch robot_xacro.launch
<?xml version="1.0"?>
<!--##########################################-->
<!--Launch file for the Gazebo simulation of the 4-wheeled robot-->
<!--##########################################-->

<launch>

<include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="paused" value="false"/>
    <arg name="use_sim_time" value="true"/>
    <arg name="gui" value="true"/>
    <arg name="headless" value="false"/>
    <arg name="debug" value="false"/>
</include>

<!--Load the robot description-->
<param name="robot_description" command="$(find xacro)/xacro '$(find robot_model_pkg_zoe)/urdf/robot.xacro'"/>

<!--Robot state publisher node-->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />

<!--Spawn the model-->
<node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model"  output="screen" respawn="false" args="-urdf -model robot_model -param robot_description" />

</launch>

在两个terminal中分别运行:

roslaunch robot_model_pkg_zoe robot_xacro.launch
rosrun teleop_twist_keyboard teleop_twist_keyboard.py #用键盘来控制小车运动

U: 逆时针转
I: 直线向前
O: 顺时针转
空格 : 停止

检查 topic得:

root@cf943b247720:~/robot_four# rostopic list
/clock
/cmd_vel
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/performance_metrics
/gazebo/set_link_state
/gazebo/set_model_state
/joint_states
/odom
/rosout
/rosout_agg
/tf
/tf_static

控制运动的topic/cmd_vel,检视该topic

root@cf943b247720:~/robot_four# rostopic info /cmd_vel
Type: geometry_msgs/Twist

Publishers: 
 * /teleop_twist_keyboard (http://cf943b247720:41719/)

Subscribers: 
 * /gazebo (http://cf943b247720:45045/)

当直线运动(按住I键)时,在x轴方向移动:

root@cf943b247720:~/robot_four# rostopic echo /cmd_vel
linear: 
  x: 0.5
  y: 0.0
  z: 0.0
angular: 
  x: 0.0
  y: 0.0
  z: 0.0

运行前:在这里插入图片描述
运行后:
在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到