24 #include "geometry_msgs/Twist.h" 25 #include "sensor_msgs/JoyFeedbackArray.h" 33 std::string base_name;
37 if (nh_private.
getParam(
"base", base_name))
39 ROS_INFO(
"User namespace '%s' for robot limits.", base_name.c_str());
83 if (nh_private.
hasParam(
"linear/x/throttle_percent"))
98 if (nh_private.
hasParam(
"angular/z/throttle_percent"))
125 sensor_msgs::JoyFeedbackArray joy_feedback_array;
126 sensor_msgs::JoyFeedback fb_led0;
127 sensor_msgs::JoyFeedback fb_led1;
128 sensor_msgs::JoyFeedback fb_led2;
129 sensor_msgs::JoyFeedback fb_led3;
131 fb_led0.type = sensor_msgs::JoyFeedback::TYPE_LED;
133 fb_led0.intensity = 0.0;
134 fb_led1.type = sensor_msgs::JoyFeedback::TYPE_LED;
136 fb_led1.intensity = 0.0;
137 fb_led2.type = sensor_msgs::JoyFeedback::TYPE_LED;
139 fb_led2.intensity = 0.0;
140 fb_led3.type = sensor_msgs::JoyFeedback::TYPE_LED;
142 fb_led3.intensity = 0.0;
146 fb_led0.intensity = 1.0;
150 fb_led1.intensity = 1.0;
154 fb_led2.intensity = 1.0;
158 fb_led3.intensity = 1.0;
161 joy_feedback_array.array.push_back(fb_led0);
162 joy_feedback_array.array.push_back(fb_led1);
163 joy_feedback_array.array.push_back(fb_led2);
164 joy_feedback_array.array.push_back(fb_led3);
171 sensor_msgs::JoyFeedbackArray joy_feedback_array;
172 sensor_msgs::JoyFeedback fb_rumble;
174 fb_rumble.type = sensor_msgs::JoyFeedback::TYPE_RUMBLE;
177 fb_rumble.intensity = 1.0;
179 joy_feedback_array.array.push_back(fb_rumble);
183 fb_rumble.intensity = 0.0;
185 joy_feedback_array.array.push_back(fb_rumble);
192 geometry_msgs::Twist vel;
194 static const int MSG_BTN_Z = 0;
195 static const int MSG_BTN_C = 1;
202 float x = joy->axes[0];
203 float y = joy->axes[1];
204 float const abs_error = 0.000001;
206 if (fabs(x) > abs_error || fabs(y) > abs_error)
212 ROS_INFO(
"nunchuk: x: %f, y: %f", x, y);
214 if (joy->buttons[MSG_BTN_Z] ||
215 joy->buttons[MSG_BTN_C])
218 joy->buttons[MSG_BTN_Z],
219 joy->buttons[MSG_BTN_C]);
222 if (joy->buttons[MSG_BTN_Z])
228 if (joy->buttons[MSG_BTN_C])
290 geometry_msgs::Twist vel;
292 static const int MSG_BTN_1 = 0;
293 static const int MSG_BTN_2 = 1;
294 static const int MSG_BTN_PLUS = 2;
295 static const int MSG_BTN_MINUS = 3;
296 static const int MSG_BTN_A = 4;
297 static const int MSG_BTN_B = 5;
298 static const int MSG_BTN_UP = 6;
299 static const int MSG_BTN_DOWN = 7;
300 static const int MSG_BTN_LEFT = 8;
301 static const int MSG_BTN_RIGHT = 9;
302 static const int MSG_BTN_HOME = 10;
304 static bool one_depressed =
false;
305 static bool two_depressed =
false;
306 static bool plus_depressed =
false;
307 static bool minus_depressed =
false;
308 static bool home_depressed =
false;
317 if (wiistate->buttons[MSG_BTN_1])
319 if (wiistate->buttons[MSG_BTN_PLUS])
329 plus_depressed =
true;
339 plus_depressed =
false;
341 if (wiistate->buttons[MSG_BTN_MINUS])
343 if (!minus_depressed)
351 minus_depressed =
true;
361 minus_depressed =
false;
372 one_depressed =
true;
377 else if (wiistate->buttons[MSG_BTN_2])
379 if (wiistate->buttons[MSG_BTN_PLUS])
389 plus_depressed =
true;
399 plus_depressed =
false;
401 if (wiistate->buttons[MSG_BTN_MINUS])
403 if (!minus_depressed)
411 minus_depressed =
true;
421 minus_depressed =
false;
432 two_depressed =
true;
437 if (one_depressed || two_depressed)
442 one_depressed =
false;
443 two_depressed =
false;
448 if (wiistate->buttons[MSG_BTN_HOME])
452 ROS_INFO(
"Battery[]: raw: %f, percent: %f", wiistate->raw_battery, wiistate->percent_battery);
454 home_depressed =
true;
464 home_depressed =
false;
469 (wiistate->buttons[MSG_BTN_RIGHT] ||
470 wiistate->buttons[MSG_BTN_LEFT] ||
471 wiistate->buttons[MSG_BTN_UP] ||
472 wiistate->buttons[MSG_BTN_DOWN]))
476 ROS_INFO(
"buttons[]: Right: %d, Left: %d, Up: %d, Down: %d, A: %d, B: %d",
477 wiistate->buttons[MSG_BTN_RIGHT],
478 wiistate->buttons[MSG_BTN_LEFT],
479 wiistate->buttons[MSG_BTN_UP],
480 wiistate->buttons[MSG_BTN_DOWN],
481 wiistate->buttons[MSG_BTN_A],
482 wiistate->buttons[MSG_BTN_B]);
487 if (wiistate->buttons[MSG_BTN_B])
493 if (wiistate->buttons[MSG_BTN_A])
498 if (wiistate->buttons[MSG_BTN_UP])
503 else if (wiistate->buttons[MSG_BTN_DOWN])
509 if (wiistate->buttons[MSG_BTN_LEFT])
514 else if (wiistate->buttons[MSG_BTN_RIGHT])
532 int main(
int argc,
char** argv)
void joyCallback(const sensor_msgs::Joy::ConstPtr &joy)
#define DEFAULT_MAX_LINEAR_X
void publish(const boost::shared_ptr< M > &message) const
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)
double linear_x_min_velocity_
void wiimoteStateCallback(const wiimote::State::ConstPtr &wiistate)
double linear_x_max_velocity_
void rumbleFeedback(int useconds)
void setLEDFeedback(double value)
ros::Subscriber wiimote_sub_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
double angular_z_max_velocity_
double percent_angular_throttle_
int main(int argc, char **argv)
bool getParam(const std::string &key, std::string &s) const
#define DEFAULT_PERCENT_LINEAR_THROTTLE
double angular_z_min_velocity_
bool hasParam(const std::string &key) const
#define DEFAULT_MAX_ANGULAR_Z
double percent_linear_throttle_
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
#define DEFAULT_PERCENT_ANGULAR_THROTTLE