uos_diffdrive_teleop_wiimote.cpp
Go to the documentation of this file.
1 /*This program will run the robot in three different speeds
2  The buttons array shows which buttons are currently depressed on the Wiimote device.
3  The position mapping is as follows:
4  Position Button Name
5  0 1
6  1 2
7  2 A
8  3 B (toggle button on back of device)
9  4 Plus
10  5 Minus
11  6 Rocker Left
12  7 Rocker Right
13  8 Rocker Up
14  9 Rocker Down
15  10 HOME
16  */
17 #include <ros/ros.h>
18 #include <geometry_msgs/Twist.h>
19 #include <sensor_msgs/Joy.h>
20 
23 
24 void ps3joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
25 {
26  geometry_msgs::Twist vel;
27 
28  int c = 0; // assigning three cases based on three buttons on the wii remote
29  if (joy->buttons[0])
30  c = 1;
31  else if (joy->buttons[1])
32  c = 2;
33  else if (joy->buttons[3])
34  c = 3;
35 
36  //choosing speed and assigning it to max_vel
37  switch (c)
38  {
39  case 1:
40  max_vel_x = 0.1;
41  break;
42  case 2:
43  max_vel_x = 0.5;
44  break;
45  case 3:
46  max_vel_x = 1.5;
47  break;
48  }
49 
50  // assigning x and z value in the Twist message
51  if (joy->buttons[8])
52  {
53  vel.linear.x = max_vel_x;
54  }
55  else if (joy->buttons[9])
56  {
57  vel.linear.x = -max_vel_x;
58  }
59  else if (joy->buttons[6])
60  {
61  vel.angular.z = max_rotational_vel;
62  }
63  else if (joy->buttons[7])
64  {
65  vel.angular.z = -max_rotational_vel;
66  }
67  else
68 
69  {
70  vel.linear.x = 0;
71  vel.angular.z = 0;
72  }
73 
74  vel_pub.publish(vel);
75 }
76 
77 int main(int argc, char** argv)
78 {
79  ros::init(argc, argv, "uos_diffdrive_teleop_wiimote");
80 
81  ros::NodeHandle nh;
82  ros::NodeHandle nh_ns("~");
83 
84  nh_ns.param("max_vel_x", max_vel_x, 1.5);
85  nh_ns.param("max_rotational_vel", max_rotational_vel, 1.5);
86 
87  vel_pub = nh.advertise<geometry_msgs::Twist>("cmd_vel", 1);
88  ros::Subscriber ps3joy_sub = nh.subscribe("joy", 10, ps3joyCallback);
89 
90  ros::spin();
91 }
92 
void ps3joyCallback(const sensor_msgs::Joy::ConstPtr &joy)
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)
int main(int argc, char **argv)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ROSCPP_DECL void spin()
double max_rotational_vel
ros::Publisher vel_pub


uos_diffdrive_teleop
Author(s): Jochen Sprickerhof, Sebastian Pütz
autogenerated on Mon Jun 10 2019 15:49:27