主要内容

Annotate Vehicle Simulation

This example shows how to annotate the trajectory, location, speed, and direction of a vehicle during simulation. First, you create a 3D environment with a straight road and cones to form a double lane change maneuver. Next, add a vehicle to drive in the environment. Then, create an arrow to show the steering direction, text labels for vehicle location and speed during simulation, and path markers to trace the vehicle trajectory.

Open Model

Open the model.

open_system("VehicleAnnotations.slx");

Simulink model in which to annotate vehicle simulation.

Explore Model Components

The model includes a Simulation 3D Scene Configuration block, a Simulation 3D Vehicle with Ground Following block, and Simulation 3D Actor blocks to create a 3D environment with actors that you can annotate during simulation.

3D Environment

The Simulation 3D Scene Configuration block implements the 3D environment. Double-click the Simulation 3D Scene Configuration block to open the Block Parameters dialog box. Set Scene name to Straight road.

The Simulation 3D Actor block named Cones creates actors with a cone shape and adds them to the 3D environment. The Initialization script of the block loads the ConeLocations.mat file to access the variables LPos and RPos, which specify cone locations. The Initialization script uses the createShape function to build cone shape for each actor created at the LPos and RPos locations.

Vehicle Trajectory

The Simulation 3D Vehicle with Ground Following block adds a vehicle actor to the 3D environment. The vehicle location at each time step is loaded to the X, Y, and Yaw input ports of the block using the VehicleTransformSignals.mat file, which contains the timeseries variables, X,Y, and Yaw.

The Simulation 3D Actor block named Trajectory creates a sim3d.graphics.PathMarker object to trace the vehicle trajectory. Use the Initialization script of the actor block to create and add the sim3d.graphics.PathMarker object to the world. Set the ControlActor argument of the sim3d.graphics.PathMarker object to the name of the vehicle actor, SimulinkVehicle1.

Annotations

These Simulation 3D Actor blocks create and add annotations to the environment and update the annotations during simulation.

  • Display Speed displays the text label Speed and the vehicle speed during simulation. Use the Initialization script of the actor block to create and add two sim3d.graphics.Text objects named SpeedLabel and Speed to the environment. The object SpeedLabel displays the text label Speed, and the object Speed displays the vehicle speed at each time step. Use the Input tab of the block to select the input port Speed.String. The speed during each time step is calculated by the MATLAB Function block named Speed value and displays the speed value in the environment using the Speed.String input port of the Display Speed block.

  • Display X displays the text label X and the vehicle location along X-axis during simulation. Use the Initialization script of the actor block to create and add two sim3d.graphics.Text objects to display the text label and the value in the environment. Use the Input tab of the block to select the input port X.String. The MATLAB Function block rounds the X value from the Location output port of the Simulation 3D Vehicle with Ground Following block and displays it using the Display X block.

  • Display Y displays the text label Y and the vehicle location along Y-axis during simulation. Use the Initialization script of the actor block to create and add two sim3d.graphics.Text objects to display the text label and the value in the environment. Use the Input tab of the block to select the input port Y.String. The MATLAB Function block rounds the Y value from the Location output port of the Simulation 3D Vehicle with Ground Following block and displays it using the Display Y block.

  • Display Yaw displays the text label Yaw and the vehicle orientation about Z-axis location during simulation. Use the Initialization script of the actor block to create and add two sim3d.graphics.Text objects to display the text label and the value in the environment. Use the Input tab of the block to select the input port Yaw.String. The MATLAB Function block rounds the Yaw value from the Orientation output port of the Simulation 3D Vehicle with Ground Following block and displays it using the Display Yaw block.

  • Steering Direction displays an arrow that changes orientation during simulation based on the vehicle direction. Use the Initialization script of the actor block to create and add a sim3d.graphics.Arrow object named SteeringDirection that displays an arrow in the environment. Use the Input tab of the block to select the input port SteeringDirection.Rotation.The MATLAB Function block rounds the rotation value from the Orientation output port of the Simulation 3D Vehicle with Ground Following block and updates the rotation of the arrow in the 3D environment using the SteeringDirection.Rotation input port of the Steering Direction block.

Simulate Model

Simulate the model and view the vehicle driving in the environment with annotations in the Simulation 3D Viewer.

sim("VehicleAnnotations.slx");

3D environment with vehicle, its trajectory, arrow showing steering direction, and text labels X, Y, Yaw , and Speed with the real time values.

Close Model

Close the Simulink model.

close_system("VehicleAnnotations.slx");

See Also

| | | | | | | | | (Simulink)

Topics