# How to define conditions for state-machines in roby?

I am searching for a way that allows me to wait for some conditions on ports before applying a new state.

My concrete Problem: I want to make sure that my AUV aligns to the right pipeline. Therefore before starting the pipeline-tracking, I want to check for the current system heading.

My current state-machine looks like this:

find_pipe_back = state target_move_def(:finish_when_reached => false , :heading => 1 ...)

pipe_detector = state pipeline_detector_def

pipe_detector.depends_on find_pipe_back, :role => "detector"

start(pipe_detector) forward pipe_detector.align_auv_event, success_event

roughly I am looking for a way to condition the last-forward.

Such "conditioning" was existing in the pre-syskit days, and it got removed as it made the state machines considerably more complex. Usually, what starts as a simple condition becomes quickly something a lot more involved.

The best way is therefore to create a dedicated composition that would do the monitoring:

class PipelineFinder < Syskit::Composition
# Test for tolerance
end
# Don't know the name of the relevant port, so I am making it up
wait detector.align_auv_event
emit :success
else
emit :false_positive
end
end
end


Note that you could also attach the task script on the detector task in a separate action:

describe('runs the pipeline detector but filters against an expected direction').
def detect_pipeline_with_validation(arguments = Hash.new)
detector = pipeline_detector_def