Skip to content
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

set_initial_state: set current_state to initial state #93

Open
wants to merge 2 commits into
base: noetic-devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion smach/src/smach/state_machine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import threading
import traceback
import time
from contextlib import contextmanager

import smach
Expand Down Expand Up @@ -41,6 +42,7 @@ def __init__(self, outcomes, input_keys=[], output_keys=[]):

# Properties
self._state_transitioning_lock = threading.Lock()
self._state_executing_lock = threading.Lock()

# Current state of the state machine
self._is_running = False # True when a goal has been dispatched to and accepted by the state machine
Expand Down Expand Up @@ -356,7 +358,10 @@ def execute(self, parent_ud = smach.UserData()):
# Step through state machine
while container_outcome is None and self._is_running and not smach.is_shutdown():
# Update the state machine
container_outcome = self._update_once()
with self._state_executing_lock:
container_outcome = self._update_once()
# let's set_initial_state to update status
time.sleep(0.01)

# Copy output keys
self._copy_output_keys(self.userdata, parent_ud)
Expand Down Expand Up @@ -421,6 +426,16 @@ def set_initial_state(self, initial_states, userdata=smach.UserData()):
# Set local userdata
self.userdata.update(userdata)

with self._state_executing_lock:
# Set initial state
if self._initial_state_label not in self._states:
smach.logwarn("Try to set inital state '%s', but it does not exist. Available states are: %s" %
(self._initial_state_label, list(self._states.keys())))
else:
self._set_current_state(self._initial_state_label)
# Call start callbacks
self.call_start_cbs()

def get_active_states(self):
return [str(self._current_label)]

Expand Down