scripts
undock_on_button.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (c) 2015, Fetch Robotics Inc.
4
# Author: Michael Ferguson
5
6
import
rospy
7
import
actionlib
8
from
sensor_msgs.msg
import
Joy
9
from
fetch_auto_dock_msgs.msg
import
UndockAction, UndockGoal
10
11
# Listen to joy messages, when button held, undock
12
class
UndockTeleop
:
13
ACTION_NAME =
"/undock"
14
15
def
__init__
(self):
16
rospy.loginfo(
"Connecting to %s..."
% self.
ACTION_NAME
)
17
self.
client
=
actionlib.SimpleActionClient
(self.
ACTION_NAME
, UndockAction)
18
self.
client
.wait_for_server()
19
rospy.loginfo(
"Done."
)
20
21
self.
dock_button
= rospy.get_param(
"~undock_button"
, 15)
# default button is the square
22
23
self.
pressed
=
False
24
self.
pressed_last
=
None
25
26
self.
joy_sub
= rospy.Subscriber(
"joy"
, Joy, self.
joy_callback
)
27
28
def
joy_callback
(self, msg):
29
try
:
30
if
msg.buttons[self.
dock_button
] > 0:
31
if
not
self.
pressed
:
32
self.
pressed_last
= rospy.Time.now()
33
self.
pressed
=
True
34
elif
self.
pressed_last
and
rospy.Time.now() > self.
pressed_last
+ rospy.Duration(1.0):
35
self.
reset
()
36
self.
pressed_last
=
None
37
else
:
38
self.
pressed
=
False
39
except
IndexError:
40
rospy.logwarn(
"undock_button is out of range"
)
41
42
def
reset
(self):
43
goal = UndockGoal()
44
goal.rotate_in_place =
True
45
self.
client
.send_goal(goal)
46
47
if
__name__ ==
"__main__"
:
48
rospy.init_node(
"undock_on_button"
)
49
c =
UndockTeleop
()
50
rospy.spin()
undock_on_button.UndockTeleop.reset
def reset(self)
Definition:
undock_on_button.py:42
undock_on_button.UndockTeleop.__init__
def __init__(self)
Definition:
undock_on_button.py:15
undock_on_button.UndockTeleop.dock_button
dock_button
Definition:
undock_on_button.py:21
undock_on_button.UndockTeleop
Definition:
undock_on_button.py:12
actionlib::SimpleActionClient
undock_on_button.UndockTeleop.client
client
Definition:
undock_on_button.py:17
undock_on_button.UndockTeleop.pressed
pressed
Definition:
undock_on_button.py:23
undock_on_button.UndockTeleop.pressed_last
pressed_last
Definition:
undock_on_button.py:24
undock_on_button.UndockTeleop.joy_sub
joy_sub
Definition:
undock_on_button.py:26
undock_on_button.UndockTeleop.joy_callback
def joy_callback(self, msg)
Definition:
undock_on_button.py:28
undock_on_button.UndockTeleop.ACTION_NAME
string ACTION_NAME
Definition:
undock_on_button.py:13
fetch_open_auto_dock
Author(s): Michael Ferguson, Griswald Brooks
autogenerated on Mon Feb 28 2022 22:21:37