src
joy_teleop.cpp
Go to the documentation of this file.
1
/*
2
3
Copyright (c) 2021, Botsync Pte. Ltd.
4
All rights reserved.
5
6
Redistribution and use in source and binary forms, with or without
7
modification, are permitted provided that the following conditions are met:
8
* Redistributions of source code must retain the above copyright
9
notice, this list of conditions and the following disclaimer.
10
* Redistributions in binary form must reproduce the above copyright
11
notice, this list of conditions and the following disclaimer in the
12
documentation and/or other materials provided with the distribution.
13
* Neither the name of the Botsync Pte. Ltd. nor the
14
names of its contributors may be used to endorse or promote products
15
derived from this software without specific prior written permission.
16
17
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
*/
29
30
#include <
volta_teleoperator/joy_teleop.h
>
31
32
void
joy_callback
(
const
sensor_msgs::Joy::ConstPtr& joy) {
33
geometry_msgs::Twist cmd;
34
35
if
(
enable_e_stop
&& joy->buttons[
e_stop_button
] && !
e_stop_status
) {
36
std_msgs::Bool e_stop_msg;
37
38
e_stop_msg.data =
true
;
39
e_stop_status
=
true
;
40
41
// Publish 0 velocity
42
cmd.linear.x = 0.0;
43
cmd.linear.y = 0.0;
44
cmd.linear.z = 0.0;
45
cmd.angular.x = 0.0;
46
cmd.angular.y = 0.0;
47
cmd.angular.z = 0.0;
48
49
e_stop_pub
.
publish
(e_stop_msg);
50
}
else
if
(
enable_e_stop
&& joy->buttons[
e_stop_button
] &&
e_stop_status
) {
51
std_msgs::Bool e_stop_msg;
52
53
e_stop_msg.data =
false
;
54
e_stop_status
=
false
;
55
56
// Publish 0 velocity
57
cmd.linear.x = 0.0;
58
cmd.linear.y = 0.0;
59
cmd.linear.z = 0.0;
60
cmd.angular.x = 0.0;
61
cmd.angular.y = 0.0;
62
cmd.angular.z = 0.0;
63
64
e_stop_pub
.
publish
(e_stop_msg);
65
}
else
if
(joy->buttons[
stop_button
]) {
66
// Publish 0 velocity
67
cmd.linear.x = 0.0;
68
cmd.linear.y = 0.0;
69
cmd.linear.z = 0.0;
70
cmd.angular.x = 0.0;
71
cmd.angular.y = 0.0;
72
cmd.angular.z = 0.0;
73
74
}
else
if
(joy->buttons[
enable_button
]) {
75
cmd.linear.x =
max_linear_speed
* joy->axes[
linear_speed_axis
];
76
cmd.linear.y = 0.0;
77
cmd.linear.z = 0.0;
78
cmd.angular.x = 0.0;
79
cmd.angular.y = 0.0;
80
cmd.angular.z =
max_angular_speed
* joy->axes[
angular_speed_axis
];
81
dead_man
=
true
;
82
cmd_to_send
= cmd;
83
84
}
else
{
85
cmd.linear.x = 0.0;
86
cmd.linear.y = 0.0;
87
cmd.linear.z = 0.0;
88
cmd.angular.x = 0.0;
89
cmd.angular.y = 0.0;
90
cmd.angular.z = 0.0;
91
dead_man
=
false
;
92
}
93
94
cmd_vel_pub
.
publish
(cmd);
95
}
max_linear_speed
double max_linear_speed
Definition:
joy_teleop.h:45
angular_speed_axis
int angular_speed_axis
Definition:
joy_teleop.h:41
cmd_vel_pub
ros::Publisher cmd_vel_pub
Definition:
joy_teleop.h:50
joy_callback
void joy_callback(const sensor_msgs::Joy::ConstPtr &joy)
Definition:
joy_teleop.cpp:32
dead_man
bool dead_man
Definition:
joy_teleop.h:53
linear_speed_axis
int linear_speed_axis
Definition:
joy_teleop.h:40
enable_button
int enable_button
Definition:
joy_teleop.h:37
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
max_angular_speed
double max_angular_speed
Definition:
joy_teleop.h:46
e_stop_pub
ros::Publisher e_stop_pub
Definition:
joy_teleop.h:51
enable_e_stop
int enable_e_stop
Definition:
joy_teleop.h:43
stop_button
int stop_button
Definition:
joy_teleop.h:38
e_stop_button
int e_stop_button
Definition:
joy_teleop.h:39
joy_teleop.h
e_stop_status
bool e_stop_status
Definition:
joy_teleop.h:35
cmd_to_send
geometry_msgs::Twist cmd_to_send
Definition:
joy_teleop.h:54
volta_teleoperator
Author(s): Nikhil Venkatesh
, Mahendra L Seervi
autogenerated on Wed Mar 2 2022 01:13:34