如何在ROS2 Humble中使用ackermann插件

问题描述 投票:0回答:1

我正在制作 4 轮阿克曼汽车的 urdf 模型。我想使用 ackerman Gazebo 插件,在 github 中我找到了一个使用示例,如下:

<gazebo>
    <plugin name="gazebo_ros_ackermann_drive" filename="libgazebo_ros_ackermann_drive.so">

  <ros>
    <namespace>ackermann</namespace>
    <remapping>cmd_vel:=cmd_vel</remapping>
    <remapping>odom:=odom</remapping>
    <remapping>distance:=distance</remapping>
  </ros>

  <update_rate>100.0</update_rate>

  <!-- wheels -->
  <front_left_joint>front_left_joint</front_left_joint>
  <front_right_joint>front_eight_joint</front_right_joint>
  <rear_left_joint>rear_left_joint</rear_left_joint>
  <rear_right_joint>rear_right_joint</rear_right_joint>
  <left_steering_joint>left_steering_joint</left_steering_joint>
  <right_steering_joint>right_steering_joint</right_steering_joint>
  <steering_wheel_joint>steering_joint</steering_wheel_joint>
  

  <!-- Max absolute steer angle for tyre in radians-->
  <!-- Any cmd_vel angular z greater than this would be capped -->
  <max_steer>0.6458</max_steer>

  <!-- Max absolute steering angle of steering wheel -->
  <max_steering_angle>7.85</max_steering_angle>

  <!-- Max absolute linear speed in m/s -->
  <max_speed>20</max_speed>

  <!-- PID tuning -->
  <left_steering_pid_gain>1500 0 1</left_steering_pid_gain>
  <left_steering_i_range>0 0</left_steering_i_range>
  <right_steering_pid_gain>1500 0 1</right_steering_pid_gain>
  <right_steering_i_range>0 0</right_steering_i_range>
  <linear_velocity_pid_gain>1000 0 1</linear_velocity_pid_gain>
  <linear_velocity_i_range>0 0</linear_velocity_i_range>

  <!-- output -->
  <publish_odom>true</publish_odom>
  <publish_odom_tf>true</publish_odom_tf>
  <publish_wheel_tf>true</publish_wheel_tf>
  <publish_distance>true</publish_distance>

  <odometry_frame>odom</odometry_frame>
  <robot_base_frame>base_footprint</robot_base_frame>

</plugin>
</gazebo>

我的问题出在关节上,因为我制作了 4 个连续关节来使车轮滚动,并制作了两个旋转关节来使前轮沿 z 轴旋转。这 4 个关节是您在插件标签中可以看到的前四个关节。我的问题是,方向盘接头到底是什么?我必须把它放在哪里以及它应该如何连接到汽车的其他部分?如果我删除它,我实际上不会收到错误消息,但我的所有车轮都会在汽车下方移动到中心。如果我只在 Rviz 上显示 urdf,该模型似乎不错。我的 urdf 结构由车身的 base_link、4 个轮子和 base_footprint 组成。

这是仅使用Rviz推出的型号:

Model when I only launch Rviz

这是我启动 Gazebo 和插件的时候:

Model when I launch Gazebo and the plugin too

ros robotics ros2 gazebo-simu ackermann
1个回答
0
投票

一般来说,

ackermann_drive
插件的工作原理是订阅名为
cmd_vel
(或者使用不同的名称,如果您在 urdf 文件中重新映射)类型为
geometry_msgs::msg::Twist
的主题,这意味着包含目标线速度和整车的目标横摆率。基于此目标,使用您在
urdf
中设置的 PID 控制器为驱动轮和方向盘生成单独的扭矩命令。

从这个意义上说,这里没有方向盘,你是用这个扭转命令来转向的。根据我通过查看代码的理解,

steering_wheel_joint
并不是严格需要的,但您不应该删除它,因为,正如您所注意到的,整个链接/关节结构受到损害。我猜想,如果您有一些链接连接到
steering_wheel_joint
,那么它将被渲染为实际的方向盘,来自左右方向盘的平均值(与物理现实中发生的情况相反) ).

要查找此内容,您实际上应该打开插件文件gazebo_ros_ackermann_drive.cpp

只是一个片段(第 533-543 行,来自我的评论):

// computing the steering wheel angle averaging left and right
auto steer_wheel_angle = (left_steering_angle + right_steering_angle) * 0.5 / steering_ratio_;
// setting the steer torque on the steering wheels
joints_[STEER_LEFT]->SetForce(0, left_steering_cmd);
joints_[STEER_RIGHT]->SetForce(0, right_steering_cmd);
// setting the driving torque on the driving wheels
joints_[REAR_RIGHT]->SetForce(0, linear_cmd);
joints_[REAR_LEFT]->SetForce(0, linear_cmd);

if (joints_.size() == 7) {
  // setting the steer angle
  joints_[STEER_WHEEL]->SetPosition(0, steer_wheel_angle);
}

另外(第 224-229 行):

// if the steering_wheel_joint is deleted
if (!impl_->joints_[GazeboRosAckermannDrivePrivate::STEER_WHEEL]) {
RCLCPP_WARN(
  impl_->ros_node_->get_logger(),
  "Steering wheel joint [%s] not found.", steering_wheel_joint.c_str());
  // the joints are potentially messed up
  impl_->joints_.resize(6);
}

如需更详细的答案,我需要您提供更多详细信息:)

希望这能有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.