sentry.cpp
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 flying on 2021/1/18.
36 //
39 #include <string>
41 
42 namespace rm_chassis_controllers
43 {
45  ros::NodeHandle& controller_nh)
46 {
47  ChassisBase::init(robot_hw, root_nh, controller_nh);
48  ros::NodeHandle nh_wheel = ros::NodeHandle(controller_nh, "wheel");
49  ros::NodeHandle nh_brake = ros::NodeHandle(controller_nh, "catapult");
50  if (!nh_brake.getParam("catapult_angle", catapult_angle_) || !nh_brake.getParam("velocity_coefficient", vel_coff_) ||
51  !nh_brake.getParam("lock_duration", lock_duratoin_))
52  {
53  ROS_ERROR("Could not find parameters: catapult_angle, velocity_coefficient or lock_duration");
54  }
55  if (!ctrl_wheel_.init(effort_joint_interface_, nh_wheel) ||
57  return false;
58  if_catapult_ = false;
61  return true;
62 }
63 
64 void SentryController::moveJoint(const ros::Time& time, const ros::Duration& period)
65 {
68  ctrl_wheel_.update(time, period);
69  ctrl_catapult_joint_.update(time, period);
70 
71  if (last_vel_cmd_ * cmd_rt_buffer_.readFromRT()->cmd_vel_.linear.x < 0)
72  {
73  if_catapult_ = true;
74  ROS_INFO("[sentryChassis] Enter CATAPULT");
75  }
76  last_vel_cmd_ = cmd_rt_buffer_.readFromRT()->cmd_vel_.linear.x;
77  if (if_catapult_ == false)
78  {
79  normal(time, period);
80  lock_time_ = time;
81  }
82  else
83  {
84  catapult(time, period);
85  }
86 }
87 
88 void SentryController::catapult(const ros::Time& time, const ros::Duration& period)
89 {
92  ctrl_wheel_.update(time, period);
93  ctrl_catapult_joint_.update(time, period);
96  {
97  if_catapult_ = false;
98  ROS_INFO("[sentryChassis] Enter NORMAL");
99  }
100  if ((time - lock_time_).toSec() > lock_duratoin_)
101  {
103  if_catapult_ = false;
104  ROS_INFO("[sentryChassis] Exit CATAPULT");
105  }
106 }
107 
108 geometry_msgs::Twist SentryController::odometry()
109 {
110  geometry_msgs::Twist vel_data;
111  vel_data.linear.x = ctrl_wheel_.joint_.getVelocity() * wheel_radius_;
112  return vel_data;
113 }
114 
115 void SentryController::normal(const ros::Time& time, const ros::Duration& period)
116 {
118 }
119 
120 } // namespace rm_chassis_controllers
121 
rm_chassis_controllers::SentryController::last_vel_cmd_
double last_vel_cmd_
Definition: sentry.h:145
rm_chassis_controllers::SentryController::catapult_angle_
double catapult_angle_
Definition: sentry.h:143
effort_controllers::JointVelocityController::update
void update(const ros::Time &time, const ros::Duration &period)
HardwareResourceManager< JointHandle, ClaimResources >::getHandle
JointHandle getHandle(const std::string &name)
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
rm_chassis_controllers::ChassisBase< rm_control::RobotStateInterface, hardware_interface::EffortJointInterface >::vel_cmd_
geometry_msgs::Vector3 vel_cmd_
Definition: chassis_base.h:200
effort_controllers::JointPositionController::init
bool init(hardware_interface::EffortJointInterface *robot, ros::NodeHandle &n)
sentry.h
effort_controllers::JointVelocityController::getJointName
std::string getJointName()
rm_chassis_controllers::ChassisBase< rm_control::RobotStateInterface, hardware_interface::EffortJointInterface >::effort_joint_interface_
hardware_interface::EffortJointInterface * effort_joint_interface_
Definition: chassis_base.h:177
rm_chassis_controllers::SentryController::lock_time_
ros::Time lock_time_
Definition: sentry.h:146
hardware_interface::JointHandle::setCommand
void setCommand(double command)
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(RobotLocalization::EkfNodelet, nodelet::Nodelet)
controller_interface::ControllerBase
rm_chassis_controllers::SentryController::catapult
void catapult(const ros::Time &time, const ros::Duration &period)
Definition: sentry.cpp:119
rm_chassis_controllers::SentryController::ctrl_wheel_
effort_controllers::JointVelocityController ctrl_wheel_
Definition: sentry.h:138
hardware_interface::RobotHW
effort_controllers::JointPositionController::update
void update(const ros::Time &time, const ros::Duration &period)
rm_chassis_controllers::SentryController::init
bool init(hardware_interface::RobotHW *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override
Execute ChassisBase::init. Init necessary handles.
Definition: sentry.cpp:75
effort_controllers::JointVelocityController::setCommand
void setCommand(double cmd)
effort_controllers::JointPositionController::setCommand
void setCommand(double pos_target)
rm_chassis_controllers::SentryController::ctrl_catapult_joint_
effort_controllers::JointPositionController ctrl_catapult_joint_
Definition: sentry.h:139
effort_controllers::JointVelocityController::init
bool init(hardware_interface::EffortJointInterface *robot, const std::string &joint_name, const control_toolbox::Pid &pid)
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
effort_controllers::JointPositionController::getJointName
std::string getJointName()
rm_chassis_controllers::ChassisBase< rm_control::RobotStateInterface, hardware_interface::EffortJointInterface >::cmd_rt_buffer_
realtime_tools::RealtimeBuffer< Command > cmd_rt_buffer_
Definition: chassis_base.h:209
hardware_interface::JointStateHandle::getVelocity
double getVelocity() const
ros::Time
rm_chassis_controllers::SentryController::odometry
geometry_msgs::Twist odometry() override
Calculate current linear_x according to current velocity.
Definition: sentry.cpp:139
rm_chassis_controllers::ChassisBase< rm_control::RobotStateInterface, hardware_interface::EffortJointInterface >::joint_handles_
std::vector< hardware_interface::JointHandle > joint_handles_
Definition: chassis_base.h:178
rm_chassis_controllers::SentryController::vel_coff_
double vel_coff_
Definition: sentry.h:144
rm_chassis_controllers::SentryController::if_catapult_
bool if_catapult_
Definition: sentry.h:141
ROS_ERROR
#define ROS_ERROR(...)
class_list_macros.hpp
ros_utilities.h
rm_chassis_controllers::ChassisBase< rm_control::RobotStateInterface, hardware_interface::EffortJointInterface >::wheel_radius_
double wheel_radius_
Definition: chassis_base.h:180
ROS_INFO
#define ROS_INFO(...)
rm_chassis_controllers::SentryController::normal
void normal(const ros::Time &time, const ros::Duration &period)
Definition: sentry.cpp:146
ros::Duration
rm_chassis_controllers::SentryController
Definition: sentry.h:76
rm_chassis_controllers::SentryController::lock_duratoin_
double lock_duratoin_
Definition: sentry.h:147
rm_chassis_controllers::SentryController::moveJoint
void moveJoint(const ros::Time &time, const ros::Duration &period) override
Calculate correct command and set it to wheel.
Definition: sentry.cpp:95
rm_chassis_controllers::SentryController::catapult_initial_velocity_
double catapult_initial_velocity_
Definition: sentry.h:142
effort_controllers::JointVelocityController::joint_
hardware_interface::JointHandle joint_
ros::NodeHandle
rm_chassis_controllers
Definition: balance.h:15


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