Main Content

sim3d.scenario.ActorBehavior Class

Namespace: sim3d.scenario
Superclasses: matlab.System

Define RoadRunner actors that use Unreal Engine viewer visualization

Since R2023b

Description

sim3d.scenario.ActorBehavior is the base class to define the behavior of RoadRunner actors in an Unreal Engine® 3D Viewer scenario simulation. Associating a subclass of ActorBehavior to a RoadRunner actor allows you to view your RoadRunner scenario simulation in Unreal Engine 3D Viewer. For example, to create an actor behavior named My3DActor, use this code in the first line of your class definition file.

classdef My3DActor < sim3d.scenario.ActorBehavior

In your subclass, customize the onSimulationStart, onSimulationStep, and onSimulationStop methods to define the simulation behavior of your actor.

To define the behavior of a RoadRunner actor that uses Unreal Engine 3D viewer:

  1. Create a subclass of sim3d.scenario.ActorBehavior.

  2. Customize the onSimulationStart, onSimulationStep, and onSimulationStop methods.

  3. Create a new behavior in the RoadRunner Asset Library that uses your subclass file.

  4. Associate the new behavior with one or more actors in your scenario.

  5. Connect MATLAB® and RoadRunner and start simulation.

This workflow builds on the one described in Simulate RoadRunner Scenarios with Actors Modeled in MATLAB. For an example of ActorBehavior objects, see Simulate RoadRunner Scenarios with Actors Modeled in MATLAB and View in Unreal Engine 3D Viewer.

The sim3d.scenario.ActorBehavior class is a handle class.

Class Attributes

Abstract
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Protected Properties

3D Visualization Actor Properties

Handle to the 3D world object used in the 3D visualization, specified as a sim3d.World object. For more information, see sim3d.World (Simulink 3D Animation). This value is created automatically.

Attributes:

GetAccess
protected
SetAccess
protected

Camera information for the 3D world, specified as a sim3d.sensors.MainCamera object. For more information, see sim3d.sensors.MainCamera (Simulink 3D Animation). This value is created automatically.

Attributes:

GetAccess
protected
SetAccess
protected

Actor in the 3D world, specified as a sim3d.Actor object. Update the Translation, Rotation and Scale attributes to change the pose of the actor in the 3D visualization. For more information, see sim3d.Actor (Simulink 3D Animation). This value is created automatically.

Attributes:

GetAccess
protected
SetAccess
protected
RoadRunner Actor Properties

Unique name of actor, specified as a string scalar. This value is created automatically.

Attributes:

GetAccess
protected
SetAccess
protected

Data Types: string

Actor pose at current time step, specified as 4-by-4 real matrix. Update this matrix to update the RoadRunner actor pose.

Example: [0.0386 0.9993 0 -14.1322; -0.9993 0.0386 0 -2.1225; 0 0 1.0000 0; 0 0 0 1.0000]

Attributes:

GetAccess
protected
SetAccess
protected

Data Types: double

Actor velocity at current time step, specified as 1-by-3 real vector.

Example: [9.9925 0.3862 0]

Attributes:

GetAccess
protected
SetAccess
protected

Data Types: double

Static attributes of the actor, such as name, paint color, and bounding box, specified as an ActorModel object.

Attributes:

GetAccess
protected
SetAccess
protected

Runtime attributes of the actor, such as pose and velocity, specified as an ActorSimulation object.

Attributes:

GetAccess
protected
SetAccess
protected

Scenario simulation attributes, specified as a ScenarioSimulation object.

Attributes:

GetAccess
protected
SetAccess
protected

Methods

expand all

Examples

collapse all

Define a class named Sim3dEgoVehicle1 that inherits from the sim3d.scenario.ActorBehavior class. The Sim3dEgoVehicle1 class defines a custom onSimulationStep method that moves the actor at a constant velocity and direction.

classdef Sim3dEgoVehicle1 < sim3d.scenario.ActorBehavior
    % Sim3dEgoVehicle1 implements an ego vehicle behavior using sim3d

    %   Copyright 2023 The MathWorks, Inc.
    methods(Access = protected)

        function onSimulationStep(self, actorSimulation)

            self.Actor.Translation(1,1) = self.Actor.Translation(1,1) + ...
                self.Velocity(1) * self.getSampleTimeImpl.SampleTime;
            self.Actor.Translation(1,2) = self.Actor.Translation(1,2) + ...
                self.Velocity(2) * self.getSampleTimeImpl.SampleTime;
            self.Actor.step(self.Actor.Translation(1,1), ...
                self.Actor.Translation(1,2), ...
                self.Actor.Rotation(1,3));

            self.Pose = self.transform2matrix(self.Actor.Translation, ...
                self.Actor.Rotation, self.Actor.Scale);
        end

    end
end

Version History

Introduced in R2023b