-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.idea | ||
build | ||
install | ||
utils | ||
log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
cmake_minimum_required(VERSION 3.8) | ||
project(utils) | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
# find dependencies | ||
find_package(ament_cmake REQUIRED) | ||
find_package(ament_cmake_python REQUIRED) | ||
find_package(rclpy REQUIRED) | ||
|
||
ament_python_install_package(${PROJECT_NAME}) | ||
|
||
install(PROGRAMS | ||
utils/heartbeat_helper.py | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
# uncomment the following section in order to fill in | ||
# further dependencies manually. | ||
# find_package(<dependency> REQUIRED) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
# the following line skips the linter which checks for copyrights | ||
# comment the line when a copyright and license is added to all source files | ||
set(ament_cmake_copyright_FOUND TRUE) | ||
# the following line skips cpplint (only works in a git repo) | ||
# comment the line when this package is in a git repo and when | ||
# a copyright and license is added to all source files | ||
set(ament_cmake_cpplint_FOUND TRUE) | ||
ament_lint_auto_find_test_dependencies() | ||
endif() | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>utils</name> | ||
<version>0.0.0</version> | ||
<description>TODO: Package description</description> | ||
<maintainer email="akahl@purdue.edu">adam</maintainer> | ||
<license>TODO: License declaration</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<buildtool_depend>ament_cmake_python</buildtool_depend> | ||
<buildtool_depend>rosidl_default_generators</buildtool_depend> | ||
|
||
<depend>rclpy</depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
<exec_depend>builtin_interfaces</exec_depend> | ||
<exec_depend>rosidl_default_generators</exec_depend> | ||
|
||
<member_of_group>rosidl_interface_packages</member_of_group> | ||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#! /usr/bin/python3 | ||
|
||
from rclpy.node import Node | ||
from std_msgs.msg import Header | ||
|
||
class HeartbeatHelper: | ||
def __init__(self, node: Node, topic_name="heartbeat", timer_period=5.0): | ||
"""This class is used to publish a heartbeat message on a given topic at a given interval""" | ||
self.timer_period = timer_period | ||
self.node = node | ||
self.publisher = self.node.create_publisher(Header, topic_name, 10) | ||
self.timer = self.node.create_timer(timer_period, self.publish_heartbeat) | ||
|
||
def publish_heartbeat(self): | ||
"""Publish a heartbeat message on the topic""" | ||
self.node.get_logger().info("Publishing heartbeat from {}".format(self.node.get_name())) | ||
msg = Header() | ||
msg.stamp = self.node.get_clock().now().to_msg() | ||
msg.frame_id = self.node.get_name() | ||
self.publisher.publish(msg) | ||
|
||
def stop_heartbeat(self): | ||
"""Stop the heartbeat timer""" | ||
self.timer.cancel() | ||
self.node.destroy_publisher(self.publisher) | ||
self.node.get_logger().info(f'Heartbeat stopped for {self.node.get_name()}') | ||
|
||
def start_heartbeat(self): | ||
"""Start the heartbeat timer""" | ||
self.timer = self.node.create_timer(self.timer_period, self.publish_heartbeat) | ||
self.node.get_logger().info(f'Heartbeat started for {self.node.get_name()}') |
File renamed without changes.