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