Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heartbeat #2

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
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
59 changes: 59 additions & 0 deletions rb_ws/src/buggy/buggy/watchdog/watchdog_node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import rclpy
from rclpy.node import Node

from std_msgs.msg import Bool

class Watchdog(Node):

def __init__(self):
"""
Constructor for Watchdog class.

Creates a ROS node with a publisher that periodically sends a message
indicating whether the node is still alive.

"""
super().__init__('watchdog')

# Publishers
self.heartbeat_publisher = self.create_publisher(Bool, 'self/debug/heartbeat', 1)

# Subscribers
self.heartbeat_subscriber = self.create_subscription(Bool, 'self/debug/heartbeat', self.heartbeat_listener, 1)

timer_period = 0.01 # seconds (100 Hz)
self.timer = self.create_timer(timer_period, self.loop)
self.i = 0 # Loop Counter

def loop(self):
# Loop for the code that operates every 10ms
msg = Bool()
msg.data = True
self.heartbeat_publisher.publish(msg)

def heartbeat_listener(self, msg : Node):
"""
Subscriber Function that checks if Heartbeat is ever alse
It never actually is false, this is just a demonstration of a subscriber
If it ever actually is false, something cursed has happened
"""
if msg.data == False:
self.get_logger().error("Hearbeat Failed!")


def main(args=None):
rclpy.init(args=args)

watchdog = Watchdog()

rclpy.spin(watchdog)

# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
watchdog.destroy_node()
rclpy.shutdown()


if __name__ == '__main__':
main()
4 changes: 4 additions & 0 deletions rb_ws/src/buggy/launch/watchdog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<launch>
<node pkg="foxglove_bridge" exec="foxglove_bridge" name="foxglove" namespace="SC"/>
<node pkg="buggy" exec="watchdog" name="SC_watchdog" namespace="SC"/>
</launch>
7 changes: 4 additions & 3 deletions rb_ws/src/buggy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
(os.path.join("share", package_name), glob("launch/*.xml")),
(os.path.join("share", package_name), glob("launch/*.xml"))
],
install_requires=['setuptools'],
zip_safe=True,
Expand All @@ -24,7 +24,8 @@
tests_require=['pytest'],
entry_points={
'console_scripts': [
'hello_world = buggy.hello_world:main'
'hello_world = buggy.hello_world:main',
'watchdog = buggy.watchdog.watchdog_node:main'
],
},
)
)
Loading