Main Content

robotSensor

Sensor for robot scenario

    Description

    The robotSensor object creates a sensor that is rigidly attached to a robot platform, specified as a robotPlatform object. You can specify different mounting positions and orientations. Configure this object to automatically generate readings at fixed rate from a sensor specified as an gpsSensor, insSensor, or robotLidarPointCloudGenerator System object™.

    Creation

    Description

    sensor = robotSensor(name,platform,sensormodel) creates a sensor with the specified name name and sensor model sensormodel, which set the Name and SensorModel properties respectively. The sensor is added to the platform platform specified as a robotPlatform object. The platform argument sets the MountingBodyName property.

    example

    sensor = robotSensor(___,Name=Value) sets properties using one or more name-value pair arguments in addition to the input arguments in the previous syntax. You can specify the MountingLocation, MountingAngles, or UpdateRate properties as name-value pairs.

    Properties

    expand all

    Sensor name, specified as a string scalar. Choose a name to identify this specific sensor.

    Data Types: char | string

    Sensor model for generating readings, specified as an gpsSensor, insSensor, or robotLidarPointCloudGenerator System object.

    Name of the sensor mounted platform body, specified as a string scalar. The rigidBodyTree based robot platform can have multiple bodies, any valid body can be selected to mount sensor.

    Data Types: char | string

    Sensor position on platform, specified as a vector of the form [x y z] in the platform frame. Units are in meters.

    Data Types: single | double

    Sensor orientation on platform, specified as a vector of the form [z y x] where z, y, and x are rotations about the z-axis, y-axis, and x-axis, sequentially, in degrees. The orientation is relative to the platform body frame.

    Data Types: single | double

    Update rate of the sensor, specified as a positive scalar in Hz. By default, the object uses the UpdateRate property of the specified sensor model object.

    The sensor update interval (1/UpdateRate) must be a multiple of the update interval for the associated robotScenario object.

    Data Types: single | double

    Object Functions

    readGather latest reading from robot sensor

    Examples

    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, ...
                              "ReferenceFrame","ENU");

    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, ...
                             BaseTrajectory=traj);

    Set up platform mesh with the rigidBodyTree object.

    updateMesh(platform,"RigidBodyTree",Object=robotRBT)

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

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

    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;
    end

    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.

    setup(scenario)
    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.
            show3D(scenario,FastUpdate=true,Parent=ax);
            % Refresh all plot data and visualize.
            refreshdata
            drawnow limitrate
        end
        % Advance scenario simulation time and move platform.
        advance(scenario);
        motion = [Position(idx,:),Velocity(idx,:),Acceleration(idx,:), ...
                  compact(Orientation(idx,:)),AngularVelocity(idx,:)];
        move(platform,"base",motion)
        % Update all sensors in the scene.
        updateSensors(scenario)
    end
    hold off

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

    Version History

    Introduced in R2022a