avoid multiple switch event

This commit is contained in:
Huang Zhenbiao 2024-09-29 20:45:50 +08:00
parent e0020b4bfe
commit 0ed329a44d
2 changed files with 3 additions and 0 deletions

View File

@ -31,6 +31,7 @@ namespace ocs2::legged_robot {
std::shared_ptr<GaitSchedule> gait_schedule_ptr_;
ModeSequenceTemplate target_gait_;
int last_command_ = 0;
bool gait_updated_{false};
bool verbose_{false};
std::vector<ModeSequenceTemplate> gait_list_;

View File

@ -42,6 +42,8 @@ namespace ocs2::legged_robot {
void GaitManager::getTargetGait() {
if (ctrl_component_.control_inputs_.command == 0) return;
if (ctrl_component_.control_inputs_.command == last_command_) return;
last_command_ = ctrl_component_.control_inputs_.command;
target_gait_ = gait_list_[ctrl_component_.control_inputs_.command - 1];
RCLCPP_INFO(rclcpp::get_logger("GaitManager"), "Switch to gait: %s",
gait_name_list_[ctrl_component_.control_inputs_.command - 1].c_str());