From 2f615daf3a1587a3eb78e89b1cf41e2195bc4062 Mon Sep 17 00:00:00 2001 From: Luis Date: Fri, 8 Jul 2022 11:51:12 +0200 Subject: [PATCH 1/5] Add new axes class. --- robotnik_pad/include/robotnik_pad/axes.h | 84 +++++++++++++++++++ .../include/robotnik_pad/generic_pad_plugin.h | 7 +- .../include/robotnik_pad/robotnik_pad.h | 3 +- robotnik_pad/src/robotnik_pad.cpp | 11 ++- .../ackermann_movement_plugin.h | 2 +- .../robotnik_pad_plugins/elevator_plugin.h | 7 +- .../robotnik_pad_plugins/movement_plugin.h | 2 +- .../src/ackermann_movement_plugin.cpp | 6 +- robotnik_pad_plugins/src/elevator_plugin.cpp | 82 ++++++++++++------ robotnik_pad_plugins/src/movement_plugin.cpp | 22 ++--- 10 files changed, 177 insertions(+), 49 deletions(-) create mode 100644 robotnik_pad/include/robotnik_pad/axes.h diff --git a/robotnik_pad/include/robotnik_pad/axes.h b/robotnik_pad/include/robotnik_pad/axes.h new file mode 100644 index 0000000..7440dad --- /dev/null +++ b/robotnik_pad/include/robotnik_pad/axes.h @@ -0,0 +1,84 @@ +#ifndef _AXES_ +#define _AXES_ + +//! Class to save the state of the buttons +class Axes +{ + int is_pressed_pos, is_pressed_neg; + bool is_released_pos, is_released_neg; + float axis_value; + +public: + Axes() + { + is_pressed_pos = 0; + is_pressed_neg = 0; + is_released_pos = false; + is_released_neg = false; + axis_value = 0.0; + } + + //! Set the button as 'pressed'/'released' + void press(float value) + { + if (is_pressed_pos and !(value > 0)) + { + is_released_pos = true; + } + else if (is_released_pos and (value > 0)) + is_released_pos = false; + + if (is_pressed_neg and !(value < 0)) + { + is_released_neg = true; + } + else if (is_released_neg and (value < 0)) + is_released_neg = false; + + if (value > 0) + is_pressed_pos = true; + else + is_pressed_pos = false; + + if (value < 0) + is_pressed_neg = true; + else + is_pressed_neg = false; + + axis_value = value; + } + + int isPressedPos() const + { + return is_pressed_pos; + } + int isPressedNeg() const + { + return is_pressed_neg; + } + + bool isReleasedPos() const + { + return is_released_pos; + } + + bool isReleasedNeg() const + { + return is_released_neg; + } + + void resetReleased() + { + if (is_released_pos) + is_released_pos = false; + if (is_released_neg) + is_released_neg = false; + } + + float getValue() const + { + return axis_value; + } +}; + +#endif // _AXES_ diff --git a/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h b/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h index 361263b..01baf09 100644 --- a/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h +++ b/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h @@ -2,6 +2,7 @@ #define GENERIC_PAD_PLUGIN_H_ #include +#include #include #include #include @@ -15,7 +16,7 @@ class GenericPadPlugin public: virtual void initialize(const ros::NodeHandle& nh, const std::string& plugin_ns) = 0; - virtual void execute(const std::vector