Skip to content

Commit

Permalink
Merge pull request #105 from BlanchardLj/modeFSM
Browse files Browse the repository at this point in the history
Encapsulate two chassis modes for easier recall
  • Loading branch information
d0h0s authored Jul 21, 2024
2 parents de20f92 + 2945084 commit 77425cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions include/rm_manual/chassis_gimbal_manual.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/chassis_gimbal_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 9 additions & 14 deletions src/chassis_gimbal_shooter_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_ :
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 77425cc

Please sign in to comment.