This repository was archived by the owner on Jul 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 783
Port wheel slip plugin to ros2 (forward port from eloquent) #1148
Merged
scpeters
merged 3 commits into
ros-simulation:ros2
from
scpeters:wheel_slip_plugin_ros2
Aug 17, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
gazebo_plugins/include/gazebo_plugins/gazebo_ros_wheel_slip.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright 2019 Open Source Robotics Foundation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef GAZEBO_PLUGINS__GAZEBO_ROS_WHEEL_SLIP_HPP_ | ||
| #define GAZEBO_PLUGINS__GAZEBO_ROS_WHEEL_SLIP_HPP_ | ||
|
|
||
| #include <gazebo/common/Plugin.hh> | ||
| #include <gazebo/plugins/WheelSlipPlugin.hh> | ||
|
|
||
| #include <memory> | ||
|
|
||
| namespace gazebo_plugins | ||
| { | ||
| class GazeboRosWheelSlipPrivate; | ||
|
|
||
| /// A plugin for adjusting wheel slip parameters in gazebo. | ||
| /// The plugin can set separate longitudinal and lateral wheel slip compliance | ||
| /// parameters for separate wheel links. | ||
| /// 1. slip_compliance_unitless_lateral | ||
| /// - Type: double | ||
| /// - Description: Unitless slip compliance (slip / friction) in the | ||
| /// lateral direction. This value is applied to all wheels declared | ||
| /// in the WheelSlipPlugin. | ||
| /// | ||
| /// 2. slip_compliance_unitless_longitudinal | ||
| /// - Type: double | ||
| /// - Description: Unitless slip compliance (slip / friction) in the | ||
| /// longitudinal direction. This value is applied to all wheels declared | ||
| /// in the WheelSlipPlugin. | ||
| /// See the WheelSlipPlugin documentation at the following location for more details: | ||
| /// http://osrf-distributions.s3.amazonaws.com/gazebo/api/11.0.0/classgazebo_1_1WheelSlipPlugin.html#details | ||
| /** | ||
| Example Usage: | ||
| \code{.xml} | ||
| <!-- Plugin to set wheel slip parameters according to wheel speed --> | ||
| <plugin name="projector" filename="libgazebo_ros_wheel_speed.so"> | ||
| <ros> | ||
| <namespace>wheel_slip_front</namespace> | ||
| </ros> | ||
| <wheel link_name="wheel_front_left"> | ||
| <slip_compliance_lateral>0</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>0.1</slip_compliance_longitudinal> | ||
| <wheel_normal_force>100</wheel_normal_force> | ||
| </wheel> | ||
| <wheel link_name="wheel_front_right"> | ||
| <slip_compliance_lateral>0</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>0.1</slip_compliance_longitudinal> | ||
| <wheel_normal_force>100</wheel_normal_force> | ||
| </wheel> | ||
| </plugin> | ||
| \endcode | ||
| */ | ||
| class GazeboRosWheelSlip : public gazebo::WheelSlipPlugin | ||
| { | ||
| public: | ||
| /// Constructor | ||
| GazeboRosWheelSlip(); | ||
|
|
||
| /// Destructor | ||
| ~GazeboRosWheelSlip(); | ||
|
|
||
| protected: | ||
| // Documentation inherited | ||
| void Load(gazebo::physics::ModelPtr _model, sdf::ElementPtr _sdf) override; | ||
|
|
||
| private: | ||
| /// Private data pointer | ||
| std::unique_ptr<GazeboRosWheelSlipPrivate> impl_; | ||
| }; | ||
| } // namespace gazebo_plugins | ||
|
|
||
| #endif // GAZEBO_PLUGINS__GAZEBO_ROS_WHEEL_SLIP_HPP_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Copyright 2020 Open Source Robotics Foundation | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include <gazebo/physics/Model.hh> | ||
| #include <gazebo/physics/World.hh> | ||
|
|
||
| #include <gazebo/transport/transport.hh> | ||
| #include <gazebo_plugins/gazebo_ros_wheel_slip.hpp> | ||
| #include <gazebo_ros/node.hpp> | ||
| #include <std_msgs/msg/bool.hpp> | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| namespace gazebo_plugins | ||
| { | ||
| class GazeboRosWheelSlipPrivate | ||
| { | ||
| public: | ||
| /// A pointer to the GazeboROS node. | ||
| gazebo_ros::Node::SharedPtr ros_node_; | ||
|
|
||
| /// Handle to parameters callback | ||
| rclcpp::Node::OnSetParametersCallbackHandle::SharedPtr on_set_parameters_callback_handle_; | ||
| }; | ||
|
|
||
| GazeboRosWheelSlip::GazeboRosWheelSlip() | ||
| : impl_(std::make_unique<GazeboRosWheelSlipPrivate>()) | ||
| { | ||
| } | ||
|
|
||
| GazeboRosWheelSlip::~GazeboRosWheelSlip() | ||
| { | ||
| } | ||
|
|
||
| void GazeboRosWheelSlip::Load(gazebo::physics::ModelPtr _model, sdf::ElementPtr _sdf) | ||
| { | ||
| // Initialize the WheelSlipPlugin first so its values are preferred unless the ros | ||
| // parameters are overridden by a launch file. | ||
| WheelSlipPlugin::Load(_model, _sdf); | ||
|
|
||
| // Initialize ROS node | ||
| impl_->ros_node_ = gazebo_ros::Node::Get(_sdf); | ||
|
|
||
| auto param_change_callback = | ||
| [this](std::vector<rclcpp::Parameter> parameters) { | ||
| auto result = rcl_interfaces::msg::SetParametersResult(); | ||
| result.successful = true; | ||
| for (const auto & parameter : parameters) { | ||
| std::string param_name = parameter.get_name(); | ||
| if (param_name == "slip_compliance_unitless_lateral") { | ||
| double slip = parameter.as_double(); | ||
| if (slip >= 0.) { | ||
| RCLCPP_INFO( | ||
| impl_->ros_node_->get_logger(), | ||
| "New lateral slip compliance: %.3e", slip); | ||
| this->SetSlipComplianceLateral(slip); | ||
| } | ||
| } else if (param_name == "slip_compliance_unitless_longitudinal") { | ||
| double slip = parameter.as_double(); | ||
| if (slip >= 0.) { | ||
| RCLCPP_INFO( | ||
| impl_->ros_node_->get_logger(), | ||
| "New longitudinal slip compliance: %.3e", slip); | ||
| this->SetSlipComplianceLongitudinal(slip); | ||
| } | ||
| } else { | ||
| RCLCPP_WARN( | ||
| impl_->ros_node_->get_logger(), | ||
| "Unrecognized parameter name[%s]", param_name); | ||
| result.successful = false; | ||
| } | ||
| } | ||
| return result; | ||
| }; | ||
|
|
||
| impl_->on_set_parameters_callback_handle_ = impl_->ros_node_->add_on_set_parameters_callback( | ||
| param_change_callback); | ||
|
|
||
| // Declare parameters after adding callback so that callback will trigger immediately. | ||
| // Set negative values by default, which are ignored by the callback. | ||
| // This approach allows values specified in a launch file to override the SDF/URDF values. | ||
| impl_->ros_node_->declare_parameter("slip_compliance_unitless_lateral", -1.); | ||
| impl_->ros_node_->declare_parameter("slip_compliance_unitless_longitudinal", -1.); | ||
| } | ||
|
|
||
| GZ_REGISTER_MODEL_PLUGIN(GazeboRosWheelSlip) | ||
| } // namespace gazebo_plugins |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| <?xml version="1.0" ?> | ||
| <!-- | ||
| Gazebo ROS wheel slip plugin demo | ||
|
|
||
| Try for example: | ||
|
|
||
| To change slip compliance of a group of wheels: | ||
|
|
||
| ros2 param set /trisphere_cycle_slip0/wheel_slip_rear slip_compliance_unitless_longitudinal 1.0 | ||
| ros2 param set /trisphere_cycle_slip1/wheel_slip_rear slip_compliance_unitless_longitudinal 0.0 | ||
|
|
||
| To get the current slip compliance of a group of wheels: | ||
|
|
||
| ros2 param get /trisphere_cycle_slip1/wheel_slip_rear slip_compliance_unitless_longitudinal | ||
| --> | ||
| <sdf version="1.6"> | ||
| <world name="default"> | ||
| <gravity>-2 0 -9.8</gravity> | ||
|
|
||
| <include> | ||
| <uri>model://ground_plane</uri> | ||
| </include> | ||
| <include> | ||
| <uri>model://sun</uri> | ||
| </include> | ||
|
|
||
| <include> | ||
| <uri>model://trisphere_cycle</uri> | ||
| <name>trisphere_cycle_slip0</name> | ||
| <pose>0 0 0 0 0 0</pose> | ||
| <plugin name="wheel_slip_front" filename="libgazebo_ros_wheel_slip.so"> | ||
| <ros> | ||
| <namespace>trisphere_cycle_slip0</namespace> | ||
| </ros> | ||
| <wheel link_name="wheel_front"> | ||
| <slip_compliance_lateral>0</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>0</slip_compliance_longitudinal> | ||
| <wheel_normal_force>77</wheel_normal_force> | ||
| </wheel> | ||
| </plugin> | ||
| <plugin name="wheel_slip_rear" filename="libgazebo_ros_wheel_slip.so"> | ||
| <ros> | ||
| <namespace>trisphere_cycle_slip0</namespace> | ||
| </ros> | ||
| <wheel link_name="wheel_rear_left"> | ||
| <slip_compliance_lateral>0</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>0</slip_compliance_longitudinal> | ||
| <wheel_normal_force>32</wheel_normal_force> | ||
| </wheel> | ||
| <wheel link_name="wheel_rear_right"> | ||
| <slip_compliance_lateral>0</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>0</slip_compliance_longitudinal> | ||
| <wheel_normal_force>32</wheel_normal_force> | ||
| </wheel> | ||
| </plugin> | ||
| <plugin name="joint_control" filename="libJointControlPlugin.so"> | ||
| <controller type="position"> | ||
| <joint>wheel_front_steer</joint> | ||
| <target>0</target> | ||
| <pid_gains>9 0 0.1</pid_gains> | ||
| </controller> | ||
| <controller type="velocity"> | ||
| <joint>wheel_rear_left_spin</joint> | ||
| <joint>wheel_rear_right_spin</joint> | ||
| <target>6.0</target> | ||
| <pid_gains>9 0 0</pid_gains> | ||
| </controller> | ||
| <controller type="force"> | ||
| <joint>wheel_rear_left_spin</joint> | ||
| <joint>wheel_rear_right_spin</joint> | ||
| <target>2.15</target> | ||
| </controller> | ||
| </plugin> | ||
| </include> | ||
|
|
||
| <include> | ||
| <uri>model://trisphere_cycle</uri> | ||
| <name>trisphere_cycle_slip1</name> | ||
| <pose>0 2 0 0 0 0</pose> | ||
| <plugin name="wheel_slip_front" filename="libgazebo_ros_wheel_slip.so"> | ||
| <ros> | ||
| <namespace>trisphere_cycle_slip1</namespace> | ||
| </ros> | ||
| <wheel link_name="wheel_front"> | ||
| <slip_compliance_lateral>1</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>1</slip_compliance_longitudinal> | ||
| <wheel_normal_force>77</wheel_normal_force> | ||
| </wheel> | ||
| </plugin> | ||
| <plugin name="wheel_slip_rear" filename="libgazebo_ros_wheel_slip.so"> | ||
| <ros> | ||
| <namespace>trisphere_cycle_slip1</namespace> | ||
| </ros> | ||
| <wheel link_name="wheel_rear_left"> | ||
| <slip_compliance_lateral>1</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>1</slip_compliance_longitudinal> | ||
| <wheel_normal_force>32</wheel_normal_force> | ||
| </wheel> | ||
| <wheel link_name="wheel_rear_right"> | ||
| <slip_compliance_lateral>1</slip_compliance_lateral> | ||
| <slip_compliance_longitudinal>1</slip_compliance_longitudinal> | ||
| <wheel_normal_force>32</wheel_normal_force> | ||
| </wheel> | ||
| </plugin> | ||
| <plugin name="joint_control" filename="libJointControlPlugin.so"> | ||
| <controller type="position"> | ||
| <joint>wheel_front_steer</joint> | ||
| <target>0</target> | ||
| <pid_gains>9 0 0.1</pid_gains> | ||
| </controller> | ||
| <controller type="velocity"> | ||
| <joint>wheel_rear_left_spin</joint> | ||
| <joint>wheel_rear_right_spin</joint> | ||
| <target>6.0</target> | ||
| <pid_gains>9 0 0</pid_gains> | ||
| </controller> | ||
| <controller type="force"> | ||
| <joint>wheel_rear_left_spin</joint> | ||
| <joint>wheel_rear_right_spin</joint> | ||
| <target>2.15</target> | ||
| </controller> | ||
| </plugin> | ||
| </include> | ||
|
|
||
| <gui fullscreen='0'> | ||
| <camera name='user_camera'> | ||
| <pose>1.5 -4 2.5 0 0.5 1.6</pose> | ||
| <view_controller>orbit</view_controller> | ||
| </camera> | ||
| </gui> | ||
| </world> | ||
| </sdf> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.