Skip to content

Commit

Permalink
Fix State Visualizer For New State Lib (#696)
Browse files Browse the repository at this point in the history
* Try to update cameras

* New joint_c config

* added bitset

* Backup moteus config for back left

* New State Machine Visualizer

* Fixed Launchfile

* Removed stuff from autonomy.launch; sim no luanhc tho

* restore moteus configs

* fix world mesh

---------

Co-authored-by: umroverPerception <[email protected]>
Co-authored-by: MRover Laptop <[email protected]>
Co-authored-by: Alison Ryckman <[email protected]>
  • Loading branch information
4 people authored Jul 11, 2024
1 parent 272e3a2 commit 90795b2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
31 changes: 16 additions & 15 deletions scripts/visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

import rospy
import sys
from smach_msgs.msg import SmachContainerStatus, SmachContainerStructure
from mrover.msg import StateMachineStructure, StateMachineStateUpdate
from threading import Lock
from dataclasses import dataclass
from typing import Optional, List, Dict


STRUCTURE_TOPIC = "/smach/container_structure"
STATUS_TOPIC = "/smach/container_status"
STRUCTURE_TOPIC = "nav_structure"
STATUS_TOPIC = "nav_state"


@dataclass
Expand All @@ -30,7 +30,7 @@ class State:
class StateMachine:
def __init__(self):
self.states: Dict[str, State] = {}
self.structure: Optional[SmachContainerStructure] = None
self.structure: Optional[StateMachineStructure] = None
self.mutex: Lock = Lock()
self.cur_active: str = ""
self.previous_state: str = ""
Expand All @@ -50,17 +50,18 @@ def set_active_state(self, active_state):
f"Current time: {now} Previous state: {self.previous_state} Current State: { self.cur_active}"
)

def _rebuild(self, structure: SmachContainerStructure):
def _rebuild(self, structure: StateMachineStructure):
"""
rebuilds the state dictionary with a new structure message
"""
self.states = {child: State(child, []) for child in structure.children}
for start, end in zip(structure.outcomes_from, structure.outcomes_to):
if end != "None":
self.states[start].children.append(self.states[end])
self.states = {child.origin: State(child.origin, []) for child in structure.transitions}
for transition in structure.transitions:
origin = transition.origin
for to in transition.destinations:
self.states[origin].children.append(self.states[to])
self.needs_redraw = True

def check_rebuild(self, structure: SmachContainerStructure):
def check_rebuild(self, structure: StateMachineStructure):
"""
checks if the structure passed as input matches the structure already represented (thread safe)
"""
Expand All @@ -71,10 +72,10 @@ def check_rebuild(self, structure: SmachContainerStructure):
self._rebuild(structure)
self.structure = structure

def container_status_callback(self, status: SmachContainerStatus):
self.set_active_state(status.active_states[0])
def container_status_callback(self, status: StateMachineStateUpdate):
self.set_active_state(status.state)

def container_structure_callback(self, structure: SmachContainerStructure):
def container_structure_callback(self, structure: StateMachineStructure):
self.check_rebuild(structure)


Expand Down Expand Up @@ -121,12 +122,12 @@ def update(self):
rospy.init_node("smach_visualizer", anonymous=False, disable_signals=True, log_level=rospy.INFO)
rospy.Subscriber(
STRUCTURE_TOPIC,
SmachContainerStructure,
StateMachineStructure,
state_machine.container_structure_callback,
)
rospy.Subscriber(
STATUS_TOPIC,
SmachContainerStatus,
StateMachineStateUpdate,
state_machine.container_status_callback,
)
app = QApplication([]) # type: ignore
Expand Down
4 changes: 3 additions & 1 deletion src/navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def __init__(self, context: Context):
)
self.state_machine.add_transitions(
SearchState(),
[ApproachTargetState(), LongRangeState(), WaypointState(), RecoveryState()],
[
ApproachTargetState(), LongRangeState(), WaypointState(), RecoveryState()
],
)
self.state_machine.add_transitions(DoneState(), [WaypointState()])
self.state_machine.add_transitions(
Expand Down
4 changes: 2 additions & 2 deletions urdf/world/world.urdf.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</inertial>
<visual>
<geometry>
<mesh filename="package://mrover/urdf/meshes/ground_boulders.fbx"/>
<mesh filename="package://mrover/urdf/meshes/groundflat.fbx"/>
</geometry>
</visual>
<collision>
<geometry>
<mesh filename="package://mrover/urdf/meshes/ground_boulders.fbx"/>
<mesh filename="package://mrover/urdf/meshes/groundflat.fbx"/>
</geometry>
</collision>
</link>
Expand Down

0 comments on commit 90795b2

Please sign in to comment.