diff --git a/robotnik_pad/CMakeLists.txt b/robotnik_pad/CMakeLists.txt index 454c7ed..0174ef1 100644 --- a/robotnik_pad/CMakeLists.txt +++ b/robotnik_pad/CMakeLists.txt @@ -15,12 +15,13 @@ find_package(catkin REQUIRED COMPONENTS geometry_msgs ackermann_msgs pluginlib + actionlib ) catkin_package( INCLUDE_DIRS include # LIBRARIES robotnik_pad - CATKIN_DEPENDS roscpp rcomponent robotnik_msgs sensor_msgs geometry_msgs ackermann_msgs pluginlib + CATKIN_DEPENDS roscpp rcomponent robotnik_msgs sensor_msgs geometry_msgs ackermann_msgs pluginlib actionlib # DEPENDS system_lib ) diff --git a/robotnik_pad/include/robotnik_pad/axes.h b/robotnik_pad/include/robotnik_pad/axes.h new file mode 100644 index 0000000..2c12d5c --- /dev/null +++ b/robotnik_pad/include/robotnik_pad/axes.h @@ -0,0 +1,65 @@ +#ifndef _AXES_ +#define _AXES_ + + +#include +//! Class to save the state of the buttons +class Axes +{ + int is_pressed_pos{0}; + int is_pressed_neg{0}; + bool is_released_pos{false}; + bool is_released_neg{false}; + float axis_value{0.0}; + +public: + Axes(){} + + void press(float value) + { + bool isValuePositive = (value > 0); + bool isValueNegative = (value < 0); + + is_released_pos = (is_pressed_pos && !isValuePositive); + is_released_neg = (is_pressed_neg && !isValueNegative); + + is_pressed_pos = isValuePositive; + is_pressed_neg = isValueNegative; + + 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_ \ No newline at end of file diff --git a/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h b/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h index 361263b..e0bd5a9 100644 --- a/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h +++ b/robotnik_pad/include/robotnik_pad/generic_pad_plugin.h @@ -2,9 +2,18 @@ #define GENERIC_PAD_PLUGIN_H_ #include +#include #include #include #include +#include + +struct pad_element +{ + bool isAButton; + int index; + bool negativeAxes{false}; +}; namespace pad_plugins { @@ -15,7 +24,7 @@ class GenericPadPlugin public: virtual void initialize(const ros::NodeHandle& nh, const std::string& plugin_ns) = 0; - virtual void execute(const std::vector