13def get_key(input_stream, settings, timeout):
14 tty.setraw(input_stream.fileno())
15 rlist, _, _ = select([input_stream], [], [], timeout)
16 key = input_stream.read(1)
if rlist
else ""
17 termios.tcsetattr(input_stream, termios.TCSADRAIN, settings)
38 [matrix[0][0], matrix[1][0], matrix[2][0]],
39 [matrix[0][1], matrix[1][1], matrix[2][1]],
40 [matrix[0][2], matrix[1][2], matrix[2][2]],
47 left[0][0] * right[0][0]
48 + left[0][1] * right[1][0]
49 + left[0][2] * right[2][0],
50 left[0][0] * right[0][1]
51 + left[0][1] * right[1][1]
52 + left[0][2] * right[2][1],
53 left[0][0] * right[0][2]
54 + left[0][1] * right[1][2]
55 + left[0][2] * right[2][2],
58 left[1][0] * right[0][0]
59 + left[1][1] * right[1][0]
60 + left[1][2] * right[2][0],
61 left[1][0] * right[0][1]
62 + left[1][1] * right[1][1]
63 + left[1][2] * right[2][1],
64 left[1][0] * right[0][2]
65 + left[1][1] * right[1][2]
66 + left[1][2] * right[2][2],
69 left[2][0] * right[0][0]
70 + left[2][1] * right[1][0]
71 + left[2][2] * right[2][0],
72 left[2][0] * right[0][1]
73 + left[2][1] * right[1][1]
74 + left[2][2] * right[2][1],
75 left[2][0] * right[0][2]
76 + left[2][1] * right[1][2]
77 + left[2][2] * right[2][2],
84 matrix[0][0] * vector[0] + matrix[0][1] * vector[1] + matrix[0][2] * vector[2],
85 matrix[1][0] * vector[0] + matrix[1][1] * vector[1] + matrix[1][2] * vector[2],
86 matrix[2][0] * vector[0] + matrix[2][1] * vector[1] + matrix[2][2] * vector[2],
91 sin_roll = math.sin(roll)
92 cos_roll = math.cos(roll)
93 sin_pitch = math.sin(pitch)
94 cos_pitch = math.cos(pitch)
98 gravity * sin_roll * cos_pitch,
99 gravity * cos_roll * cos_pitch,
317 rclpy.init(args=args)
320 input_stream = sys.stdin
321 input_stream_owned =
False
323 if not input_stream.isatty():
325 input_stream = open(
"/dev/tty")
326 input_stream_owned =
True
327 node.get_logger().info(
"Using /dev/tty for keyboard reset input.")
331 if input_stream
is not None and input_stream.isatty():
332 settings = termios.tcgetattr(input_stream)
334 node.get_logger().warn(
"No TTY detected; keyboard reset (R) is disabled.")
338 rclpy.spin_once(node, timeout_sec=0.05)
342 key =
get_key(input_stream, settings, 0.0)
343 if key
in (
"r",
"R"):
345 elif key ==
"q" or key ==
"\x03":
348 if settings
is not None and input_stream
is not None:
349 termios.tcsetattr(input_stream, termios.TCSADRAIN, settings)
350 if input_stream_owned
and input_stream
is not None: