uos_diffdrive_teleop_ps3joy.cpp
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2015 University of Osnabrück, Germany
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * uos_diffdrive_teleop_ps3.cpp
20  *
21  * Created on: 16.02.2015
22  * Author: Sebastian Pütz <spuetz@uos.de>
23  */
24 
26 
28  ros::NodeHandle n_private("~");
29  //enable button pressure intensity
30  n_private.param("use_button_pressure", use_button_pressure, false);
31  joy_sub = n_.subscribe<sensor_msgs::Joy>("joy", 15, &TeleopPS3::PS3Callback, this);
32 }
33 
34 void TeleopPS3::PS3Callback(const sensor_msgs::Joy::ConstPtr& joy) {
35 
36  // factor elem of [0 1]
37  double factor_x = 0;
38  double factor_y = 0;
39  double fac_button_x = 0;
40  double fac_button_y = 0;
41 
42  // read the stick intensity factor
43  double fac_stick_y = joy->axes[PS3_AXIS_STICK_LEFT_UPWARDS];
44  double fac_stick_x = joy->axes[PS3_AXIS_STICK_LEFT_LEFTWARDS];
45 
46  // if required, read the button pressure as intensity factor
48  // left, normalize scale
49  double fac_button_up = (1-joy->axes[PS3_AXIS_BUTTON_CROSS_UP])/2.0;
50  double fac_button_down = -(1-joy->axes[PS3_AXIS_BUTTON_CROSS_DOWN])/2.0;
51  fac_button_y = fac_button_up + fac_button_down;
52  // right, normalize scale
53  double fac_button_left = (1-joy->axes[PS3_AXIS_BUTTON_CROSS_LEFT])/2.0;
54  double fac_button_right = -(1-joy->axes[PS3_AXIS_BUTTON_CROSS_RIGHT])/2.0;
55  fac_button_x = fac_button_left + fac_button_right;
56  } else {
57  // no button pressure required, check if the factor should be 1 or 0
58  // if there is no button pressure enabled the factor should be 1
59  fac_button_y = joy->buttons[PS3_BUTTON_CROSS_UP] - joy->buttons[PS3_BUTTON_CROSS_DOWN];
60  fac_button_x = joy->buttons[PS3_BUTTON_CROSS_LEFT] - joy->buttons[PS3_BUTTON_CROSS_RIGHT];
61  }
62  // enable both, stick and buttons at the same time
63  factor_x = fac_button_x + fac_stick_x; // can be > 1 or < -1
64  factor_y = fac_button_y + fac_stick_y; // can be > 1 or < -1
65 
66  in.forwards = factor_y;
67  in.left = factor_x;
68  in.updated = true;
69 }
70 
71 int main(int argc, char** argv)
72 {
73  ros::init(argc, argv, "uos_diffdrive_teleop_ps3");
74  TeleopPS3 teleop;
75  ros::spin();
76  return EXIT_SUCCESS;
77 }
#define PS3_AXIS_STICK_LEFT_LEFTWARDS
#define PS3_BUTTON_CROSS_LEFT
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
#define PS3_BUTTON_CROSS_RIGHT
#define PS3_BUTTON_CROSS_UP
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ros::NodeHandle n_
#define PS3_AXIS_STICK_LEFT_UPWARDS
#define PS3_AXIS_BUTTON_CROSS_DOWN
bool param(const std::string &param_name, T &param_val, const T &default_val) const
#define PS3_BUTTON_CROSS_DOWN
ROSCPP_DECL void spin()
#define PS3_AXIS_BUTTON_CROSS_UP
#define PS3_AXIS_BUTTON_CROSS_LEFT
ros::Subscriber joy_sub
int main(int argc, char **argv)
#define PS3_AXIS_BUTTON_CROSS_RIGHT
void PS3Callback(const sensor_msgs::Joy::ConstPtr &joy)


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