rm_controllers
Loading...
Searching...
No Matches
standard.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/1/18.
36//
37
38#pragma once
39
40#include <effort_controllers/joint_velocity_controller.h>
41#include <effort_controllers/joint_position_controller.h>
42#include <velocity_controllers/joint_velocity_controller.h>
43#include <controller_interface/multi_interface_controller.h>
44#include <hardware_interface/joint_command_interface.h>
45#include <rm_common/hardware_interface/robot_state_interface.h>
46#include <rm_common/ros_utilities.h>
47#include <rm_common/filters/filters.h>
48#include <rm_common/filters/lp_filter.h>
49#include <realtime_tools/realtime_publisher.h>
50#include <dynamic_reconfigure/server.h>
51#include <rm_dshot_shooter_controllers/ShooterConfig.h>
52#include <rm_msgs/ShootCmd.h>
53#include <rm_msgs/ShootState.h>
54#include <rm_msgs/LocalHeatState.h>
55#include <control_toolbox/pid.h>
56
57#include <utility>
58
60{
67
68class Controller : public controller_interface::MultiInterfaceController<hardware_interface::EffortJointInterface,
69 hardware_interface::VelocityJointInterface,
70 rm_control::RobotStateInterface>
71{
72public:
73 Controller() = default;
74 bool init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh) override;
75 void update(const ros::Time& time, const ros::Duration& period) override;
76 void starting(const ros::Time& /*time*/) override;
77
78private:
79 void stop(const ros::Time& time, const ros::Duration& period);
80 void ready(const ros::Duration& period);
81 void push(const ros::Time& time, const ros::Duration& period);
82 void block(const ros::Time& time, const ros::Duration& period);
83 void setSpeed(const rm_msgs::ShootCmd& cmd, const ros::Duration& period);
84 void normalize();
85 void judgeBulletShoot(const ros::Time& time, const ros::Duration& period);
86 void commandCB(const rm_msgs::ShootCmdConstPtr& msg)
87 {
88 cmd_rt_buffer_.writeFromNonRT(*msg);
89 }
90
91 void reconfigCB(rm_dshot_shooter_controllers::ShooterConfig& config, uint32_t /*level*/);
92
93 hardware_interface::EffortJointInterface* effort_joint_interface_{};
94 hardware_interface::VelocityJointInterface* velocity_joint_interface_{};
95 std::vector<std::vector<velocity_controllers::JointVelocityController*>> ctrls_friction_;
96 std::vector<std::vector<std::shared_ptr<control_toolbox::Pid>>> friction_pid_controllers_;
97 effort_controllers::JointPositionController ctrl_trigger_;
98 LowPassFilter* lp_filter_;
99 RampFilter<double>* wheel_speed_ramp_filter_{};
100 int push_per_rotation_{}, count_{};
101 double push_wheel_speed_threshold_{};
102 double freq_threshold_{};
103 bool dynamic_reconfig_initialized_ = false;
104 bool state_changed_ = false;
105 bool enter_ready_ = false;
106 bool maybe_block_ = false;
107 int friction_block_count = 0;
108 bool last_friction_wheel_block = false, friction_wheel_block = false;
109 double friction_block_vel_{};
110 double anti_friction_block_duty_cycle_{}, anti_friction_block_vel_{};
111 bool has_shoot_ = false, has_shoot_last_ = false;
112 bool wheel_speed_drop_ = true;
113 double last_fricition_speed_{};
114 double last_friction_change_speed_{};
115
116 ros::Time last_shoot_time_, block_time_, last_block_time_;
117 enum
118 {
119 STOP,
120 READY,
121 PUSH,
122 BLOCK
123 };
124 int state_ = STOP;
125 Config config_{};
126 realtime_tools::RealtimeBuffer<Config> config_rt_buffer;
127 realtime_tools::RealtimeBuffer<rm_msgs::ShootCmd> cmd_rt_buffer_;
128 rm_msgs::ShootCmd cmd_;
129 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::LocalHeatState>> local_heat_state_pub_;
130 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::ShootState>> shoot_state_pub_;
131 std::vector<std::vector<std::unique_ptr<realtime_tools::RealtimePublisher<control_msgs::JointControllerState>>>>
132 friction_state_publishers_;
133 int loop_count_ = 0;
134 ros::Subscriber cmd_subscriber_;
135 dynamic_reconfigure::Server<rm_dshot_shooter_controllers::ShooterConfig>* d_srv_{};
136};
137
138} // namespace rm_dshot_shooter_controllers
bool init(hardware_interface::RobotHW *robot_hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh) override
Definition standard.cpp:47
void update(const ros::Time &time, const ros::Duration &period) override
Definition standard.cpp:134
void starting(const ros::Time &) override
Definition standard.cpp:127
Definition standard.h:60
Definition standard.h:62
double extra_wheel_speed
Definition standard.h:65
double forward_push_threshold
Definition standard.h:64
double wheel_speed_raise_threshold
Definition standard.h:65
double block_effort
Definition standard.h:63
double block_duration
Definition standard.h:63
double anti_block_threshold
Definition standard.h:63
double anti_block_angle
Definition standard.h:63
double block_overtime
Definition standard.h:63
double block_speed
Definition standard.h:63
double exit_push_threshold
Definition standard.h:64
double wheel_speed_drop_threshold
Definition standard.h:65