34 #include <geometry_msgs/Twist.h> 35 #include <sensor_msgs/Joy.h> 36 #include <std_msgs/Bool.h> 63 void cbJoy(
const sensor_msgs::Joy::Ptr msg)
65 if (static_cast<size_t>(interrupt_button_) >= msg->buttons.size())
67 ROS_ERROR(
"Out of range: number of buttons (%lu) must be greater than interrupt_button (%d).",
72 if (!msg->buttons[interrupt_button_])
76 pub_twist_.
publish(last_input_twist_);
86 if (static_cast<size_t>(linear_axis_) < msg->axes.size())
87 lin = msg->axes[linear_axis_];
89 ROS_ERROR(
"Out of range: number of axis (%lu) must be greater than linear_axis (%d).",
91 if (static_cast<size_t>(angular_axis_) < msg->axes.size())
92 ang = msg->axes[angular_axis_];
94 ROS_ERROR(
"Out of range: number of axis (%lu) must be greater than angular_axis (%d).",
97 if (linear_axis2_ >= 0)
99 if (static_cast<size_t>(linear_axis2_) < msg->axes.size())
101 if (std::abs(msg->axes[linear_axis2_]) > std::abs(lin))
102 lin = msg->axes[linear_axis2_];
105 ROS_ERROR(
"Out of range: number of axis (%lu) must be greater than linear_axis2 (%d).",
108 if (angular_axis2_ >= 0)
110 if (static_cast<size_t>(angular_axis2_) < msg->axes.size())
112 if (std::abs(msg->axes[angular_axis2_]) > std::abs(ang))
113 ang = msg->axes[angular_axis2_];
116 ROS_ERROR(
"Out of range: number of axis (%lu) must be greater than angular_axis2 (%d).",
120 if (high_speed_button_ >= 0)
122 if (static_cast<size_t>(high_speed_button_) < msg->buttons.size())
124 if (msg->buttons[high_speed_button_])
131 ROS_ERROR(
"Out of range: number of buttons (%lu) must be greater than high_speed_button (%d).",
135 geometry_msgs::Twist cmd_vel;
137 cmd_vel.linear.y = cmd_vel.linear.z = 0.0;
139 cmd_vel.angular.x = cmd_vel.angular.y = 0.0;
142 void cbTwist(
const geometry_msgs::Twist::Ptr msg)
144 last_input_twist_ = *msg;
145 std_msgs::Bool status;
149 pub_twist_.
publish(last_input_twist_);
167 nh_,
"cmd_vel_input",
169 pub_twist_ = neonavigation_common::compat::advertise<geometry_msgs::Twist>(
172 pub_int_ = pnh_.advertise<std_msgs::Bool>(
"interrupt_status", 2);
174 pnh_.param(
"linear_vel", linear_vel_, 0.5);
175 pnh_.param(
"angular_vel", angular_vel_, 0.8);
176 pnh_.param(
"linear_axis", linear_axis_, 1);
177 pnh_.param(
"angular_axis", angular_axis_, 0);
178 pnh_.param(
"linear_axis2", linear_axis2_, -1);
179 pnh_.param(
"angular_axis2", angular_axis2_, -1);
180 pnh_.param(
"interrupt_button", interrupt_button_, 6);
181 pnh_.param(
"high_speed_button", high_speed_button_, -1);
182 pnh_.param(
"linear_high_speed_ratio", linear_high_speed_ratio_, 1.3);
183 pnh_.param(
"angular_high_speed_ratio", angular_high_speed_ratio_, 1.1);
184 pnh_.param(
"timeout", timeout_, 0.5);
187 if (interrupt_button_ < 0)
189 ROS_ERROR(
"interrupt_button must be grater than -1.");
193 if (linear_axis_ < 0)
195 ROS_ERROR(
"linear_axis must be grater than -1.");
199 if (angular_axis_ < 0)
201 ROS_ERROR(
"angular_axis must be grater than -1.");
208 int main(
int argc,
char* argv[])
210 ros::init(argc, argv,
"joystick_interrupt");
double linear_high_speed_ratio_
void publish(const boost::shared_ptr< M > &message) const
void cbJoy(const sensor_msgs::Joy::Ptr msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
geometry_msgs::Twist last_input_twist_
ros::Subscriber subscribe(ros::NodeHandle &nh_new, const std::string &topic_new, ros::NodeHandle &nh_old, const std::string &topic_old, uint32_t queue_size, void(*fp)(M), const ros::TransportHints &transport_hints=ros::TransportHints())
ros::Subscriber sub_twist_
int main(int argc, char *argv[])
ros::Publisher pub_twist_
double angular_high_speed_ratio_
ROSCPP_DECL void shutdown()
void cbTwist(const geometry_msgs::Twist::Ptr msg)