Main Content


Move robot platform in scenario



    move(platform,type,motion) moves the robot platform of the specified type in the scenario according to the specified motion.


    collapse all

    Create a robot scenario.

    scenario = robotScenario(UpdateRate=100,StopTime=1);

    Add the ground plane and a box as meshes.

    addMesh(scenario,"Plane",Size=[3 3],Color=[0.7 0.7 0.7]);
    addMesh(scenario,"Box",Size=[0.5 0.5 0.5],Position=[0 0 0.25], ...
            Color=[0 1 0])

    Create a waypoint trajectory for the robot platform using an ENU reference frame.

    waypoint = [0 -1 0; 1 0 0; -1 1 0; 0 -1 0];
    toa = linspace(0,1,length(waypoint));
    traj = waypointTrajectory("Waypoints",waypoint, ...
                              "TimeOfArrival",toa, ...

    Create a rigidBodyTree object of the TurtleBot 3 Waffle Pi robot with loadrobot.

    robotRBT = loadrobot("robotisTurtleBot3WafflePi");

    Create a robot platform with trajectory.

    platform = robotPlatform("TurtleBot",scenario, ...

    Set up platform mesh with the rigidBodyTree object.


    Create an INS sensor object and attach the sensor to the platform.

    ins = robotSensor("INS",platform,insSensor("RollAccuracy",0), ...

    Visualize the scenario.

    [ax,plotFrames] = show3D(scenario);
    axis equal
    hold on

    In a loop, step through the trajectory to output the position, orientation, velocity, acceleration, and angular velocity.

    count = 1;
    while ~isDone(traj)
        [Position(count,:),Orientation(count,:),Velocity(count,:), ...
         Acceleration(count,:),AngularVelocity(count,:)] = traj();
        count = count+1;

    Create a line plot for the trajectory. First create the plot with plot3, then manually modify the data source properties of the plot. This improves the performance of the plotting.

    trajPlot = plot3(nan,nan,nan,"Color",[1 1 1],"LineWidth",2);
    trajPlot.XDataSource = "Position(:,1)";
    trajPlot.YDataSource = "Position(:,2)";
    trajPlot.ZDataSource = "Position(:,3)";

    Set up the simulation. Then, iterate through the positions and show the scene each time the INS sensor updates. Advance the scene, move the robot platform, and update the sensors.

    for idx = 1:count-1
        % Read sensor readings.
        [isUpdated,insTimestamp(idx,1),sensorReadings(idx)] = read(ins);
        if isUpdated
            % Use fast update to move platform visualization frames.
            % Refresh all plot data and visualize.
            drawnow limitrate
        % Advance scenario simulation time and move platform.
        motion = [Position(idx,:),Velocity(idx,:),Acceleration(idx,:), ...
        % Update all sensors in the scene.
    hold off

    Figure contains an axes object. The axes object contains 28 objects of type patch, line.

    Input Arguments

    collapse all

    Robot platform in the scenario, specified as a robotPlatform object.

    Type of robot platform, specified as "base".

    Data Types: char | string

    Robot platform motion at the current instance in the scenario, specified as a 16-element vector with these elements in order:

    • [x y z] — Positions in xyz-axes in meters.

    • [vx vy vz] — Velocities in xyz-directions in meters per second.

    • [ax ay az] — Accelerations in xyz-directions in meters per second.

    • [qw qx qy qz] — Quaternion vector for orientation.

    • [wx wy wz] — Angular velocities in radians per second.

    Data Types: single | double

    Version History

    Introduced in R2022a