四轮差分驱动平台gazebo插件

6 篇文章 0 订阅
1 篇文章 0 订阅

转载自:http://gazebosim.org/tutorials?tut=ros_gzplugins#AddingaModelPlugin

<gazebo>
  <plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so">
    <updateRate>100.0</updateRate>
    <robotNamespace>/</robotNamespace>
    <leftFrontJoint>front_left_wheel_joint</leftFrontJoint>
    <rightFrontJoint>front_right_wheel_joint</rightFrontJoint>
    <leftRearJoint>back_left_wheel_joint</leftRearJoint>
    <rightRearJoint>back_right_wheel_joint</rightRearJoint>
    <wheelSeparation>0.4</wheelSeparation>
    <wheelDiameter>0.215</wheelDiameter>
    <robotBaseFrame>base_link</robotBaseFrame>
    <torque>20</torque>
    <topicName>cmd_vel</topicName>
    <broadcastTF>false</broadcastTF>
  </plugin>
</gazebo>
  • 1
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
我可以为您提供一份用于 Gazebo 驱动件的源码:#include <gazebo/common/Plugin.hh> #include <gazebo/physics/physics.hh>namespace gazebo { class DiffDrivePlugin : public ModelPlugin { public: void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf) { // 获取模型和世界指针 this->model = _parent; this->world = this->model->GetWorld(); // 读取件参数 this->robotNamespace = ""; if (_sdf->HasElement("robotNamespace")) this->robotNamespace = _sdf->GetElement("robotNamespace")->Get<std::string>(); // 设置速器参数 this->leftJointName = "left_wheel_joint"; if (_sdf->HasElement("left_joint")) this->leftJointName = _sdf->GetElement("left_joint")->Get<std::string>(); this->rightJointName = "right_wheel_joint"; if (_sdf->HasElement("right_joint")) this->rightJointName = _sdf->GetElement("right_joint")->Get<std::string>(); // 初始化速器 this->leftJoint = this->model->GetJoint(this->leftJointName); this->rightJoint = this->model->GetJoint(this->rightJointName); // 初始化控制器 this->pid = common::PID(0.1, 0.01, 0.1); // 订阅广播状态 this->updateConnection = event::Events::ConnectWorldUpdateBegin( std::bind(&DiffDrivePlugin::OnUpdate, this)); } // 每一步更新 public: void OnUpdate() { // 计算速器控制力 double leftSpeed = this->pid.Update(this->leftJoint->GetVelocity(0), this->leftSpeedTarget); double rightSpeed = this->pid.Update(this->rightJoint->GetVelocity(0), this->rightSpeedTarget); this->leftJoint->SetForce(0, leftSpeed); this->rightJoint->SetForce(0, rightSpeed); } // 读取模型指针 private: physics::ModelPtr model; // 读取世界指针 private: physics::WorldPtr world; // 读取命名空间 private: std::string robotNamespace; // 读取左右引擎的名字 private: std::string leftJointName; private: std::string rightJointName; // 读取左右引擎的指针 private: physics::JointPtr leftJoint; private: physics::JointPtr rightJoint; // 读取PID控制器 private: common::PID pid; // 读取左右引擎的目标速度 private: double leftSpeedTarget = 0; private: double rightSpeedTarget = 0; // 读取更新连接 private: event::ConnectionPtr updateConnection; }; // 注册件 GZ_REGISTER_MODEL_PLUGIN(DiffDrivePlugin) }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值