-
Notifications
You must be signed in to change notification settings - Fork 0
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
System monitor node #193
Open
chrstrom
wants to merge
9
commits into
test/29.04
Choose a base branch
from
feature/system_monitor_node
base: test/29.04
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
System monitor node #193
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
719e7e1
Add initial system monitor draft and lifeycle node management
chrstrom 896e76b
Committing clang-format changes
7221427
Minor cleanup
chrstrom 921b6e5
Actually use ping rate param
chrstrom befa76d
Merge branch 'feature/system_monitor_node' of https://github.com/vort…
chrstrom 6b11ad6
Committing clang-format changes
3ac0bc4
added seapath to system monitor ip list
alekskl01 a7b6cdd
Remove setup.py and minor lifecycle callback changes
chrstrom ae04a05
Readd lost docstrings
chrstrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,34 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(system_monitor) | ||
|
||
# Find required packages | ||
find_package(ament_cmake REQUIRED) | ||
find_package(ament_cmake_python REQUIRED) | ||
find_package(rclpy REQUIRED) | ||
find_package(std_msgs REQUIRED) | ||
|
||
# Install Python modules | ||
ament_python_install_package(${PROJECT_NAME}) | ||
|
||
# Install Python executables | ||
install(PROGRAMS | ||
system_monitor/system_monitor_node.py | ||
DESTINATION lib/${PROJECT_NAME} | ||
) | ||
|
||
# Install launch and config files | ||
install(DIRECTORY | ||
config | ||
launch | ||
DESTINATION share/${PROJECT_NAME} | ||
) | ||
|
||
# Install the package.xml file | ||
install(FILES package.xml DESTINATION share/${PROJECT_NAME}) | ||
|
||
if(BUILD_TESTING) | ||
find_package(ament_lint_auto REQUIRED) | ||
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,8 @@ | ||
system_monitor: | ||
ros__parameters: | ||
ip_list: | ||
- "10.0.1.10" | ||
- "10.0.1.100" | ||
- "10.0.1.240" | ||
- "10.0.1.250" | ||
ping_rate: 1.0 |
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,24 @@ | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
from ament_index_python.packages import get_package_share_directory | ||
import os | ||
|
||
def generate_launch_description(): | ||
config = os.path.join( | ||
get_package_share_directory('system_monitor'), | ||
'config', | ||
'system_monitor_config.yaml' | ||
) | ||
|
||
system_monitor_node = Node( | ||
package='system_monitor', | ||
executable='system_monitor_node.py', | ||
name='system_monitor', | ||
output='screen', | ||
emulate_tty=True, | ||
parameters=[config] | ||
) | ||
|
||
return LaunchDescription([ | ||
system_monitor_node | ||
]) |
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,25 @@ | ||
<?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>system_monitor</name> | ||
<version>0.0.0</version> | ||
<description>A global system monitor to ensure safe autonomous operations</description> | ||
<maintainer email="[email protected]">Christopher Strøm</maintainer> | ||
<license>TODO: License declaration</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
<buildtool_depend>ament_cmake_python</buildtool_depend> | ||
|
||
<exec_depend>launch_ros</exec_depend> | ||
<exec_depend>launch</exec_depend> | ||
<exec_depend>rclpy</exec_depend> | ||
<exec_depend>std_msgs</exec_depend> | ||
|
||
<test_depend>ament_lint_auto</test_depend> | ||
<test_depend>ament_lint_common</test_depend> | ||
|
||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
Empty file.
82 changes: 82 additions & 0 deletions
82
mission/system_monitor/system_monitor/system_monitor_node.py
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,82 @@ | ||
#!/usr/bin/python3 | ||
|
||
import rclpy | ||
from rclpy.node import Node | ||
from std_msgs.msg import Float32MultiArray | ||
from lifecycle_msgs.srv import ChangeState | ||
from lifecycle_msgs.msg import Transition | ||
import os | ||
import sys | ||
|
||
class SystemMonitor(Node): | ||
def __init__(self): | ||
super().__init__('system_monitor') | ||
|
||
self.declare_parameter('ip_list', rclpy.Parameter.Type.STRING_ARRAY) | ||
self.m_ip_list = self.get_parameter('ip_list').get_parameter_value().string_array_value | ||
|
||
self.declare_parameter("ping_rate", rclpy.Parameter.Type.DOUBLE) | ||
ping_rate = self.get_parameter("ping_rate").get_parameter_value().double_value | ||
|
||
self.m_force_publisher = self.create_publisher(Float32MultiArray, '/thrust/thruster_forces', 5) | ||
self.m_timer = self.create_timer(ping_rate, self.timer_callback) | ||
|
||
self.m_allocator_lifecycle_client = self.create_client(ChangeState, '/motion/thruster_allocator_node/change_state') | ||
|
||
self.get_logger().info('SystemMonitor initialized') | ||
|
||
def timer_callback(self): | ||
all_ips_responsive = all(self.ping_ip(ip) for ip in self.m_ip_list) | ||
|
||
if not all_ips_responsive: | ||
self.get_logger().warn('One or more IPs are unresponsive. Initiating shutdown sequence.') | ||
self.shutdown_thruster_allocator() | ||
self.publish_zero_force() | ||
sys.exit(0) | ||
|
||
def ping_ip(self, ip): | ||
response = os.system(f"ping -c 1 -W 1 {ip} > /dev/null 2>&1") | ||
if response != 0: | ||
self.get_logger().error(f'Failed to ping IP: {ip}') | ||
return False | ||
return True | ||
|
||
def shutdown_thruster_allocator(self): | ||
self.get_logger().warn("Shutting down thruster allocator" | ||
" -> Manual intervention will be necessary") | ||
|
||
if not self.m_allocator_lifecycle_client.wait_for_service(timeout_sec=0.5): | ||
self.get_logger().error('Service not available') | ||
return | ||
|
||
request = ChangeState.Request() | ||
request.transition.id = Transition.TRANSITION_DEACTIVATE | ||
|
||
future = self.m_allocator_lifecycle_client.call_async(request) | ||
rclpy.spin_until_future_complete(self, future, timeout_sec=0.5) | ||
|
||
def publish_zero_force(self): | ||
self.get_logger().info('Publishing zero-force on shutdown...') | ||
message = Float32MultiArray() | ||
message.data = [0.0] * 4 | ||
self.m_force_publisher.publish(message) | ||
self.get_logger().warn('Done! Manual intervention is now required!') | ||
|
||
|
||
def main(args=None): | ||
rclpy.init(args=args) | ||
node = SystemMonitor() | ||
node.get_logger().info('Starting SystemMonitor node') | ||
|
||
try: | ||
rclpy.spin(node) | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
node.get_logger().info('SystemMonitor node shutting down') | ||
node.destroy_node() | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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
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
15 changes: 8 additions & 7 deletions
15
motion/thruster_allocator/launch/thruster_allocator.launch.py
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,19 +1,20 @@ | ||
from os import path | ||
from ament_index_python.packages import get_package_share_directory | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
from launch_ros.actions import LifecycleNode | ||
|
||
def generate_launch_description(): | ||
config = path.join(get_package_share_directory('asv_setup'),'config','robots','freya.yaml') | ||
|
||
thruster_allocator_node = Node( | ||
config = path.join(get_package_share_directory('asv_setup'), 'config', 'robots', 'freya.yaml') | ||
thruster_allocator_node = LifecycleNode( | ||
package='thruster_allocator', | ||
executable='thruster_allocator_node', | ||
name='thruster_allocator_node', | ||
namespace='motion', | ||
parameters=[config], | ||
output='screen' | ||
output='screen', | ||
) | ||
|
||
return LaunchDescription([ | ||
thruster_allocator_node | ||
]) | ||
]) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add num_thrusters as a parameter