chassis_base.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2021, Qiayuan Liao
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE
25  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *******************************************************************************/
33 
34 //
35 // Created by huakang on 2021/3/21.
36 //
37 
38 #pragma once
39 
46 #include <rm_msgs/ChassisCmd.h>
47 #include <geometry_msgs/TwistStamped.h>
48 #include <geometry_msgs/Vector3Stamped.h>
49 #include <nav_msgs/Odometry.h>
51 
52 namespace rm_chassis_controllers
53 {
54 struct Command
55 {
56  geometry_msgs::Twist cmd_vel_;
57  rm_msgs::ChassisCmd cmd_chassis_;
59 };
60 template <typename... T>
61 class ChassisBase : public controller_interface::MultiInterfaceController<T...>
62 {
63 public:
64  ChassisBase() = default;
76  bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh) override;
88  void update(const ros::Time& time, const ros::Duration& period) override;
89 
90 protected:
95  void raw();
103  void follow(const ros::Time& time, const ros::Duration& period);
111  void twist(const ros::Time& time, const ros::Duration& period);
112  virtual void moveJoint(const ros::Time& time, const ros::Duration& period) = 0;
113  virtual geometry_msgs::Twist odometry() = 0;
119  void updateOdom(const ros::Time& time, const ros::Duration& period);
122  void recovery();
127  void tfVelToBase(const std::string& from);
132  void powerLimit();
137  void cmdChassisCallback(const rm_msgs::ChassisCmdConstPtr& msg);
142  void cmdVelCallback(const geometry_msgs::Twist::ConstPtr& msg);
143  void outsideOdomCallback(const nav_msgs::Odometry::ConstPtr& msg);
144 
147  std::vector<hardware_interface::JointHandle> joint_handles_{};
148 
150  power_offset_{};
151  double max_odom_vel_;
152  bool enable_odom_tf_ = false;
153  bool topic_update_ = false;
154  bool publish_odom_tf_ = false;
155  bool state_changed_ = true;
156  enum
157  {
158  RAW,
159  FOLLOW,
160  TWIST
161  };
162  int state_ = RAW;
165 
167  geometry_msgs::TransformStamped odom2base_{};
169  geometry_msgs::Vector3 vel_cmd_{}; // x, y
171 
172  std::shared_ptr<realtime_tools::RealtimePublisher<nav_msgs::Odometry> > odom_pub_;
180 };
181 
182 } // namespace rm_chassis_controllers
realtime_tools::RealtimeBuffer
rm_chassis_controllers::ChassisBase::power_offset_
double power_offset_
Definition: chassis_base.h:181
rm_common::TfRtBroadcaster
rm_chassis_controllers::ChassisBase::follow_source_frame_
std::string follow_source_frame_
Definition: chassis_base.h:195
realtime_publisher.h
rm_chassis_controllers::ChassisBase::twist
void twist(const ros::Time &time, const ros::Duration &period)
The mode TWIST: Just moving chassis.
Definition: chassis_base.cpp:241
RampFilter< double >
rm_chassis_controllers::ChassisBase::ramp_y_
RampFilter< double > * ramp_y_
Definition: chassis_base.h:194
rm_chassis_controllers::ChassisBase::TWIST
@ TWIST
Definition: chassis_base.h:191
rm_chassis_controllers::ChassisBase::odom_pub_
std::shared_ptr< realtime_tools::RealtimePublisher< nav_msgs::Odometry > > odom_pub_
Definition: chassis_base.h:203
rm_chassis_controllers::ChassisBase::update
void update(const ros::Time &time, const ros::Duration &period) override
Receive real_time command from manual. Execute different action according to current mode....
Definition: chassis_base.cpp:152
rm_chassis_controllers::ChassisBase::enable_odom_tf_
bool enable_odom_tf_
Definition: chassis_base.h:183
rm_chassis_controllers::ChassisBase::ChassisBase
ChassisBase()=default
rm_chassis_controllers::Command
Definition: chassis_base.h:85
rm_chassis_controllers::ChassisBase::recovery
void recovery()
Set chassis velocity to zero.
Definition: chassis_base.cpp:402
rm_chassis_controllers::ChassisBase::command_source_frame_
std::string command_source_frame_
Definition: chassis_base.h:195
rm_chassis_controllers::ChassisBase::ramp_x_
RampFilter< double > * ramp_x_
Definition: chassis_base.h:194
rm_chassis_controllers::ChassisBase::follow
void follow(const ros::Time &time, const ros::Duration &period)
The mode FOLLOW: chassis will follow gimbal.
Definition: chassis_base.cpp:213
rm_control::RobotStateHandle
rm_chassis_controllers::ChassisBase::vel_cmd_
geometry_msgs::Vector3 vel_cmd_
Definition: chassis_base.h:200
rm_chassis_controllers::ChassisBase::cmd_struct_
Command cmd_struct_
Definition: chassis_base.h:208
joint_velocity_controller.h
filters.h
rm_chassis_controllers::ChassisBase::twist_angular_
double twist_angular_
Definition: chassis_base.h:180
rm_chassis_controllers::ChassisBase::effort_joint_interface_
hardware_interface::EffortJointInterface * effort_joint_interface_
Definition: chassis_base.h:177
rm_chassis_controllers::ChassisBase::odometry
virtual geometry_msgs::Twist odometry()=0
rm_chassis_controllers::ChassisBase::max_odom_vel_
double max_odom_vel_
Definition: chassis_base.h:182
rm_chassis_controllers::ChassisBase::timeout_
double timeout_
Definition: chassis_base.h:180
rm_chassis_controllers::ChassisBase::tf_broadcaster_
rm_common::TfRtBroadcaster tf_broadcaster_
Definition: chassis_base.h:204
rm_chassis_controllers::ChassisBase::updateOdom
void updateOdom(const ros::Time &time, const ros::Duration &period)
Init frame on base_link. Integral vel to pos and angle.
Definition: chassis_base.cpp:294
rm_chassis_controllers::ChassisBase::pid_follow_
control_toolbox::Pid pid_follow_
Definition: chassis_base.h:201
joint_command_interface.h
hardware_interface::RobotHW
rm_chassis_controllers::ChassisBase::publish_odom_tf_
bool publish_odom_tf_
Definition: chassis_base.h:185
rm_chassis_controllers::ChassisBase::effort_coeff_
double effort_coeff_
Definition: chassis_base.h:180
controller_interface::MultiInterfaceController
rm_chassis_controllers::ChassisBase::world2odom_
tf2::Transform world2odom_
Definition: chassis_base.h:199
rm_chassis_controllers::ChassisBase::raw
void raw()
Definition: chassis_base.cpp:281
tf2::Transform
rm_chassis_controllers::ChassisBase::ramp_w_
RampFilter< double > * ramp_w_
Definition: chassis_base.h:194
hardware_interface::EffortJointInterface
rm_chassis_controllers::ChassisBase::velocity_coeff_
double velocity_coeff_
Definition: chassis_base.h:180
rm_chassis_controllers::ChassisBase::outside_odom_sub_
ros::Subscriber outside_odom_sub_
Definition: chassis_base.h:205
rm_chassis_controllers::ChassisBase::FOLLOW
@ FOLLOW
Definition: chassis_base.h:190
rm_chassis_controllers::Command::stamp_
ros::Time stamp_
Definition: chassis_base.h:120
rm_chassis_controllers::Command::cmd_chassis_
rm_msgs::ChassisCmd cmd_chassis_
Definition: chassis_base.h:119
rm_chassis_controllers::ChassisBase::last_publish_time_
ros::Time last_publish_time_
Definition: chassis_base.h:197
robot_state_interface.h
rm_chassis_controllers::ChassisBase::init
bool init(hardware_interface::RobotHW *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override
Get and check params for covariances. Setup odometry realtime publisher + odom message constant field...
Definition: chassis_base.cpp:83
rm_chassis_controllers::ChassisBase::moveJoint
virtual void moveJoint(const ros::Time &time, const ros::Duration &period)=0
rm_chassis_controllers::ChassisBase::outsideOdomCallback
void outsideOdomCallback(const nav_msgs::Odometry::ConstPtr &msg)
Definition: chassis_base.cpp:466
rm_chassis_controllers::ChassisBase::RAW
@ RAW
Definition: chassis_base.h:189
rm_chassis_controllers::ChassisBase::cmd_rt_buffer_
realtime_tools::RealtimeBuffer< Command > cmd_rt_buffer_
Definition: chassis_base.h:209
rm_chassis_controllers::ChassisBase::cmd_chassis_sub_
ros::Subscriber cmd_chassis_sub_
Definition: chassis_base.h:206
ros::Time
rm_chassis_controllers::ChassisBase::state_changed_
bool state_changed_
Definition: chassis_base.h:186
rm_chassis_controllers::ChassisBase::cmdChassisCallback
void cmdChassisCallback(const rm_msgs::ChassisCmdConstPtr &msg)
Write current command from rm_msgs::ChassisCmd.
Definition: chassis_base.cpp:451
rm_chassis_controllers::ChassisBase::tfVelToBase
void tfVelToBase(const std::string &from)
Transform tf velocity to base link frame.
Definition: chassis_base.cpp:438
rm_chassis_controllers::ChassisBase::joint_handles_
std::vector< hardware_interface::JointHandle > joint_handles_
Definition: chassis_base.h:178
rm_chassis_controllers::ChassisBase::robot_state_handle_
rm_control::RobotStateHandle robot_state_handle_
Definition: chassis_base.h:176
control_toolbox::Pid
tf2_geometry_msgs.h
rm_chassis_controllers::ChassisBase::cmd_vel_sub_
ros::Subscriber cmd_vel_sub_
Definition: chassis_base.h:207
rm_chassis_controllers::Command::cmd_vel_
geometry_msgs::Twist cmd_vel_
Definition: chassis_base.h:118
rm_chassis_controllers::ChassisBase::odom2base_
geometry_msgs::TransformStamped odom2base_
Definition: chassis_base.h:198
rm_chassis_controllers::ChassisBase::cmdVelCallback
void cmdVelCallback(const geometry_msgs::Twist::ConstPtr &msg)
Write current command from geometry_msgs::Twist.
Definition: chassis_base.cpp:458
rm_chassis_controllers::ChassisBase::wheel_radius_
double wheel_radius_
Definition: chassis_base.h:180
rm_chassis_controllers::ChassisBase::odom_buffer_
realtime_tools::RealtimeBuffer< nav_msgs::Odometry > odom_buffer_
Definition: chassis_base.h:210
rm_chassis_controllers::ChassisBase::powerLimit
void powerLimit()
To limit the chassis power according to current power limit.
Definition: chassis_base.cpp:410
rm_chassis_controllers::ChassisBase::state_
int state_
Definition: chassis_base.h:193
ros::Duration
rm_chassis_controllers::ChassisBase::publish_rate_
double publish_rate_
Definition: chassis_base.h:180
ros::NodeHandle
ros::Subscriber
rm_chassis_controllers::ChassisBase::topic_update_
bool topic_update_
Definition: chassis_base.h:184
rm_chassis_controllers
Definition: balance.h:15
multi_interface_controller.h


rm_chassis_controllers
Author(s): Qiayuan Liao
autogenerated on Sun May 4 2025 02:57:17