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 
42 #include <geometry_msgs/TransformStamped.h>
43 #include <visualization_msgs/Marker.h>
44 #include <rm_gimbal_controllers/BulletSolverConfig.h>
45 #include <dynamic_reconfigure/server.h>
47 #include <rm_common/eigen_types.h>
49 #include <std_msgs/Bool.h>
50 #include <std_msgs/Float64.h>
51 #include <rm_msgs/TrackData.h>
52 #include <rm_msgs/ShootBeforehandCmd.h>
53 
55 {
56 struct Config
57 {
63 };
64 
65 class BulletSolver
66 {
67 public:
68  explicit BulletSolver(ros::NodeHandle& controller_nh);
69 
70  bool solve(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double bullet_speed, double yaw, double v_yaw,
71  double r1, double r2, double dz, int armors_num, double chassis_angular_vel_z);
72  double getGimbalError(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double yaw, double v_yaw, double r1,
73  double r2, double dz, int armors_num, double yaw_real, double pitch_real, double bullet_speed);
74  double getResistanceCoefficient(double bullet_speed) const;
75  double getYaw() const
76  {
77  return output_yaw_;
78  }
79  double getPitch() const
80  {
81  return -output_pitch_;
82  }
83  void getSelectedArmorPosAndVel(geometry_msgs::Point& armor_pos, geometry_msgs::Vector3& armor_vel,
84  geometry_msgs::Point pos, geometry_msgs::Vector3 vel, double yaw, double v_yaw,
85  double r1, double r2, double dz, int armors_num);
86  void judgeShootBeforehand(const ros::Time& time, double v_yaw);
87  void bulletModelPub(const geometry_msgs::TransformStamped& odom2pitch, const ros::Time& time);
88  void identifiedTargetChangeCB(const std_msgs::BoolConstPtr& msg);
89  void reconfigCB(rm_gimbal_controllers::BulletSolverConfig& config, uint32_t);
90  ~BulletSolver() = default;
91 
92 private:
93  std::shared_ptr<realtime_tools::RealtimePublisher<visualization_msgs::Marker>> path_desire_pub_;
94  std::shared_ptr<realtime_tools::RealtimePublisher<visualization_msgs::Marker>> path_real_pub_;
95  std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::ShootBeforehandCmd>> shoot_beforehand_cmd_pub_;
96  std::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Float64>> fly_time_pub_;
100  dynamic_reconfigure::Server<rm_gimbal_controllers::BulletSolverConfig>* d_srv_{};
101  Config config_{};
102  double max_track_target_vel_;
103  double output_yaw_{}, output_pitch_{};
104  double bullet_speed_{}, resistance_coff_{};
105  double fly_time_;
107  int shoot_beforehand_cmd_{};
108  int selected_armor_;
109  int count_;
110  bool track_target_ = true;
111  bool identified_target_change_ = true;
114 
115  geometry_msgs::Point target_pos_{};
116  visualization_msgs::Marker marker_desire_;
117  visualization_msgs::Marker marker_real_;
118 };
119 } // namespace rm_gimbal_controllers
realtime_tools::RealtimeBuffer
rm_gimbal_controllers::Config::wait_next_armor_delay
double wait_next_armor_delay
Definition: bullet_solver.h:121
realtime_publisher.h
rm_gimbal_controllers::BulletSolver::output_pitch_
double output_pitch_
Definition: bullet_solver.h:134
rm_gimbal_controllers::BulletSolver::shoot_beforehand_cmd_pub_
std::shared_ptr< realtime_tools::RealtimePublisher< rm_msgs::ShootBeforehandCmd > > shoot_beforehand_cmd_pub_
Definition: bullet_solver.h:126
rm_gimbal_controllers::BulletSolver::count_
int count_
Definition: bullet_solver.h:140
rm_gimbal_controllers::Config::resistance_coff_qd_16
double resistance_coff_qd_16
Definition: bullet_solver.h:120
rm_gimbal_controllers::Config::min_fit_switch_count
int min_fit_switch_count
Definition: bullet_solver.h:124
rm_gimbal_controllers::Config::ban_shoot_duration
double ban_shoot_duration
Definition: bullet_solver.h:122
rm_gimbal_controllers::BulletSolver::shoot_beforehand_cmd_
int shoot_beforehand_cmd_
Definition: bullet_solver.h:138
rm_gimbal_controllers::BulletSolver::fly_time_pub_
std::shared_ptr< realtime_tools::RealtimePublisher< std_msgs::Float64 > > fly_time_pub_
Definition: bullet_solver.h:127
rm_gimbal_controllers::BulletSolver::switch_armor_time_
ros::Time switch_armor_time_
Definition: bullet_solver.h:129
rm_gimbal_controllers::BulletSolver::fly_time_
double fly_time_
Definition: bullet_solver.h:136
realtime_buffer.h
rm_gimbal_controllers::BulletSolver::selected_armor_
int selected_armor_
Definition: bullet_solver.h:139
rm_gimbal_controllers::BulletSolver::output_yaw_
double output_yaw_
Definition: bullet_solver.h:134
rm_gimbal_controllers::BulletSolver::marker_desire_
visualization_msgs::Marker marker_desire_
Definition: bullet_solver.h:147
rm_gimbal_controllers::BulletSolver::target_pos_
geometry_msgs::Point target_pos_
Definition: bullet_solver.h:146
rm_gimbal_controllers::BulletSolver::marker_real_
visualization_msgs::Marker marker_real_
Definition: bullet_solver.h:148
rm_gimbal_controllers::BulletSolver::switch_hysteresis_
double switch_hysteresis_
Definition: bullet_solver.h:137
rm_gimbal_controllers::Config::resistance_coff_qd_18
double resistance_coff_qd_18
Definition: bullet_solver.h:120
rm_gimbal_controllers::BulletSolver::bulletModelPub
void bulletModelPub(const geometry_msgs::TransformStamped &odom2pitch, const ros::Time &time)
Definition: bullet_solver.cpp:315
rm_gimbal_controllers::Config::gimbal_switch_duration
double gimbal_switch_duration
Definition: bullet_solver.h:122
rm_gimbal_controllers::BulletSolver::getGimbalError
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:364
rm_gimbal_controllers::BulletSolver::BulletSolver
BulletSolver(ros::NodeHandle &controller_nh)
Definition: bullet_solver.cpp:76
rm_gimbal_controllers::BulletSolver::config_
Config config_
Definition: bullet_solver.h:132
rm_gimbal_controllers::BulletSolver
Definition: bullet_solver.h:96
rm_gimbal_controllers::Config::resistance_coff_qd_15
double resistance_coff_qd_15
Definition: bullet_solver.h:120
rm_gimbal_controllers::Config::dt
double dt
Definition: bullet_solver.h:121
rm_gimbal_controllers::BulletSolver::identified_target_change_
bool identified_target_change_
Definition: bullet_solver.h:142
rm_gimbal_controllers::Config::wait_diagonal_armor_delay
double wait_diagonal_armor_delay
Definition: bullet_solver.h:121
rm_gimbal_controllers::BulletSolver::identified_target_change_sub_
ros::Subscriber identified_target_change_sub_
Definition: bullet_solver.h:128
rm_gimbal_controllers::BulletSolver::config_rt_buffer_
realtime_tools::RealtimeBuffer< Config > config_rt_buffer_
Definition: bullet_solver.h:130
rm_gimbal_controllers::BulletSolver::identifiedTargetChangeCB
void identifiedTargetChangeCB(const std_msgs::BoolConstPtr &msg)
Definition: bullet_solver.cpp:414
rm_gimbal_controllers::BulletSolver::bullet_speed_
double bullet_speed_
Definition: bullet_solver.h:135
rm_gimbal_controllers::Config::resistance_coff_qd_30
double resistance_coff_qd_30
Definition: bullet_solver.h:121
rm_gimbal_controllers::Config::delay
double delay
Definition: bullet_solver.h:121
rm_gimbal_controllers::BulletSolver::path_desire_pub_
std::shared_ptr< realtime_tools::RealtimePublisher< visualization_msgs::Marker > > path_desire_pub_
Definition: bullet_solver.h:124
rm_gimbal_controllers
Definition: bullet_solver.h:54
rm_gimbal_controllers::BulletSolver::getResistanceCoefficient
double getResistanceCoefficient(double bullet_speed) const
Definition: bullet_solver.cpp:134
rm_gimbal_controllers::BulletSolver::judgeShootBeforehand
void judgeShootBeforehand(const ros::Time &time, double v_yaw)
Definition: bullet_solver.cpp:420
rm_gimbal_controllers::BulletSolver::getPitch
double getPitch() const
Definition: bullet_solver.h:110
rm_gimbal_controllers::BulletSolver::dynamic_reconfig_initialized_
bool dynamic_reconfig_initialized_
Definition: bullet_solver.h:144
robot_state_interface.h
rm_gimbal_controllers::BulletSolver::max_track_target_vel_
double max_track_target_vel_
Definition: bullet_solver.h:133
ros::Time
rm_gimbal_controllers::Config
Definition: bullet_solver.h:87
eigen_types.h
rm_gimbal_controllers::BulletSolver::resistance_coff_
double resistance_coff_
Definition: bullet_solver.h:135
rm_gimbal_controllers::BulletSolver::getSelectedArmorPosAndVel
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:288
rm_gimbal_controllers::Config::track_move_target_delay
double track_move_target_delay
Definition: bullet_solver.h:123
rm_gimbal_controllers::BulletSolver::path_real_pub_
std::shared_ptr< realtime_tools::RealtimePublisher< visualization_msgs::Marker > > path_real_pub_
Definition: bullet_solver.h:125
rm_gimbal_controllers::Config::timeout
double timeout
Definition: bullet_solver.h:121
ros_utilities.h
rm_gimbal_controllers::BulletSolver::solve
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 chassis_angular_vel_z)
Definition: bullet_solver.cpp:151
rm_gimbal_controllers::BulletSolver::track_target_
bool track_target_
Definition: bullet_solver.h:141
rm_gimbal_controllers::Config::min_shoot_beforehand_vel
double min_shoot_beforehand_vel
Definition: bullet_solver.h:122
rm_gimbal_controllers::BulletSolver::reconfigCB
void reconfigCB(rm_gimbal_controllers::BulletSolverConfig &config, uint32_t)
Definition: bullet_solver.cpp:441
rm_gimbal_controllers::Config::max_chassis_angular_vel
double max_chassis_angular_vel
Definition: bullet_solver.h:123
rm_gimbal_controllers::Config::resistance_coff_qd_10
double resistance_coff_qd_10
Definition: bullet_solver.h:120
rm_gimbal_controllers::Config::track_rotate_target_delay
double track_rotate_target_delay
Definition: bullet_solver.h:123
rm_gimbal_controllers::BulletSolver::is_in_delay_before_switch_
bool is_in_delay_before_switch_
Definition: bullet_solver.h:143
rm_gimbal_controllers::Config::g
double g
Definition: bullet_solver.h:121
rm_gimbal_controllers::Config::max_switch_angle
double max_switch_angle
Definition: bullet_solver.h:122
rm_gimbal_controllers::BulletSolver::getYaw
double getYaw() const
Definition: bullet_solver.h:106
ros::NodeHandle
ros::Subscriber
rm_gimbal_controllers::BulletSolver::~BulletSolver
~BulletSolver()=default
rm_gimbal_controllers::BulletSolver::d_srv_
dynamic_reconfigure::Server< rm_gimbal_controllers::BulletSolverConfig > * d_srv_
Definition: bullet_solver.h:131
rm_gimbal_controllers::Config::min_switch_angle
double min_switch_angle
Definition: bullet_solver.h:122


rm_gimbal_controllers
Author(s): Qiayuan Liao
autogenerated on Sun May 4 2025 02:57:21