Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gimbal cascade pid and modify bullet_solver #162

Merged
merged 53 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9927d0d
Add chassis vel feedforward for yaw.
1moule Apr 2, 2024
adc60be
Use lp filter to estimate chassis angular velocity.
liyixin135 Apr 3, 2024
1880ed7
Finish the target position and compensation of yaw.
liyixin135 Apr 3, 2024
8700331
Add flag by subscribing vision target changed.
liyixin135 Apr 4, 2024
00ecfab
Control fire near switching target.
liyixin135 Apr 4, 2024
d5ee264
Modify switch limit.
liyixin135 Apr 4, 2024
105f1b9
Modify switch angle.
liyixin135 Apr 4, 2024
d41e046
Modify something wrong.
liyixin135 Apr 4, 2024
53f4a43
Add mode for suggest fire.
liyixin135 Apr 4, 2024
907918f
Add suggest_fire near switching armor.
liyixin135 Apr 4, 2024
b1e8201
Add dynamic reconfig.
liyixin135 Apr 4, 2024
c675052
Add angles' dynamic reconfig.
liyixin135 Apr 4, 2024
da4a085
Modify something wrong.
liyixin135 Apr 4, 2024
14f4467
Add dynamic reconfig.
liyixin135 Apr 4, 2024
99b4063
Modify something wrong.
liyixin135 Apr 4, 2024
47b6162
Modify something wrong.
liyixin135 Apr 4, 2024
e48f42e
Add delay.
liyixin135 Apr 4, 2024
de6d6d7
Delete switching armor target when in low v_yaw.
liyixin135 Apr 4, 2024
5beff48
Delete delay for moving.
liyixin135 Apr 4, 2024
d7c2306
Delete pitch feedforward.
liyixin135 Apr 6, 2024
b22a806
Merge pull request #3 from liyixin135/my_test_dev
1moule Apr 11, 2024
f7a8fe5
Delete friction feedforward.
1moule Apr 12, 2024
4088582
Modify namespace.
1moule Apr 12, 2024
889ffec
Modify some variable and function names.
1moule Apr 12, 2024
ccbf157
Modify variable name.
1moule Apr 12, 2024
5eb12e1
Modify expression of shoot beforehand cmd.
1moule Apr 12, 2024
96cb624
Modify variable name.
1moule Apr 12, 2024
393241c
Publish fly time.
1moule Apr 12, 2024
440aa04
Modify description of variable in cfg.
1moule Apr 12, 2024
34e03f5
Only use target vel for feedforward and enable gravity feedforward on…
1moule Apr 12, 2024
c20dfec
Thinking the situation of tracking center.
liyixin135 Apr 16, 2024
27ed0d9
Add delay2 used to estimate current armor's position when moving.
liyixin135 Apr 16, 2024
5f77ef5
Merge branch 'master' into final-gimbal
liyixin135 Apr 23, 2024
6c6c251
Make sure switch angle when facing different v_yaw's target.
liyixin135 Apr 23, 2024
efb566f
Add GimbalBase.cfg in cmakelist.
liyixin135 Apr 23, 2024
56e9831
Add ramp filter for rate_yaw and rate_pitch.
liyixin135 Apr 27, 2024
a4cdb99
Add count to judge whether switch target.
liyixin135 Apr 27, 2024
b2acbf1
Modify param name.
liyixin135 Apr 27, 2024
45ddcc4
Modify param name.
liyixin135 Apr 27, 2024
53b86d3
Delete lp filter which used to estimate chassis angular vel.
liyixin135 Apr 28, 2024
f2c7935
Add param to dynamic reconfigure.
liyixin135 Apr 28, 2024
700e6ec
Use base_link2pitch to calculate gravity compensation.
liyixin135 Apr 28, 2024
94488c8
Modify topic's name.
liyixin135 Apr 29, 2024
03f03a0
Delete something unused.
liyixin135 May 3, 2024
2e259a3
Used for vision's topic which is called change.
liyixin135 May 5, 2024
caa9190
Delete something unused.
liyixin135 May 5, 2024
ae0ff13
Update cfg.
liyixin135 May 6, 2024
e0503cf
Delete something unused and modify param name.
liyixin135 May 6, 2024
28bbefa
Add some param and modify param name.
liyixin135 May 6, 2024
05eb17a
Modify param name,delete something unused and add chassis vel into so…
liyixin135 May 6, 2024
e9dad34
Modify param name,add delay when rotation and moving,and think about …
liyixin135 May 6, 2024
2fa2b16
Modify cfg's description.
liyixin135 May 8, 2024
7364ccc
Add cfg and modify param name.
liyixin135 May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions rm_gimbal_controllers/cfg/BulletSolver.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ gen.add("g", double_t, 0, "Air resistance divided by mass", 9.8, 9.6, 10.0)
gen.add("delay", double_t, 0, "Delay of bullet firing", 0.0, 0, 0.5)
gen.add("dt", double_t, 0, "Iteration interval", 0.01, 0.0001, 0.1)
gen.add("timeout", double_t, 0, "Flight time exceeded", 2.0, 0.5, 3.0)
gen.add("ban_shoot_duration", double_t, 0, "Ban shoot duration while beforehand shooting", 0.0, 0.0, 2.0)
gen.add("gimbal_switch_duration", double_t, 0, "Gimbal switch duration", 0.0, 0.0, 2.0)
gen.add("angle1", double_t, 0, "Switch angle1", 40.0, 0.0, 90.0)
gen.add("angle2", double_t, 0, "Switch angle2", 2.0, 0.0, 90.0)
liyixin135 marked this conversation as resolved.
Show resolved Hide resolved

exit(gen.generate(PACKAGE, "bullet_solver", "BulletSolver"))
7 changes: 5 additions & 2 deletions rm_gimbal_controllers/cfg/GimbalBase.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ from dynamic_reconfigure.parameter_generator_catkin import *

gen = ParameterGenerator()

gen.add("yaw_k_v_", double_t, 0, "Pid pitch position max output", 0.0, 0, 1.0)
gen.add("pitch_k_v_", double_t, 0, "Pid pitch position max output", 0.0, 0, 1.0)
gen.add("yaw_k_v_", double_t, 0, "Yaw input feedforward scale", 0.0, 0, 1.0)
gen.add("pitch_k_v_", double_t, 0, "Pitch input feedforward scale", 0.0, 0, 1.0)
gen.add("k_chassis_vel_", double_t, 0, "Yaw chassis velocity feedforward scale", 0.0, 0, 1.0)
gen.add("delay", double_t, 0, "Delay used to estimate current armor's yaw", 0.0, -1.0, 1.0)
gen.add("delay2", double_t, 0, "Delay2 used to estimate current armor's position when moving", 0.0, -1.0, 1.0)

exit(gen.generate(PACKAGE, "gimbal_base", "GimbalBase"))
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@
#include <rm_common/hardware_interface/robot_state_interface.h>
#include <rm_common/eigen_types.h>
#include <rm_common/ros_utilities.h>
#include <std_msgs/Bool.h>
liyixin135 marked this conversation as resolved.
Show resolved Hide resolved
#include <std_msgs/Float64.h>
#include <rm_msgs/TrackData.h>
#include <rm_msgs/ShootBeforehandCmd.h>

namespace rm_gimbal_controllers
{
struct Config
{
double resistance_coff_qd_10, resistance_coff_qd_15, resistance_coff_qd_16, resistance_coff_qd_18,
resistance_coff_qd_30, g, delay, dt, timeout;
resistance_coff_qd_30, g, delay, dt, timeout, ban_shoot_duration, gimbal_switch_duration, angle1, angle2;
};

class BulletSolver
Expand All @@ -76,22 +80,31 @@ class BulletSolver
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);
void judgeShootBeforehand(const ros::Time& time);
void bulletModelPub(const geometry_msgs::TransformStamped& odom2pitch, const ros::Time& time);
void identifiedTargetChangeCB(const std_msgs::BoolConstPtr& msg);
void reconfigCB(rm_gimbal_controllers::BulletSolverConfig& config, uint32_t);
~BulletSolver() = default;

private:
std::shared_ptr<realtime_tools::RealtimePublisher<visualization_msgs::Marker>> path_desire_pub_;
std::shared_ptr<realtime_tools::RealtimePublisher<visualization_msgs::Marker>> path_real_pub_;
std::shared_ptr<realtime_tools::RealtimePublisher<rm_msgs::ShootBeforehandCmd>> shoot_beforehand_cmd_pub_;
std::shared_ptr<realtime_tools::RealtimePublisher<std_msgs::Float64>> fly_time_pub_;
ros::Subscriber identified_target_change_sub_;
ros::Time switch_armor_time_{};
realtime_tools::RealtimeBuffer<Config> config_rt_buffer_;
dynamic_reconfigure::Server<rm_gimbal_controllers::BulletSolverConfig>* d_srv_{};
Config config_{};
double max_track_target_vel_;
bool dynamic_reconfig_initialized_{};
double output_yaw_{}, output_pitch_{};
double bullet_speed_{}, resistance_coff_{};
int shoot_beforehand_cmd_{};
int selected_armor_;
bool track_target_;
bool identified_target_change_ = true;
bool is_in_delay_before_switch_{};
bool dynamic_reconfig_initialized_{};

geometry_msgs::Point target_pos_{};
double fly_time_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@
#include <urdf/model.h>
#include <dynamic_reconfigure/server.h>
#include <realtime_tools/realtime_publisher.h>
#include <rm_common/filters/lp_filter.h>

namespace rm_gimbal_controllers
{
struct GimbalConfig
{
// Input feedforward
double yaw_k_v_, pitch_k_v_;
// feedforward
double yaw_k_v_, pitch_k_v_, k_chassis_vel_;
double delay, delay2;
};

class ChassisVel
Expand All @@ -74,6 +76,8 @@ class ChassisVel
nh.param("debug", is_debug_, true);
linear_ = std::make_shared<Vector3WithFilter<double>>(num_data);
angular_ = std::make_shared<Vector3WithFilter<double>>(num_data);
ros::NodeHandle nh_lp = ros::NodeHandle(nh, "lp");
angular_lp_filter_ = std::make_unique<LowPassFilter>(nh_lp);
if (is_debug_)
{
real_pub_.reset(new realtime_tools::RealtimePublisher<geometry_msgs::Twist>(nh, "real", 1));
Expand All @@ -82,6 +86,7 @@ class ChassisVel
}
std::shared_ptr<Vector3WithFilter<double>> linear_;
std::shared_ptr<Vector3WithFilter<double>> angular_;
std::shared_ptr<LowPassFilter> angular_lp_filter_;
void update(double linear_vel[3], double angular_vel[3], double period)
{
if (period < 0)
Expand All @@ -90,9 +95,11 @@ class ChassisVel
{
linear_->clear();
angular_->clear();
angular_lp_filter_->reset();
}
linear_->input(linear_vel);
angular_->input(angular_vel);
angular_lp_filter_->input(angular_vel[2]);
if (is_debug_ && loop_count_ % 10 == 0)
{
if (real_pub_->trylock())
Expand Down Expand Up @@ -185,12 +192,7 @@ class Controller : public controller_interface::MultiInterfaceController<rm_cont
double gravity_;
bool enable_gravity_compensation_;

// Resistance compensation
double yaw_resistance_;
double velocity_saturation_point_, effort_saturation_point_;

// Chassis
double k_chassis_vel_;
std::shared_ptr<ChassisVel> chassis_vel_;

bool dynamic_reconfig_initialized_{};
Expand Down
77 changes: 69 additions & 8 deletions rm_gimbal_controllers/src/bullet_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ BulletSolver::BulletSolver(ros::NodeHandle& controller_nh)
.g = getParam(controller_nh, "g", 0.),
.delay = getParam(controller_nh, "delay", 0.),
.dt = getParam(controller_nh, "dt", 0.),
.timeout = getParam(controller_nh, "timeout", 0.) };
.timeout = getParam(controller_nh, "timeout", 0.),
.ban_shoot_duration = getParam(controller_nh, "ban_shoot_duration", 0.0),
.gimbal_switch_duration = getParam(controller_nh, "gimbal_switch_duration", 0.0),
.angle1 = getParam(controller_nh, "angle1", 40.0),
.angle2 = getParam(controller_nh, "angle2", 2.0) };
max_track_target_vel_ = getParam(controller_nh, "max_track_target_vel", 5.0);
config_rt_buffer_.initRT(config_);

Expand Down Expand Up @@ -80,6 +84,12 @@ BulletSolver::BulletSolver(ros::NodeHandle& controller_nh)
new realtime_tools::RealtimePublisher<visualization_msgs::Marker>(controller_nh, "model_desire", 10));
path_real_pub_.reset(
new realtime_tools::RealtimePublisher<visualization_msgs::Marker>(controller_nh, "model_real", 10));
shoot_beforehand_cmd_pub_.reset(
new realtime_tools::RealtimePublisher<rm_msgs::ShootBeforehandCmd>(controller_nh, "shoot_beforehand_cmd", 10));
fly_time_pub_.reset(new realtime_tools::RealtimePublisher<std_msgs::Float64>(controller_nh, "fly_time", 10));

identified_target_change_sub_ = controller_nh.subscribe<std_msgs::Bool>(
"/armor_processor/change", 10, &BulletSolver::identifiedTargetChangeCB, this);
}

double BulletSolver::getResistanceCoefficient(double bullet_speed) const
Expand Down Expand Up @@ -115,14 +125,26 @@ bool BulletSolver::solve(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, d
selected_armor_ = 0;
double r = r1;
double z = pos.z;
double angle1 = config_.angle1 / 180 * M_PI;
double angle2 = config_.angle2 / 180 * M_PI;
track_target_ = std::abs(v_yaw) < max_track_target_vel_;
double switch_armor_angle = track_target_ ?
acos(r / target_rho) - M_PI / 12 +
(-acos(r / target_rho) + M_PI / 6) * std::abs(v_yaw) / max_track_target_vel_ :
M_PI / 12;
if ((((yaw + v_yaw * rough_fly_time) > output_yaw_ + switch_armor_angle) && v_yaw > 0.) ||
(((yaw + v_yaw * rough_fly_time) < output_yaw_ - switch_armor_angle) && v_yaw < 0.))
double switch_armor_angle =
track_target_ ? acos(r / target_rho) - angle1 +
(-acos(r / target_rho) + (angle1 + angle2)) * std::abs(v_yaw) / max_track_target_vel_ :
angle2;
is_in_delay_before_switch_ =
(((yaw + v_yaw * (rough_fly_time + config_.delay)) > output_yaw_ + switch_armor_angle) && v_yaw > 0.) ||
(((yaw + v_yaw * (rough_fly_time + config_.delay)) < output_yaw_ - switch_armor_angle) && v_yaw < 0.);
bool is_low_speed = std::abs(v_yaw) < 1.0;
if (((((yaw + v_yaw * rough_fly_time) > output_yaw_ + switch_armor_angle) && v_yaw > 0.) ||
(((yaw + v_yaw * rough_fly_time) < output_yaw_ - switch_armor_angle) && v_yaw < 0.)) &&
!is_low_speed)
{
if (identified_target_change_)
{
identified_target_change_ = false;
switch_armor_time_ = ros::Time::now();
}
selected_armor_ = v_yaw > 0. ? -1 : 1;
r = armors_num == 4 ? r2 : r1;
z = armors_num == 4 ? pos.z + dz : pos.z;
Expand Down Expand Up @@ -180,6 +202,11 @@ bool BulletSolver::solve(geometry_msgs::Point pos, geometry_msgs::Vector3 vel, d
if (count >= 20 || std::isnan(error))
return false;
}
if (fly_time_pub_->trylock())
{
fly_time_pub_->msg_.data = fly_time_;
fly_time_pub_->unlockAndPublish();
}
return true;
}

Expand Down Expand Up @@ -301,6 +328,32 @@ double BulletSolver::getGimbalError(geometry_msgs::Point pos, geometry_msgs::Vec
return error;
}

void BulletSolver::identifiedTargetChangeCB(const std_msgs::BoolConstPtr& msg)
{
if (msg->data)
identified_target_change_ = true;
}

void BulletSolver::judgeShootBeforehand(const ros::Time& time)
{
if (!track_target_)
shoot_beforehand_cmd_ = rm_msgs::ShootBeforehandCmd::JUDGE_BY_ERROR;
else if ((ros::Time::now() - switch_armor_time_).toSec() < ros::Duration(config_.ban_shoot_duration).toSec())
shoot_beforehand_cmd_ = rm_msgs::ShootBeforehandCmd::BAN_SHOOT;
else if (is_in_delay_before_switch_ && selected_armor_ == 0)
shoot_beforehand_cmd_ = rm_msgs::ShootBeforehandCmd::BAN_SHOOT;
else if ((ros::Time::now() - switch_armor_time_).toSec() < ros::Duration(config_.gimbal_switch_duration).toSec())
shoot_beforehand_cmd_ = rm_msgs::ShootBeforehandCmd::ALLOW_SHOOT;
else
shoot_beforehand_cmd_ = rm_msgs::ShootBeforehandCmd::JUDGE_BY_ERROR;
if (shoot_beforehand_cmd_pub_->trylock())
{
shoot_beforehand_cmd_pub_->msg_.stamp = time;
shoot_beforehand_cmd_pub_->msg_.cmd = shoot_beforehand_cmd_;
shoot_beforehand_cmd_pub_->unlockAndPublish();
}
}

void BulletSolver::reconfigCB(rm_gimbal_controllers::BulletSolverConfig& config, uint32_t /*unused*/)
{
ROS_INFO("[Bullet Solver] Dynamic params change");
Expand All @@ -316,6 +369,10 @@ void BulletSolver::reconfigCB(rm_gimbal_controllers::BulletSolverConfig& config,
config.delay = init_config.delay;
config.dt = init_config.dt;
config.timeout = init_config.timeout;
config.ban_shoot_duration = init_config.ban_shoot_duration;
config.gimbal_switch_duration = init_config.gimbal_switch_duration;
config.angle1 = init_config.angle1;
config.angle2 = init_config.angle2;
dynamic_reconfig_initialized_ = true;
}
Config config_non_rt{ .resistance_coff_qd_10 = config.resistance_coff_qd_10,
Expand All @@ -326,7 +383,11 @@ void BulletSolver::reconfigCB(rm_gimbal_controllers::BulletSolverConfig& config,
.g = config.g,
.delay = config.delay,
.dt = config.dt,
.timeout = config.timeout };
.timeout = config.timeout,
.ban_shoot_duration = config.ban_shoot_duration,
.gimbal_switch_duration = config.gimbal_switch_duration,
.angle1 = config.angle1,
.angle2 = config.angle2 };
config_rt_buffer_.writeFromNonRT(config_non_rt);
}
} // namespace rm_gimbal_controllers
62 changes: 36 additions & 26 deletions rm_gimbal_controllers/src/gimbal_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,21 @@ bool Controller::init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& ro
gravity_ = enable_feedforward ? (double)xml_rpc_value["gravity"] : 0.;
enable_gravity_compensation_ = enable_feedforward && (bool)xml_rpc_value["enable_gravity_compensation"];

ros::NodeHandle resistance_compensation_nh(controller_nh, "yaw/resistance_compensation");
yaw_resistance_ = getParam(resistance_compensation_nh, "resistance", 0.);
velocity_saturation_point_ = getParam(resistance_compensation_nh, "velocity_saturation_point", 0.);
effort_saturation_point_ = getParam(resistance_compensation_nh, "effort_saturation_point", 0.);

k_chassis_vel_ = getParam(controller_nh, "yaw/k_chassis_vel", 0.);
ros::NodeHandle chassis_vel_nh(controller_nh, "chassis_vel");
chassis_vel_ = std::make_shared<ChassisVel>(chassis_vel_nh);
ros::NodeHandle nh_bullet_solver = ros::NodeHandle(controller_nh, "bullet_solver");
bullet_solver_ = std::make_shared<BulletSolver>(nh_bullet_solver);

ros::NodeHandle nh_yaw = ros::NodeHandle(controller_nh, "yaw");
ros::NodeHandle nh_pitch = ros::NodeHandle(controller_nh, "pitch");
ros::NodeHandle nh_pid_yaw_pos = ros::NodeHandle(controller_nh, "pid_yaw_pos");
ros::NodeHandle nh_pid_pitch_pos = ros::NodeHandle(controller_nh, "pid_pitch_pos");

config_ = { .yaw_k_v_ = getParam(nh_pitch, "k_v", 0.), .pitch_k_v_ = getParam(nh_yaw, "k_v", 0.) };
ros::NodeHandle nh_pid_yaw_pos = ros::NodeHandle(controller_nh, "yaw/pid_pos");
ros::NodeHandle nh_pid_pitch_pos = ros::NodeHandle(controller_nh, "pitch/pid_pos");

config_ = { .yaw_k_v_ = getParam(nh_yaw, "k_v", 0.),
.pitch_k_v_ = getParam(nh_pitch, "k_v", 0.),
.k_chassis_vel_ = getParam(controller_nh, "yaw/k_chassis_vel", 0.),
.delay = getParam(controller_nh, "delay", 0.),
.delay2 = getParam(controller_nh, "delay2", 0.) };
config_rt_buffer_.initRT(config_);
d_srv_ = new dynamic_reconfigure::Server<rm_gimbal_controllers::GimbalBaseConfig>(controller_nh);
dynamic_reconfigure::Server<rm_gimbal_controllers::GimbalBaseConfig>::CallbackType cb =
Expand Down Expand Up @@ -141,10 +139,10 @@ bool Controller::init(hardware_interface::RobotHW* robot_hw, ros::NodeHandle& ro
data_track_sub_ = controller_nh.subscribe<rm_msgs::TrackData>("/track", 1, &Controller::trackCB, this);
publish_rate_ = getParam(controller_nh, "publish_rate", 100.);
error_pub_.reset(new realtime_tools::RealtimePublisher<rm_msgs::GimbalDesError>(controller_nh, "error", 100));
pid_yaw_pos_state_pub_.reset(new realtime_tools::RealtimePublisher<control_msgs::JointControllerState>(
nh_pid_yaw_pos, "pid_yaw_pos_state", 1));
pid_pitch_pos_state_pub_.reset(new realtime_tools::RealtimePublisher<control_msgs::JointControllerState>(
nh_pid_pitch_pos, "pid_pitch_pos_state", 1));
pid_yaw_pos_state_pub_.reset(
new realtime_tools::RealtimePublisher<control_msgs::JointControllerState>(nh_yaw, "pos_state", 1));
pid_pitch_pos_state_pub_.reset(
new realtime_tools::RealtimePublisher<control_msgs::JointControllerState>(nh_pitch, "pos_state", 1));
return true;
}

Expand Down Expand Up @@ -267,7 +265,9 @@ void Controller::track(const ros::Time& time)
double yaw_compute = yaw_real;
double pitch_compute = -pitch_real;
geometry_msgs::Point target_pos = data_track_.position;
geometry_msgs::Vector3 target_vel = data_track_.velocity;
geometry_msgs::Vector3 target_vel{};
if (data_track_.id != 12)
target_vel = data_track_.velocity;
try
{
if (!data_track_.header.frame_id.empty())
Expand All @@ -282,15 +282,19 @@ void Controller::track(const ros::Time& time)
{
ROS_WARN("%s", ex.what());
}
target_pos.x -= odom2pitch_.transform.translation.x;
target_pos.y -= odom2pitch_.transform.translation.y;
target_pos.z -= odom2pitch_.transform.translation.z;
double yaw = data_track_.yaw + data_track_.v_yaw * ((time - data_track_.header.stamp).toSec() + config_.delay);
target_pos.x +=
target_vel.x * ((time - data_track_.header.stamp).toSec() + config_.delay2) - odom2pitch_.transform.translation.x;
target_pos.y +=
target_vel.y * ((time - data_track_.header.stamp).toSec() + config_.delay2) - odom2pitch_.transform.translation.y;
target_pos.z += target_vel.z * (time - data_track_.header.stamp).toSec() - odom2pitch_.transform.translation.z;
target_vel.x -= chassis_vel_->linear_->x();
target_vel.y -= chassis_vel_->linear_->y();
target_vel.z -= chassis_vel_->linear_->z();
bool solve_success =
bullet_solver_->solve(target_pos, target_vel, cmd_gimbal_.bullet_speed, data_track_.yaw, data_track_.v_yaw,
bullet_solver_->solve(target_pos, target_vel, cmd_gimbal_.bullet_speed, yaw, data_track_.v_yaw,
data_track_.radius_1, data_track_.radius_2, data_track_.dz, data_track_.armors_num);
bullet_solver_->judgeShootBeforehand(time);

if (publish_rate_ > 0.0 && last_publish_time_ + ros::Duration(1.0 / publish_rate_) < time)
{
Expand Down Expand Up @@ -472,13 +476,15 @@ void Controller::moveJoint(const ros::Time& time, const ros::Duration& period)
}
loop_count_++;

ctrl_yaw_.setCommand(pid_yaw_pos_.getCurrentCmd() + config_.yaw_k_v_ * yaw_vel_des + ctrl_yaw_.joint_.getVelocity() -
angular_vel_yaw.z);
ctrl_yaw_.setCommand(pid_yaw_pos_.getCurrentCmd() -
config_.k_chassis_vel_ * chassis_vel_->angular_lp_filter_->output() +
config_.yaw_k_v_ * yaw_vel_des + ctrl_yaw_.joint_.getVelocity() - angular_vel_yaw.z);
ctrl_pitch_.setCommand(pid_pitch_pos_.getCurrentCmd() + config_.pitch_k_v_ * pitch_vel_des +
ctrl_pitch_.joint_.getVelocity() - angular_vel_pitch.y);
ctrl_pitch_.joint_.setCommand(ctrl_pitch_.joint_.getCommand() + feedForward(time));
ctrl_yaw_.update(time, period);
ctrl_pitch_.update(time, period);
if (data_track_.id == 12)
ctrl_pitch_.joint_.setCommand(ctrl_pitch_.joint_.getCommand() + feedForward(time));
}

double Controller::feedForward(const ros::Time& time)
Expand Down Expand Up @@ -539,12 +545,16 @@ void Controller::reconfigCB(rm_gimbal_controllers::GimbalBaseConfig& config, uin
GimbalConfig init_config = *config_rt_buffer_.readFromNonRT(); // config init use yaml
config.yaw_k_v_ = init_config.yaw_k_v_;
config.pitch_k_v_ = init_config.pitch_k_v_;
config.k_chassis_vel_ = init_config.k_chassis_vel_;
config.delay = init_config.delay;
config.delay2 = init_config.delay2;
dynamic_reconfig_initialized_ = true;
}
GimbalConfig config_non_rt{
.yaw_k_v_ = config.yaw_k_v_,
.pitch_k_v_ = config.pitch_k_v_,
};
GimbalConfig config_non_rt{ .yaw_k_v_ = config.yaw_k_v_,
.pitch_k_v_ = config.pitch_k_v_,
.k_chassis_vel_ = config.k_chassis_vel_,
.delay = config.delay,
.delay2 = config.delay2 };
config_rt_buffer_.writeFromNonRT(config_non_rt);
}

Expand Down
Loading