diff --git a/include/rm_manual/chassis_gimbal_manual.h b/include/rm_manual/chassis_gimbal_manual.h index 52b0ccc0..6c07ed8b 100644 --- a/include/rm_manual/chassis_gimbal_manual.h +++ b/include/rm_manual/chassis_gimbal_manual.h @@ -30,6 +30,7 @@ class ChassisGimbalManual : public ManualBase void dbusDataCallback(const rm_msgs::DbusData::ConstPtr& data) override; void capacityDataCallback(const rm_msgs::PowerManagementSampleAndStatusData ::ConstPtr& data) override; void trackCallback(const rm_msgs::TrackData::ConstPtr& data) override; + void setChassisMode(int mode); virtual void wPress() { x_scale_ = x_scale_ >= 1.0 ? 1.0 : x_scale_ + 1.0; diff --git a/src/chassis_gimbal_manual.cpp b/src/chassis_gimbal_manual.cpp index 71ac115c..aaef524f 100644 --- a/src/chassis_gimbal_manual.cpp +++ b/src/chassis_gimbal_manual.cpp @@ -222,4 +222,19 @@ void ChassisGimbalManual::mouseMidRise(double m_z) } } +void ChassisGimbalManual::setChassisMode(int mode) +{ + switch (mode) + { + case rm_msgs::ChassisCmd::RAW: + chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::RAW); + is_gyro_ = true; + break; + case rm_msgs::ChassisCmd::FOLLOW: + chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + is_gyro_ = false; + break; + } +} + } // namespace rm_manual diff --git a/src/chassis_gimbal_shooter_manual.cpp b/src/chassis_gimbal_shooter_manual.cpp index 97ca25bc..37648ac5 100644 --- a/src/chassis_gimbal_shooter_manual.cpp +++ b/src/chassis_gimbal_shooter_manual.cpp @@ -236,13 +236,11 @@ void ChassisGimbalShooterManual::updateRc(const rm_msgs::DbusData::ConstPtr& dbu ChassisGimbalManual::updateRc(dbus_data); if (std::abs(dbus_data->wheel) > 0.01) { - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::RAW); - is_gyro_ = true; + setChassisMode(rm_msgs::ChassisCmd::RAW); } else { - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); - is_gyro_ = false; + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); } vel_cmd_sender_->setAngularZVel((std::abs(dbus_data->ch_r_y) > 0.01 || std::abs(dbus_data->ch_r_x) > 0.01) ? dbus_data->wheel * gyro_rotate_reduction_ : @@ -400,14 +398,12 @@ void ChassisGimbalShooterManual::cPress() { if (is_gyro_) { - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); vel_cmd_sender_->setAngularZVel(0.0); - is_gyro_ = false; } else { - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::RAW); - is_gyro_ = true; + setChassisMode(rm_msgs::ChassisCmd::RAW); chassis_cmd_sender_->power_limit_->updateState(rm_common::PowerLimit::NORMAL); if (x_scale_ != 0.0 || y_scale_ != 0.0) vel_cmd_sender_->setAngularZVel(gyro_rotate_reduction_); @@ -456,7 +452,7 @@ void ChassisGimbalShooterManual::wPress() { gimbal_cmd_sender_->setEject(false); manual_to_referee_pub_data_.hero_eject_flag = gimbal_cmd_sender_->getEject(); - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); chassis_cmd_sender_->power_limit_->updateState(rm_common::PowerLimit::NORMAL); } } @@ -469,7 +465,7 @@ void ChassisGimbalShooterManual::aPress() { gimbal_cmd_sender_->setEject(false); manual_to_referee_pub_data_.hero_eject_flag = gimbal_cmd_sender_->getEject(); - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); chassis_cmd_sender_->power_limit_->updateState(rm_common::PowerLimit::NORMAL); } } @@ -482,7 +478,7 @@ void ChassisGimbalShooterManual::sPress() { gimbal_cmd_sender_->setEject(false); manual_to_referee_pub_data_.hero_eject_flag = gimbal_cmd_sender_->getEject(); - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); chassis_cmd_sender_->power_limit_->updateState(rm_common::PowerLimit::NORMAL); } } @@ -495,7 +491,7 @@ void ChassisGimbalShooterManual::dPress() { gimbal_cmd_sender_->setEject(false); manual_to_referee_pub_data_.hero_eject_flag = gimbal_cmd_sender_->getEject(); - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); chassis_cmd_sender_->power_limit_->updateState(rm_common::PowerLimit::NORMAL); } } @@ -590,9 +586,8 @@ void ChassisGimbalShooterManual::shiftPress() { if (chassis_cmd_sender_->getMsg()->mode != rm_msgs::ChassisCmd::FOLLOW && is_gyro_) { - chassis_cmd_sender_->setMode(rm_msgs::ChassisCmd::FOLLOW); + setChassisMode(rm_msgs::ChassisCmd::FOLLOW); vel_cmd_sender_->setAngularZVel(1.0); - is_gyro_ = false; } chassis_cmd_sender_->power_limit_->updateState(rm_common::PowerLimit::BURST); }