Skip to content

Commit

Permalink
Finished implementing axros
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmk authored and keithmk committed Mar 18, 2024
1 parent 270a1cc commit 3ef5592
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
81 changes: 51 additions & 30 deletions mil_common/utils/mil_tools/scripts/mil-preflight/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import asyncio
import subprocess
import time
from contextlib import suppress
from pathlib import Path

import menus
Expand All @@ -18,7 +19,7 @@
import rospy
import rostopic
import tests
from axros import NodeHandle, Subscriber
from axros import NodeHandle
from PyInquirer import prompt
from rich.console import Console
from rich.markdown import Markdown
Expand All @@ -30,7 +31,6 @@


report = []
nh = NodeHandle.from_argv("Preflight_nh", "", anonymous=True)


# ----- Main Routine ----- #
Expand Down Expand Up @@ -111,17 +111,19 @@ async def fullTest():
return

# Initialize the ROS node
rospy.init_node("preflight")
with suppress(Exception):
rospy.init_node("preflight")

# Print Node Screen description
Console().print(menus.node_desc)

# Check Nodes

# Setup AXROS
nh = NodeHandle.from_argv("Preflight_nh", "", anonymous=True)
async with nh:
answers = []
tasks = [check_node(node, answers) for node in tests.nodes]
tasks = [check_node(node, answers, nh) for node in tests.nodes]
for task in track(
asyncio.as_completed(tasks),
description="Checking Nodes...",
Expand All @@ -130,7 +132,7 @@ async def fullTest():
await task

# Clear the screen, print and save the response to the report
# print_results(answers, "Node Liveliness")
print_results(answers, "Node Liveliness")

# Prompt the user to continue to next test
menu_ans = prompt(menus.continue_question)
Expand All @@ -143,10 +145,18 @@ async def fullTest():
Console().print(menus.topic_desc)

# Check Topics
answers = []
for topic in track(tests.topics, description="Checking Topics..."):
# Check for messages on the topics
await check_topic(topic, answers)

# Setup AXROS
nh = NodeHandle.from_argv("Preflight_nh", "", anonymous=True)
async with nh:
answers = []
tasks = [check_topic(node, answers, nh) for node in tests.topics]
for task in track(
asyncio.as_completed(tasks),
description="Checking Topics...",
total=len(tasks),
):
await task

# Clear the screen, print and save the response to the report
print_results(answers, "Topic Liveliness")
Expand Down Expand Up @@ -188,7 +198,8 @@ async def specificTest():
return

# Initialize the ROS node
rospy.init_node("preflight")
with suppress(Exception):
rospy.init_node("preflight")

# Clear the screen and display the node checklist
clear_screen()
Expand All @@ -205,10 +216,16 @@ async def specificTest():
Console().print(menus.node_desc)

# Check Nodes
answers = []
for node in track(nodes, description="Checking Nodes..."):
# Try and ping the nodes
await check_node(node, answers)
nh = NodeHandle.from_argv("Preflight_nh", "", anonymous=True)
async with nh:
answers = []
tasks = [check_node(node, answers, nh) for node in nodes]
for task in track(
asyncio.as_completed(tasks),
description="Checking Nodes...",
total=len(tasks),
):
await task

# Clear the screen, print and save the response to the report
print_results(answers, "Node Liveliness")
Expand All @@ -235,10 +252,16 @@ async def specificTest():
Console().print(menus.topic_desc)

# Check Topics
answers = []
for topic in track(topics, description="Checking Topics..."):
# Check for messages on the topics
await check_topic(topic, answers)
nh = NodeHandle.from_argv("Preflight_nh", "", anonymous=True)
async with nh:
answers = []
tasks = [check_topic(node, answers, nh) for node in topics]
for task in track(
asyncio.as_completed(tasks),
description="Checking Topics...",
total=len(tasks),
):
await task

# Clear the screen, print and save the response to the report
print_results(answers, "Topic Liveliness")
Expand Down Expand Up @@ -337,25 +360,23 @@ def clear_screen():
Console().print(menus.title)


async def check_node(node, results):
async def check_node(node, results, nh):
try:
print(node)
print(nh.lookup_node(node))
results.append((node, bool(nh.lookup_node(node))))
results.append((node, bool(await nh.lookup_node(node))))
except Exception:
results.append((node, False))


async def check_topic(topic, results):
try:
topicType, topicStr, _ = rostopic.get_topic_class(topic) # get topic class
sub = Subscriber(nh, topicStr, topicType)
async def check_topic(topic, results, nh):
topicType, topicStr, _ = rostopic.get_topic_class(topic) # get topic class
sub = nh.subscribe(topicStr, topicType)

async with sub:
async with sub:
try:
await asyncio.wait_for(sub.get_next_message(), tests.topic_timeout)
results.append((topic, True))
except Exception:
results.append((topic, False))
results.append((topic, True))
except Exception:
results.append((topic, False))


def check_actuator(actuator, results):
Expand Down
2 changes: 1 addition & 1 deletion mil_common/utils/mil_tools/scripts/mil-preflight/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"/odom_estimator",
"/odom_estimator",
"/odom_estimator",
"/odom_estimator",
"/doest_exist",
]

# ----- Topics -----#
Expand Down

0 comments on commit 3ef5592

Please sign in to comment.