Hauptinhalt

validate

R2026b

Check RoadRunner scenario for critical errors

Since R2025a

    Description

    validate(scnro) checks the specified RoadRunner scenario for critical errors that prevent simulation or export. If the scenario contains critical errors, validation fails and the validate function returns an error. For each critical error, the error message identifies the affected scenario object and describes the problem. If the scenario does not contain critical errors, validation succeeds and the function returns true. You can use these messages to identify and fix scenario issues before simulating the scenario.

    validate(scnro,Name=Value) specifies options using one or more name-value arguments. For example, ObjectRoot=rrPhase checks only the phase rrPhase in the scenario.

    Examples

    collapse all

    Open an existing scenario, CutInAndSlow.rrscenario, and use the validate function to check for critical errors and warnings.

    Open and Validate Existing Scenario

    Create a roadrunner object, specifying the path to an existing project. For example, this code shows the path to a project, on a Windows® machine, located at "C:\RR\MyProject". This code assumes that RoadRunner is installed in the default location, and returns an object, rrApp, that provides functions for performing basic tasks such as opening, closing, and saving scenes and projects.

    Open an existing scenario in RoadRunner by using the openScenario function, specifying the roadrunner object rrApp and the filename of the CutInAndSlow.rrscenario scenario.

    rrApp = roadrunner(ProjectFolder="C:\RR\MyProject");
    openScenario(rrApp,"CutInAndSlow.rrscenario")

    Create an object for the RoadRunner authoring API, rrApi, that references the object for the current RoadRunner instance rrApp. The rrApi object enables you to programmatically author scenarios using MATLAB®, such as by adding and modifying actors and logic components. Then, extract the object for your scenario from the Scenario property of the authoring API object rrApi.

    rrApi = roadrunnerAPI(rrApp);
    scnro = rrApi.Scenario;

    Use the validate function to validate the scenario.

    validate(scnro)

    The scenario does not contain critical errors, so validation succeeds and the function returns true.

    ans =
    
      logical
    
       1

    Validate Scenario with Warnings

    When you modify a scenario, you can introduce issues that do not prevent simulation or export, such as an empty parallel phase. The validate function reports these issues as warnings.

    From the scenario scnro, extract the objects for the scenario phase logic, from the PhaseLogic property, and the actor named "Yellow", stored as the first element of the Actors property. rrLogic represents the RoadRunner scenario logic, and yellowCar represents the actor named "Yellow".

    rrLogic = scnro.PhaseLogic;
    yellowCar = scnro.Actors(1);

    Use the initialPhaseForActor function to extract the object for the initial phase of the actor yellowCar. Then, add a parallel phase, emptyPhase, after the initial phase initPhase. Because emptyPhase does not contain any phases, the scenario now has a validation warning.

    initPhase = initialPhaseForActor(rrLogic,yellowCar);
    emptyPhase = addPhaseInSerial(rrLogic,initPhase,"ParallelPhase",Insertion="after");

    Validate the modified scenario, specifying ShowWarnings as true.

    validate(scnro,ShowWarnings=true)

    The validate function displays the warning for the empty parallel phase, but validation still succeeds.

    Warning: Phase (unnamed): Composite phase is empty. Composite phases should contain at least one phase.
    
    ans =
    
      logical
    
       1

    Validate Invalid Scenario

    You can also introduce critical errors that cause the scenario to fail validation, such as leaving an empty ReferenceActor property for a change speed action that uses another actor as its speed reference.

    Add a new actor action phase, srPhase, after the parallel phase emptyPhase and assign it to the actor yellowCar. Then, use addAction to specify the action of srPhase as "ChangeSpeedAction". Set the SpeedReference property of the change speed action chSpd to "actor".

    srPhase = addPhaseInSerial(rrLogic,emptyPhase,"ActorActionPhase",Insertion="after");
    srPhase.Actor = yellowCar;
    chSpd = addAction(srPhase,"ChangeSpeedAction");
    chSpd.SpeedReference = "actor";

    Validate the scenario, specifying ShowWarnings as true.

    validate(scnro,ShowWarnings=true)

    Because you have not specified a reference actor for chSpd, its ReferenceActor property is empty and validation fails. The validate function displays the warning for the empty parallel phase, and then returns an error that describes the critical issue.

    Warning: Phase (unnamed): Composite phase is empty. Composite phases should contain at least one phase.
    Error using roadrunner.api.Scenario/validate
    Validation failed. The scenario has critical issues that must be corrected.
    
    Caused by:
        Change Speed Action has no assigned Reference Actor.

    Input Arguments

    collapse all

    Scenario to validate, specified as a Scenario object.

    Example: validate(scnro) checks the scenario scnro for critical errors that prevent simulation or export.

    Name-Value Arguments

    collapse all

    Example: validate(scnro,ShowWarnings=true)

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Since R2026b

    Display validation warnings, specified as a logical 1 (true) or 0 (false). Validation warnings indicate issues that do not prevent simulation or export. To display validation warnings, specify this argument as true. If the scenario contains both critical errors and warnings, and ShowWarnings is true, the function displays the warnings before returning the errors. The function reports critical errors regardless of the value of ShowWarnings.

    Example: validate(scnro,ShowWarnings=true) checks the scenario scnro for critical errors and also displays any validation warnings.

    Data Types: logical

    Version History

    Introduced in R2025a

    expand all