rm_controllers
Loading...
Searching...
No Matches
bullet_solver.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 qiayuan on 8/14/20.
36//
37
38#pragma once
39
40#include <realtime_tools/realtime_publisher.h>
41#include <realtime_tools/realtime_buffer.h>
42#include <geometry_msgs/TransformStamped.h>
43#include <visualization_msgs/Marker.h>
44#include <rm_gimbal_controllers/BulletSolverConfig.h>
45#include <rm_msgs/BulletSolverData.h>
46#include <dynamic_reconfigure/server.h>
47#include <rm_common/hardware_interface/robot_state_interface.h>
48#include <rm_common/eigen_types.h>
49#include <rm_common/ros_utilities.h>
50#include <std_msgs/Bool.h>
51#include <std_msgs/Float64.h>
52#include <rm_msgs/TrackData.h>
53#include <rm_msgs/ShootBeforehandCmd.h>
54#include <rm_msgs/LocalHeatState.h>
55
57{
71{
72 double a0, a1, a2, a3;
73};
78
80{
81public:
82 explicit BulletSolver(ros::NodeHandle& controller_nh);
83
84 bool solve(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double bullet_speed, double yaw, double v_yaw,
85 double r1, double r2, double dz, int armors_num, double start_vel);
86 double getGimbalError(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double yaw, double v_yaw, double r1,
87 double r2, double dz, int armors_num, double yaw_real, double pitch_real, double bullet_speed);
88 double getResistanceCoefficient(double bullet_speed) const;
89 double getYaw() const
90 {
91 return output_yaw_;
92 }
93 double getPitch() const
94 {
95 return -output_pitch_;
96 }
97 double getTrajectYaw() const
98 {
99 return traject_output_yaw_;
100 }
101 bool getUsingtraject() const
102 {
103 return using_traject_;
104 }
105 int getShootnum() const
106 {
107 return shoot_num_;
108 }
109 double getTrajectEffortff() const
110 {
111 return traject_effort_ff_;
112 }
114 {
115 return track_target_;
116 }
117 double getGimbalSwitchDuration(double v_yaw);
118 void getSelectedArmorPosAndVel(geometry_msgs::Point& armor_pos, geometry_msgs::Vector3& armor_vel,
119 geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double yaw, double v_yaw,
120 double r1, double r2, double dz, int armors_num);
121 void judgeShootBeforehand(const ros::Time& time, double v_yaw);
122 void bulletModelPub(const geometry_msgs::TransformStamped& odom2pitch, const ros::Time& time);
123 void identifiedTargetChangeCB(const std_msgs::BoolConstPtr& msg);
124 void reconfigCB(rm_gimbal_controllers::BulletSolverConfig& config, uint32_t);
125 double planningPoint(ros::Time& time, ros::Time& start_trajectory_time_);
126 void heatCB(const rm_msgs::LocalHeatStateConstPtr& msg);
127 ~BulletSolver() = default;
128
129private:
130 std::shared_ptr<realtime_tools::RealtimePublisher<visualization_msgs::Marker>> path_desire_pub_;
131 std::shared_ptr<realtime_tools::RealtimePublisher<visualization_msgs::Marker>> path_real_pub_;
132 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::ShootBeforehandCmd>> shoot_beforehand_cmd_pub_;
133 std::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Float64>> fly_time_pub_;
134 std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::BulletSolverData>> bullet_solver_pub;
135 ros::Subscriber identified_target_change_sub_;
136 ros::Subscriber shoot_state_sub_;
137 ros::Time switch_armor_time_{};
138 realtime_tools::RealtimeBuffer<Config> config_rt_buffer_;
139 dynamic_reconfigure::Server<rm_gimbal_controllers::BulletSolverConfig>* d_srv_{};
140 Config config_{};
141 double max_track_target_vel_;
142 double output_yaw_{}, output_pitch_{}, traject_output_yaw_{};
143 double bullet_speed_{}, resistance_coff_{};
144 double fly_time_;
145 double switch_hysteresis_;
146 double last_yaw_{}, filtered_yaw_{};
147 double gimbal_switch_duration_{};
148 double yaw_subtract_;
149 double switch_armor_angle;
150 double filtered_v_yaw_{};
151 double switchtime;
152 double traject_effort_ff_;
153 double traject_switch_time_;
154 double switche_time_yaw_;
155 double traject_max_acc_;
156 int shoot_num_ = 0;
157 int shoot_beforehand_cmd_{};
158 int count_;
159 int traject_count_;
160 int ban_shoot_count_ = 0;
161 int selected_armor_ = 0;
162
163 bool track_target_ = true;
164 bool identified_target_change_ = true;
165 bool is_in_delay_before_switch_{};
166 bool dynamic_reconfig_initialized_{};
167 bool change_armor = false;
168 bool using_traject_;
169 bool last_shoot_state_;
170
171 geometry_msgs::Point after_traject_output_yaw_{};
172 geometry_msgs::Point target_pos_{};
173 visualization_msgs::Marker marker_desire_;
174 visualization_msgs::Marker marker_real_;
175 ros::Time start_using_traject_time;
176 ros::Time ban_shoot_time_;
177
178 TrajectoryFunctionCoefficients trajectory_function_coefficients;
179 TrajectoryLimitParams stauts_limit_;
180
181 mutable std::mutex heat_mutex_;
182};
183} // namespace rm_gimbal_controllers
Definition bullet_solver.h:80
double getGimbalSwitchDuration(double v_yaw)
Definition bullet_solver.cpp:574
BulletSolver(ros::NodeHandle &controller_nh)
Definition bullet_solver.cpp:46
void getSelectedArmorPosAndVel(geometry_msgs::Point &armor_pos, geometry_msgs::Vector3 &armor_vel, geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double yaw, double v_yaw, double r1, double r2, double dz, int armors_num)
Definition bullet_solver.cpp:431
double planningPoint(ros::Time &time, ros::Time &start_trajectory_time_)
Definition bullet_solver.cpp:609
void reconfigCB(rm_gimbal_controllers::BulletSolverConfig &config, uint32_t)
Definition bullet_solver.cpp:636
double getTrajectEffortff() const
Definition bullet_solver.h:109
void heatCB(const rm_msgs::LocalHeatStateConstPtr &msg)
Definition bullet_solver.cpp:622
double getGimbalError(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double yaw, double v_yaw, double r1, double r2, double dz, int armors_num, double yaw_real, double pitch_real, double bullet_speed)
Definition bullet_solver.cpp:515
bool getTrackTarget()
Definition bullet_solver.h:113
double getPitch() const
Definition bullet_solver.h:93
bool solve(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double bullet_speed, double yaw, double v_yaw, double r1, double r2, double dz, int armors_num, double start_vel)
Definition bullet_solver.cpp:127
double getYaw() const
Definition bullet_solver.h:89
void bulletModelPub(const geometry_msgs::TransformStamped &odom2pitch, const ros::Time &time)
Definition bullet_solver.cpp:466
void judgeShootBeforehand(const ros::Time &time, double v_yaw)
Definition bullet_solver.cpp:582
double getTrajectYaw() const
Definition bullet_solver.h:97
bool getUsingtraject() const
Definition bullet_solver.h:101
int getShootnum() const
Definition bullet_solver.h:105
double getResistanceCoefficient(double bullet_speed) const
Definition bullet_solver.cpp:110
void identifiedTargetChangeCB(const std_msgs::BoolConstPtr &msg)
Definition bullet_solver.cpp:563
Definition ballistic_solver.h:22
Definition bullet_solver.h:59
int min_fit_switch_count
Definition bullet_solver.h:64
double max_switch_angle
Definition bullet_solver.h:61
double center_delay
Definition bullet_solver.h:61
double min_shoot_beforehand_vel
Definition bullet_solver.h:62
double traject_ahead_
Definition bullet_solver.h:66
double resistance_coff_qd_15
Definition bullet_solver.h:60
double track_rotate_target_delay
Definition bullet_solver.h:62
double track_move_target_delay
Definition bullet_solver.h:63
double switch_duration_scale
Definition bullet_solver.h:61
double end_pos_offset
Definition bullet_solver.h:68
double delay
Definition bullet_solver.h:61
double g
Definition bullet_solver.h:61
double switch_angle_offset
Definition bullet_solver.h:61
double resistance_coff_qd_10
Definition bullet_solver.h:60
int max_selected_armor_
Definition bullet_solver.h:65
double switch_duration_offset
Definition bullet_solver.h:62
double switch_duration_rate
Definition bullet_solver.h:62
double resistance_coff_qd_30
Definition bullet_solver.h:61
double resistance_coff_qd_16
Definition bullet_solver.h:60
int clean_shoot_num_
Definition bullet_solver.h:67
double resistance_coff_qd_18
Definition bullet_solver.h:60
double a1
Definition bullet_solver.h:72
double a2
Definition bullet_solver.h:72
double a3
Definition bullet_solver.h:72
double a0
Definition bullet_solver.h:72
double end_vel
Definition bullet_solver.h:76
double start_vel
Definition bullet_solver.h:76
double start_pos
Definition bullet_solver.h:76
double end_pos
Definition bullet_solver.h:76