Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions models/dave_robot_models/scripts/keyboard_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tty

import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
from sensor_msgs.msg import Joy

Expand Down Expand Up @@ -55,13 +56,18 @@ def __init__(self):

self.timer = self.create_timer(1.0 / PUBLISH_HZ, self.on_timer)

self.get_logger().info(
"Keyboard teleop ready on "
f"{output_topic} | "
"c: arm, x: disarm, w/s: forward/back, "
"a/d: yaw, r/f: ascend/descend, "
"h: ALT_HOLD, j: STABILIZE, space: stop, q: quit"
)
if self.input_stream is not None:
self.get_logger().info(
"Keyboard teleop ready on "
f"{output_topic} | "
"c: arm, x: disarm, w/s: forward/back, "
"a/d: yaw, r/f: ascend/descend, "
"h: ALT_HOLD, j: STABILIZE, space: stop, q: quit"
)
else:
self.get_logger().info(
"Keyboard teleop disabled because no interactive TTY is available"
)

def _open_input_stream(self):
if sys.stdin.isatty():
Expand All @@ -71,7 +77,7 @@ def _open_input_stream(self):
# Use unbuffered binary mode for reliable single-key reads.
return open("/dev/tty", "rb", buffering=0)
except OSError as exc:
self.get_logger().warn(
self.get_logger().warning(
"No interactive TTY for keyboard teleop " f"({exc}). Run launch from a terminal."
)
return None
Expand Down Expand Up @@ -188,8 +194,11 @@ def main():

try:
rclpy.spin(node)
except KeyboardInterrupt:
except (KeyboardInterrupt, ExternalShutdownException):
pass
except RuntimeError:
if rclpy.ok():
raise
finally:
node.destroy_node()
if rclpy.ok():
Expand Down
Loading