-
Notifications
You must be signed in to change notification settings - Fork 8
Add elevator_action_plugin #31
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
base: ros-devel
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #ifndef PAD_PLUGIN_ELEVATOR_ACTION_H_ | ||
| #define PAD_PLUGIN_ELEVATOR_ACTION_H_ | ||
|
|
||
| #include <robotnik_msgs/ElevatorAction.h> | ||
| #include <robotnik_msgs/SetElevatorAction.h> | ||
| #include <robotnik_msgs/SetElevatorActionGoal.h> | ||
| #include <robotnik_msgs/SetElevatorGoal.h> | ||
| #include <robotnik_msgs/SetElevatorResult.h> | ||
| #include <robotnik_pad/generic_pad_plugin.h> | ||
| #include <actionlib/client/simple_action_client.h> | ||
| #include <actionlib/client/simple_client_goal_state.h> | ||
|
|
||
| namespace pad_plugins | ||
| { | ||
| class PadPluginElevatorAction : public GenericPadPlugin | ||
| { | ||
| public: | ||
| PadPluginElevatorAction(); | ||
| ~PadPluginElevatorAction(); | ||
|
|
||
| virtual void initialize(const ros::NodeHandle &nh, const std::string &plugin_ns); | ||
| virtual void execute(const std::vector<Button> &buttons, std::vector<float> &axes); | ||
|
|
||
| protected: | ||
| int button_dead_man_; | ||
| double axis_elevator_; | ||
| bool elevator_is_running_; | ||
| bool stop_elevator_; | ||
| bool stop_elevator_dead_man_; | ||
|
|
||
| std::string elevator_action_ns_; | ||
| std::shared_ptr<actionlib::SimpleActionClient<robotnik_msgs::SetElevatorAction>> elevator_action_client_; | ||
|
|
||
| bool sendGoal(const int action); | ||
| void actionDoneCb(const actionlib::SimpleClientGoalState& state, const robotnik_msgs::SetElevatorResultConstPtr& result); | ||
| }; | ||
| }; // namespace pad_plugins | ||
| #endif // PAD_PLUGIN_ELEVATOR_ACTION_H_ |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <robotnik_pad_plugins/elevator_action_plugin.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace pad_plugins | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| PadPluginElevatorAction::PadPluginElevatorAction() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| PadPluginElevatorAction::~PadPluginElevatorAction() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void PadPluginElevatorAction::initialize(const ros::NodeHandle& nh, const std::string& plugin_ns) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bool required = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| bool not_required = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| pnh_ = ros::NodeHandle(nh, plugin_ns); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| readParam(pnh_, "config/deadman", button_dead_man_, button_dead_man_, required); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| readParam(pnh_, "config/axis_elevator", axis_elevator_, axis_elevator_, required); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| readParam(pnh_, "elevator_action_ns", elevator_action_ns_, elevator_action_ns_, required); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| readParam(pnh_, "stop_elevator", stop_elevator_, false, not_required); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| readParam(pnh_, "stop_elevator_dead_man", stop_elevator_dead_man_, false, not_required); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Service client | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| // Service client | |
| // Actionlib action client |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The action client is created using nh_ from the base class, but unlike other plugins (e.g., poi_plugin.cpp, blkarc_plugin.cpp), nh_ is not initialized in this plugin's initialize() method. This will cause the action client to be created with an uninitialized node handle. Add nh_ = ros::NodeHandle(); before line 26, similar to poi_plugin.cpp line 20.
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Redundant comparison: The expression elevator_is_running_ == true can be simplified to elevator_is_running_ for better readability and consistency with line 38 and line 45 which use !elevator_is_running_.
| if (axes[axis_elevator_] > -0.1 && axes[axis_elevator_] < 0.1 && elevator_is_running_ == true) | |
| if (axes[axis_elevator_] > -0.1 && axes[axis_elevator_] < 0.1 && elevator_is_running_) |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent state management: When stopping the elevator (line 55), elevator_is_running_ is set to the negation of sendGoal() result. If sendGoal() returns true (success), this sets elevator_is_running_ = false, which is correct. However, if sendGoal() returns false (failure), this sets elevator_is_running_ = true, incorrectly indicating the elevator is still running even though the STOP command failed. The same issue exists on line 64. Consider setting elevator_is_running_ = false unconditionally after attempting to stop, or handle the failure case explicitly.
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same inconsistent state management issue as line 55: If sendGoal() fails and returns false, this will set elevator_is_running_ = true, incorrectly indicating the elevator is still running. Consider setting elevator_is_running_ = false unconditionally or handling the failure case explicitly.
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message is unclear: The log message "PadPluginElevatorAction::execute: %d" doesn't clearly indicate what action is being performed. Consider using more descriptive messages like "Sending elevator action: %d" or adding action name strings (RAISE/LOWER/STOP) to make debugging easier.
| bool PadPluginElevatorAction::sendGoal(const int action) | |
| { | |
| robotnik_msgs::SetElevatorGoal elevator_goal; | |
| elevator_goal.action.action = action; | |
| ROS_INFO_NAMED("PadPluginElevatorAction", "PadPluginElevatorAction::execute: %d", action); | |
| // Helper function to convert action int to string | |
| static const char* elevatorActionToString(int action) { | |
| switch (action) { | |
| case robotnik_msgs::ElevatorAction::RAISE: | |
| return "RAISE"; | |
| case robotnik_msgs::ElevatorAction::LOWER: | |
| return "LOWER"; | |
| case robotnik_msgs::ElevatorAction::STOP: | |
| return "STOP"; | |
| default: | |
| return "UNKNOWN"; | |
| } | |
| } | |
| bool PadPluginElevatorAction::sendGoal(const int action) | |
| { | |
| robotnik_msgs::SetElevatorGoal elevator_goal; | |
| elevator_goal.action.action = action; | |
| ROS_INFO_NAMED("PadPluginElevatorAction", "Sending elevator action: %s (%d)", elevatorActionToString(action), action); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing
exec_dependfor actionlib. Since actionlib is required at runtime for the action client, it should be added as an execution dependency similar to other dependencies like roscpp, pluginlib, etc.