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

fix e-stop handling #21

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions joy2twist/include/joy2twist/joy2twist_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Joy2TwistNode : public rclcpp::Node
void trigger_service_cb(
const rclcpp::Client<SrvTrigger>::SharedFuture & future,
const std::string & service_name) const;
void handle_e_stop(const std::shared_ptr<MsgJoy> joy_msg);

std::map<std::string, float> linear_velocity_factors_;
std::map<std::string, float> angular_velocity_factors_;
Expand Down
34 changes: 23 additions & 11 deletions joy2twist/src/joy2twist_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,7 @@ void Joy2TwistNode::joy_cb(const MsgJoy::SharedPtr joy_msg)
{
MsgTwist twist_msg;

if (e_stop_present_) {
if (joy_msg->buttons.at(button_index_.e_stop_trigger) && !e_stop_state_) {
// Stop the robot before trying to call the e-stop trigger service
twist_pub_->publish(twist_msg);
call_trigger_service(e_stop_trigger_client_);
} else if (
joy_msg->buttons.at(button_index_.enable_e_stop_reset) &&
joy_msg->buttons.at(button_index_.e_stop_reset) && e_stop_state_) {
call_trigger_service(e_stop_reset_client_);
}
}
handle_e_stop(joy_msg);

if (joy_msg->buttons.at(button_index_.dead_man_switch)) {
driving_mode_ = true;
Expand Down Expand Up @@ -159,4 +149,26 @@ void Joy2TwistNode::trigger_service_cb(
RCLCPP_INFO(this->get_logger(), "Successfully called %s service", service_name.c_str());
}

void Joy2TwistNode::handle_e_stop(const std::shared_ptr<MsgJoy> joy_msg)
{
if (!e_stop_present_) {
return;
}

if (joy_msg->buttons.at(button_index_.e_stop_trigger)) {
if (!e_stop_state_) {
// Stop the robot before trying to call the e-stop trigger service
twist_pub_->publish(MsgTwist());
call_trigger_service(e_stop_trigger_client_);
}
return;
}

if (
joy_msg->buttons.at(button_index_.enable_e_stop_reset) &&
joy_msg->buttons.at(button_index_.e_stop_reset) && e_stop_state_) {
call_trigger_service(e_stop_reset_client_);
}
}

} // namespace joy2twist
Loading