-
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
62f8d04
2fc414e
72026bb
9d465b5
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| .*vscode | ||
| .*vscode | ||
| _codeql_detected_source_root |
| 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); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| // Actionlib action client | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_action_client_ = std::make_shared | ||||||||||||||||||||||||||||||||||||||||||||||||||
| <actionlib::SimpleActionClient<robotnik_msgs::SetElevatorAction>>(nh_, elevator_action_ns_, true); | ||||||||||||||||||||||||||||||||||||||||||||||||||
jamendezib marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_is_running_ = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void PadPluginElevatorAction::execute(const std::vector<Button>& buttons, std::vector<float>& axes) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (buttons[button_dead_man_].isPressed()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (axes[axis_elevator_] > 0.95) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!elevator_is_running_) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_is_running_ = sendGoal(robotnik_msgs::ElevatorAction::RAISE); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (axes[axis_elevator_] < -0.95) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!elevator_is_running_) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_is_running_ = sendGoal(robotnik_msgs::ElevatorAction::LOWER); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stop_elevator_) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (axes[axis_elevator_] > -0.1 && axes[axis_elevator_] < 0.1 && elevator_is_running_) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_is_running_ = !sendGoal(robotnik_msgs::ElevatorAction::STOP); | ||||||||||||||||||||||||||||||||||||||||||||||||||
jamendezib marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| else if (buttons[button_dead_man_].isReleased()) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if (stop_elevator_dead_man_ && elevator_is_running_) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_is_running_ = !sendGoal(robotnik_msgs::ElevatorAction::STOP); | ||||||||||||||||||||||||||||||||||||||||||||||||||
jamendezib marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void PadPluginElevatorAction::actionDoneCb(const actionlib::SimpleClientGoalState& state, const robotnik_msgs::SetElevatorResultConstPtr& result) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_is_running_ = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| bool PadPluginElevatorAction::sendGoal(const int action) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| robotnik_msgs::SetElevatorGoal elevator_goal; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| elevator_goal.action.action = action; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ROS_INFO_NAMED("PadPluginElevatorAction", "PadPluginElevatorAction::execute: %d", action); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+74
to
+78
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| 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); |
Uh oh!
There was an error while loading. Please reload this page.