14 from geometry_msgs.msg
import Twist
18 def __init__(self, min_velocity, max_velocity, num_steps):
19 assert min_velocity > 0
and max_velocity > 0
and num_steps > 0
31 Takes a value in the range [0, 1] and the step and returns the
32 velocity (usually m/s or rad/s).
39 return value * max_value
56 return keycode
if keycode != -1
else None
63 raise ValueError(
'lineno out of bounds')
64 height, width = self.
_screen.getmaxyx()
67 for text
in message.split(
'\n'):
68 text = text.ljust(width)
87 self.
_pub_cmd = rospy.Publisher(
'key_vel', Twist)
89 self.
_hz = rospy.get_param(
'~hz', 10)
93 forward_min = rospy.get_param(
'~turbo/linear_forward_min', 0.5)
94 forward_max = rospy.get_param(
'~turbo/linear_forward_max', 1.0)
97 backward_min = rospy.get_param(
'~turbo/linear_backward_min', 0.25)
98 backward_max = rospy.get_param(
'~turbo/linear_backward_max', 0.5)
101 angular_min = rospy.get_param(
'~turbo/angular_min', 0.7)
102 angular_max = rospy.get_param(
'~turbo/angular_max', 1.2)
109 rate = rospy.Rate(self.
_hz)
122 twist.linear.x = self.
_forward(1.0, linear)
124 twist.linear.x = self.
_backward(-1.0, -linear)
125 twist.angular.z = self.
_rotation(math.copysign(1, angular), abs(angular))
129 movement_bindings = {
130 curses.KEY_UP: ( 1, 0),
131 curses.KEY_DOWN: (-1, 0),
132 curses.KEY_LEFT: ( 0, 1),
133 curses.KEY_RIGHT: ( 0, -1),
138 if keycode
in movement_bindings:
139 acc = movement_bindings[keycode]
153 elif keycode
in speed_bindings:
154 acc = speed_bindings[keycode]
156 if acc[0]
is not None:
158 if acc[1]
is not None:
161 elif keycode == ord(
'q'):
162 rospy.signal_shutdown(
'Bye')
171 self.
_interface.write_line(5,
'Use arrow keys to move, space to stop, q to exit.')
183 self.
_hz = rospy.get_param(
'~hz', 10)
192 movement_bindings = {
193 curses.KEY_UP: ( 1, 0),
194 curses.KEY_DOWN: (-1, 0),
195 curses.KEY_LEFT: ( 0, 1),
196 curses.KEY_RIGHT: ( 0, -1),
200 rate = rospy.Rate(self.
_hz)
214 twist.linear.x = linear
215 twist.angular.z = angular
219 now = rospy.get_time()
239 if keycode == ord(
'q'):
241 rospy.signal_shutdown(
'Bye')
248 self.
_interface.write_line(5,
'Use arrow keys to move, q to exit.')
256 rospy.init_node(
'key_teleop')
260 if __name__ ==
'__main__':
263 except rospy.ROSInterruptException: