Skip to content

Commit 8475870

Browse files
committed
fix chassis switch trigger of hero
1 parent 0f3763a commit 8475870

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

decision/hero_vehicle/src/dbus_interpreter.cpp

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "hero_vehicle/dbus_interpreter.h"
2+
#include "rclcpp/rclcpp.hpp"
23
#include <cmath>
34

45
DbusInterpreter::DbusInterpreter(double max_vel, double max_omega, double aim_sens, double deadzone, double video_link_blank_time)
@@ -115,6 +116,22 @@ void DbusInterpreter::input_video_link_vt03(const operation_interface::msg::VT03
115116

116117
cns_ = msg->cns;
117118
trigger = msg->trigger;
119+
120+
auto current_time = rclcpp::Clock().now();
121+
rclcpp::Logger tmp_logger = rclcpp::get_logger("test");
122+
if(current_time.seconds()-last_trigger_update_time_.seconds() > 0.2){
123+
if(trigger && !last_trigger) // TOGGLE CHASSIS MODE
124+
{
125+
RCLCPP_INFO(tmp_logger, "trigger pressed");
126+
if(chassis_->mode == behavior_interface::msg::Chassis::GYRO){
127+
chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW;
128+
}else if(chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW){
129+
chassis_->mode = behavior_interface::msg::Chassis::GYRO;
130+
}
131+
last_trigger_update_time_ = rclcpp::Clock().now();
132+
}
133+
}
134+
last_trigger = trigger;
118135
}
119136

120137
void DbusInterpreter::update()
@@ -186,26 +203,6 @@ void DbusInterpreter::update()
186203
}
187204
// To ensure that the change take place only once per key press
188205

189-
if(current_time.seconds()-last_trigger_update_time_.seconds() > 0.2){
190-
if(trigger && !last_trigger) // TOGGLE CHASSIS MODE
191-
{
192-
if(chassis_->mode == behavior_interface::msg::Chassis::GYRO){
193-
chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW;
194-
}else if(chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW){
195-
chassis_->mode = behavior_interface::msg::Chassis::GYRO;
196-
}
197-
}
198-
last_trigger_update_time_ = rclcpp::Clock().now();
199-
}
200-
201-
// if(c_ && !last_c_){
202-
// if(chassis_->mode == behavior_interface::msg::Chassis::GYRO){
203-
// chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW;
204-
// }else if(chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW){
205-
// chassis_->mode = behavior_interface::msg::Chassis::GYRO;
206-
// }
207-
// }
208-
last_trigger = trigger;
209206
// if(ctrl_){
210207
// chassis_->mode = behavior_interface::msg::Chassis::CHASSIS_FOLLOW;
211208
// }
@@ -262,4 +259,4 @@ void DbusInterpreter::curb(double &val, double max_val)
262259
{
263260
val = -max_val;
264261
}
265-
}
262+
}

0 commit comments

Comments
 (0)