29 #ifndef JOYSTICK_HANDLER_H__ 30 #define JOYSTICK_HANDLER_H__ 34 #include <geometry_msgs/Point.h> 35 #include <geometry_msgs/Twist.h> 37 #include <sensor_msgs/Joy.h> 51 virtual void joyCallback(
const sensor_msgs::Joy::ConstPtr& joy_msg) = 0;
79 void joyCallback(
const sensor_msgs::Joy::ConstPtr& joy_msg)
override 81 if (joy_msg->buttons.size() <= button_id_)
82 ROS_ERROR_THROTTLE(1.0,
"Couldn't read button %i as only %lu buttons exist. Maybe wrong controller connected?", button_id_, joy_msg->buttons.size());
84 val_ = joy_msg->buttons[button_id_];
95 JoystickAxis(
int axis,
double thresh = 1.0,
double min_val = -1.0,
double max_val = 1.0,
double zero_val = 0.0,
double calib_offset = 0.0,
bool invert =
false)
100 , zero_val_(zero_val)
101 , calib_offset_(calib_offset)
103 , scale_factor_(2.0/(max_-min_))
104 , scale_offset_(0.5*(max_+min_))
106 ROS_INFO(
"[Axis %i] %f - (%f, %f) - %f", axis, thresh, min_val, max_val, calib_offset);
110 :
JoystickAxis(params[
"axis"], params[
"thresh"], params[
"min"], params[
"max"], params[
"zero"], params[
"calib"], params[
"invert"])
113 void joyCallback(
const sensor_msgs::Joy::ConstPtr& joy_msg)
override 115 if (joy_msg->axes.size() <= axis_id_)
116 ROS_ERROR_THROTTLE(1.0,
"Couldn't read axis %i as only %lu axes exist. Maybe wrong controller connected?", axis_id_, joy_msg->axes.size());
120 val_ = joy_msg->axes[axis_id_] - calib_offset_;
127 val_ = std::min(std::max(
val_, min_), max_);
128 val_ =
val_ * scale_factor_ + scale_offset_;
156 void joyCallback(
const sensor_msgs::Joy::ConstPtr& last_joy_msg);
158 void getJoystickCommand(geometry_msgs::Twist& twist,
bool& enable)
const;
166 void updateJoystickCommand(
double elapsed_time_sec,
double joy_val,
double& val,
double min_vel,
double max_vel,
double min_acc,
double max_acc,
double sensivity)
const;
167 double convertJoyAxisToAcc(
double elapsed_time_sec,
double joy_val,
double val,
double min_vel,
double max_vel)
const;
#define ROS_ERROR_THROTTLE(rate,...)