Main Content

validate

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, the validate function displays an error message that says: Validation failed. The scenario has critical issues that must be corrected.

    validate(scnro,ObjectRoot=targetObject) checks only the specified object in the scenario for critical errors that prevent simulation or export. For example, validate(scnro,ObjectRoot=rrPhase) checks only the phase rrPhase in the scenario scnro.

    Examples

    collapse all

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

    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, such as by adding and modifying actors and logic components, using MATLAB®. 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)

    Validate Invalid Scenario

    When you modify a scenario, you can introduce critical errors that can cause it to fail validation, such as leaving an empty ReferenceActor property for a phase that compares two actors during simulation.

    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 Actor 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. Add a new actor action phase, srPhase, after the initial phase initPhase 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".

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

    Validate the modified scenario. Because you have not specified a reference actor for chSpd, its ReferenceActor property is empty and the validation fails.

    validate(scnro)

    Input Arguments

    collapse all

    Scenario object, specified as a Scenario object.

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

    Version History

    Introduced in R2025a