4 Control of the robot with keyboad. 5 Based on https://github.com/ros-teleop 8 from __future__
import print_function
10 from mf_robot_simulator.msg
import Command, CartesianCommand
11 import sys, select, termios, tty
14 --------------------------- 22 q/z : increase/decrease max speeds by 10% 26 moveKeys = [
'i',
'j',
'k',
'l',
'p',
'm',
'u', 'o', '
r', 't', 'y',
41 tty.setraw(sys.stdin.fileno())
42 rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
47 key = sys.stdin.read(1)
48 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
56 return "currently:\tspeed %s " % (speed)
59 if __name__==
"__main__":
60 settings = termios.tcgetattr(sys.stdin)
62 rospy.init_node(
'keyboard_teleop')
63 pub = rospy.Publisher(
'command', Command, queue_size = 1)
64 cart_pub = rospy.Publisher(
'cart_command', CartesianCommand, queue_size = 1)
66 speed = rospy.get_param(
"~init_speed", 0.5)
67 init_cmd_vx = rospy.get_param(
"~init_cmd_vx", 1.0)
68 init_cmd_vy = rospy.get_param(
"~init_cmd_vy", 1.0)
69 init_cmd_vz = rospy.get_param(
"~init_cmd_vz", 1.0)
70 speed = rospy.get_param(
"~init_speed", 0.5)
71 speed = rospy.get_param(
"~init_speed", 0.5)
72 inc_delta = rospy.get_param(
"~inc_delta", 0.1)
73 inc_P = rospy.get_param(
"~inc_P", 0.1)
134 print(
"n={:.1f} ; delta_r={:.2f} ; delta_e={:.2f} ; P={:.3f}".format(
135 n, delta_r, delta_e, P))
137 elif key
in speedBindings.keys():
138 speed = speed * speedBindings[key][0]
139 v_x = v_x * speedBindings[key][0]
140 v_y = v_y * speedBindings[key][0]
141 v_z = v_z * speedBindings[key][0]
157 command.delta_r = delta_r
158 command.delta_e = delta_e
162 cart_command = CartesianCommand()
163 cart_command.v_x = v_x
164 cart_command.v_y = v_y
165 cart_command.v_z = v_z
166 cart_pub.publish(cart_command)
168 except Exception
as e:
175 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)