Skip to content

Commit

Permalink
Created Program flow and menus
Browse files Browse the repository at this point in the history
  • Loading branch information
keithmk authored and keithmk committed Feb 2, 2024
1 parent 93fd1c6 commit 99a7aa6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 22 deletions.
71 changes: 49 additions & 22 deletions mil_common/utils/mil_tools/scripts/preflight/preflight.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import subprocess

import preflight_menus
import rosnode
import rospy
import rostopic
import typer
from PyInquirer import prompt
from rich.progress import track

app = typer.Typer()

hardwareChecklist = [
{
"type": "checkbox",
"message": "Hardware Checklist:",
"name": "HardwareTests",
"name": "HardwareTests: \nPlease check that all of the following are in working order. \nYou cannot continue until everything has been checked.",
"choices": [
{"name": "check thing 1"},
{"name": "check thing 2"},
Expand All @@ -22,7 +24,7 @@
],
},
]
mechanicalChecklist = [
actuatorChecklist = [
{
"type": "list",
"message": "Select which system you want to run. BE CAREFUL make sure everyone's fingures are secured.",
Expand All @@ -43,24 +45,50 @@

nodes = ["/odom_estimator"]

run = ["/thrusters/thrust"]
actuatorsList = ["/thrusters/thrust"]


@app.command("Start")
def main():
# Display Modes/Options
subprocess.run("clear", shell=True)
mode = preflight_menus.display_start_menu()

if mode == "Run Preflight Full Test":
hardware()
software()
actuators()

# Complete the actuator tests
subprocess.run("clear", shell=True)


def hardware():
# Complete the hardware tests
subprocess.run("clear", shell=True)
answers = prompt(hardwareChecklist)
while len(answers["HardwareTests"]) != 5:
while len(next(iter(answers.values()))) != 5:
subprocess.run("clear", shell=True)
answers = prompt(hardwareChecklist)
print(answers)


@app.command("Topic")
def topic():
def software():
# Complete the software tests
subprocess.run("clear", shell=True)
rospy.init_node("preflight")

# Check Nodes
answers = []
for topic in topics:
for node in track(nodes, description="Checking Nodes..."):
try:
answers.append({node: rosnode.rosnode_ping(node, 5)})
except Exception:
answers.append({node: False})
print(answers)

# Check Topics
answers = []
for topic in track(topics, description="Checking Topics..."):
try:
topicType, topicStr, _ = rostopic.get_topic_class(topic) # get topic class
rospy.wait_for_message(
Expand All @@ -73,22 +101,21 @@ def topic():
answers.append({topic: False})
print(answers)


@app.command("Node")
def node():
rospy.init_node("preflight")
answers = []
for node in nodes:
try:
answers.append({node: rosnode.rosnode_ping(node, 5)})
except Exception:
answers.append({node: False})
print(answers)
print(
prompt(
[
{
"type": "confirm",
"name": "continue",
"message": "Continue?",
},
],
),
)


@app.command("Run")
def Run():
rospy.init_node("preflight")
def actuators():
subprocess.run("clear", shell=True)


if __name__ == "__main__":
Expand Down
42 changes: 42 additions & 0 deletions mil_common/utils/mil_tools/scripts/preflight/preflight_menus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from PyInquirer import prompt
from rich.console import Console


def display_start_menu():
console = Console()

# Title
console.print(
"[bold green]Preflight Program - Autonomous Robot Verification[/bold green]\n",
)

# Description
console.print(
"Welcome to the Preflight Program, a tool inspired by the preflight checklists used by pilots before "
"flying a plane. This program is designed to verify the functionality of all software and hardware "
"systems on your autonomous robot. It ensures that everything is in working order, allowing you to "
"safely deploy your robot with confidence.\n",
)

# Authors section
console.print("\n[italic]Authors:[/italic]")
console.print("Keith Khadar")
console.print("Anthony Liao")
console.print("Joshua Thomas\n")

# Menu options
start_menu = [
{
"type": "list",
"name": "mode selection",
"message": "Menu",
"choices": [
"Run Preflight Full Test",
"View Report",
"Run Specific Test",
"View Documentation",
],
},
]
option = prompt(start_menu)
return next(iter(option.values()))

0 comments on commit 99a7aa6

Please sign in to comment.