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 for #43 #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions locomotor/include/locomotor/locomotor_action_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
namespace locomotor
{
using NewGoalCallback = std::function<void (const nav_2d_msgs::Pose2DStamped&)>;
using PreemptionCallback = std::function<void ()>;

class LocomotorActionServer
{
Expand All @@ -51,12 +52,16 @@ class LocomotorActionServer
void publishFeedback(const locomotor_msgs::NavigationState& nav_state);
void completeNavigation();
void failNavigation(const locomotor_msgs::ResultCode& result_code);

// Note: This is a separate method so as not to change the previous constructor parameter list
void setPremptionCallback(PreemptionCallback cb) { preemption_cb_ = cb; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend just having a virtual void onPreemption() {} method that the user can override.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which class?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this one. Rather than setting a callback functor, you can just let the user override the onPreemption method if they want to trigger some callback. These 2 actions will have equal output.

protected:
void preGoalCallback();
void preemptCallback();
actionlib::SimpleActionServer<locomotor_msgs::NavigateToPoseAction> navigate_action_server_;
locomotor_msgs::NavigateToPoseFeedback feedback_;
NewGoalCallback goal_cb_;
PreemptionCallback preemption_cb_;
};
} // namespace locomotor

Expand Down
1 change: 1 addition & 0 deletions locomotor/src/locomotor_action_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void LocomotorActionServer::preGoalCallback()
void LocomotorActionServer::preemptCallback()
{
if (!navigate_action_server_.isActive()) return;
if (preemption_cb_) preemption_cb_();
locomotor_msgs::NavigateToPoseResult result;
result.result_code.result_code = -1;
result.result_code.message = "Preempted.";
Expand Down