setFailCondition
Description
assigns a condition of the specified type to the Fail Conditions of the
scenario root phase. The fail condition fails the simulation when triggered during
execution. By default, RoadRunner Scenario automatically adds a rrCondition
= setFailCondition(rootPhase
,conditionType
)Collision
condition to the scenario
Fail Conditions when you create a new scenario. You can modify an
existing fail condition by extracting the FailCondition
property of the
RootPhase
property of the scenario PhaseLogic
object.
Examples
When you create a new scenario, RoadRunner Scenario adds a Collision
condition to the scenario
Fail Conditions by default. This Collision
condition specifies for RoadRunner Scenario to fail the simulation if any actor collides with any other actor. Use the
setFailCondition
function to change the condition in the scenario
Fail Conditions to specify for RoadRunner Scenario to fail the simulation if the actor car
exceeds a speed
of 30 m/s.
This example assumes that you have prior knowledge of working with RoadRunner in MATLAB®. Before proceeding, follow the steps outlined in Set Up MATLAB Environment for RoadRunner Authoring Functions to set up your scenario using MATLAB functions for scenario authoring.
Use addPhaseInSerial
to
add a new actor action phase, srPhase
, in serial after the initial
phase. Then, use addAction
to
specify the action of the new phase as "ChangeSpeedAction"
. The
srPhase
object represents the newly created actor action phase in
the scenario logic, and chSpd
represents the Change
Speed
action assigned to srPhase
. Assign the actor to
the new phase by specifying car
as the value of the
Actor
property of the phase. Set the Speed
property of the chSpd
action to 35
. This
instructs the assigned actor to change its speed to 35 m/s during simulation.
srPhase = addPhaseInSerial(rrLogic,initPhase,"ActorActionPhase",Insertion="after"); chSpd = addAction(srPhase,"ChangeSpeedAction"); srPhase.Actor = car; chSpd.Speed = 35;
Modify Scenario Fail Condition
To modify the condition type in the scenario Fail Conditions,
extract the RootPhase
property of the scenario phase logic object
rrLogic
. The logicRoot
object represents the
root phase of the RoadRunner scenario logic.
logicRoot = rrLogic.RootPhase;
Use setFailCondition
to set a different condition in the
scenario Fail Conditions by specifying the
conditionType
argument as
"ActorSpeedCondition"
. Then, set the Actor
property of the new fail condition rrCondition
to
car
and the Speed
property to
30
. This changes the existing fail condition to an Actor
Speed
condition, and specifies for RoadRunner Scenario to fail the simulation if the actor car
exceeds a
speed of 30 m/s.
rrCondition = setFailCondition(logicRoot,"ActorSpeedCondition");
rrCondition.Actor = car;
rrCondition.Speed = 30;
Run the simulation by using the simulateScenario
function.
simulateScenario(rrApp)
Input Arguments
Scenario logic root phase, specified as a ParallelPhase
object.
Example: logicRoot = rrLogic.RootPhase;
extracts the
RootPhase
property from the scenario logic object
rrLogic
, and rrCondition =
setFailCondition(logicRoot,"ActorSpeedCondition");
sets the fail condition
of that root phase to an Actor Speed
condition.
Type of condition to assign, specified as one of these condition types:
"ActorSpeedCondition"
— Specifies for the simulation to fail when an actor reaches the specified speed."CollisionCondition"
— Specifies for the simulation to fail when an actor collides with another actor."DistanceToActorCondition"
— Specifies for the simulation to fail when an actor is a certain distance away from a reference actor."DistanceToPointCondition"
— Specifies for the simulation to fail when an actor is a certain distance away from a specified point."LongitudinalDistanceToActorCondition"
— Specifies for the simulation to fail when an actor reaches a certain longitudinal distance from another actor."DurationCondition"
— Specifies for the simulation to fail after the specified amount of time elapses."SimulationTimeCondition"
— Specifies for the associated phase to end after the specified amount of time has elapsed since the start of the simulation."PhaseStateCondition"
— Specifies for the simulation to fail when the referenced phase reaches the specified state.
Output Arguments
Condition assigned to the phase, returned as one of these objects:
ActorSpeedCondition
— Represents anActor Speed
condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor reaches the specified speed.DurationCondition
— Represents aDuration
condition in the RoadRunner scenario logic that specifies for the simulation to fail after the specified amount of time elapses.CollisionCondition
— Represents aCollision
condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor collides with another actor.PhaseStateCondition
— Represents aPhase State
condition in the RoadRunner scenario logic that specifies for the simulation to fail when the referenced phase reaches the specified state.DistanceToActorCondition
— Represents aDistance To Actor
condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor is a certain distance away from a reference actor.DistanceToPointCondition
— Represents aDistance To Point
condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor is a certain distance away from a specified point.LongitudinalDistanceToActorCondition
— Represents aLongitudinal Distance To Actor
condition in the RoadRunner scenario logic that specifies for the simulation to fail when an actor reaches a certain longitudinal distance from another actor.SimulationTimeCondition
— Represents aSimulation Time
condition in the RoadRunner scenario logic that specifies for the associated phase to end after the specified amount of time has elapsed since the start of the simulation.
Version History
Introduced in R2025a
See Also
roadrunnerAPI
| setEndCondition
| addPhase
| CollisionCondition
| PhaseStateCondition
Topics
- RoadRunner Scenario Fundamentals (RoadRunner Scenario)
- Simulate a RoadRunner Scenario Using MATLAB Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)