updateMesh
Update robot platform body mesh
Description
updateMesh(
updates the body mesh of the robot platform with the specified mesh type and specifies
additional options using one or more name-value pair arguments.platform
,type
,Name=Value
)
Examples
Create and Simulate Robot Scenario
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
Input Arguments
platform
— Robot platform in scenario
robotPlatform
object
Robot platform in the scenario, specified as a robotPlatform
object.
type
— Type of mesh
"Cuboid"
| "GroundVehicle"
| "RigidBodyTree"
| "Custom"
Type of mesh, specified as "Cuboid"
,
"GroundVehicle"
, "RigidBodyTree"
, or
"Custom"
.
Data Types: char
| string
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example:
Position
— Relative mesh position in body frame
[0 0 0]
(default) | vector of form [x
y
z]
Relative mesh position in the body frame, specified as a vector of the form
[x
y
z]
in meters.
Data Types: single
| double
Orientation
— Relative mesh orientation in body frame
[1 0 0 0]
(default) | vector of form [w
x
y
z]
| quaternion
object
Relative mesh orientation in the body frame, specified as a quaternion vector of
the form [w
x
y
z]
or a quaternion
object.
Data Types: single
| double
Offset
— Transformation of mesh relative to body frame
4-by-4 homogeneous transformation matrix
Transformation of mesh relative to the body frame, specified as a 4-by-4 homogeneous transformation matrix. The matrix maps points in the platform mesh frame to points in the body frame.
Data Types: single
| double
Color
— Robot platform body mesh color
[1 0 0]
(default) | RGB triplet
Robot platform body mesh color, specified as a RGB triplet, except for the rigid body mesh.
Data Types: single
| double
Faces
— Faces of custom robot platform mesh
N-by-3 matrix of positive integers
Faces of the custom robot platform mesh, specified as an N-by-3 matrix of positive integers. The three elements in each row are the indices of the three points in the vertices forming a triangle face. N is the number of faces.
Data Types: single
| double
Vertices
— Vertices of custom robot platform mesh
N-by-3 matrix of real scalars
Vertices of the custom robot platform mesh, specified as an N-by-3 matrix of real scalars. The first, second, and third element of each row represents the x-, y-, and z-position of each vertex, respectively. N is the number of vertices.
Data Types: single
| double
Size
— Size of cuboid robot platform mesh
[1 0.5 0.3]
(default) | vector of form [xlength
ylength
zlength]
Size of the cuboid robot platform mesh, specified as a vector of form
[xlength
ylength
zlength]
in meters.
Data Types: single
| double
Scale
— Scale of ground vehicle robot platform mesh
1
(default) | scalar
Scale of the ground vehicle robot platform mesh, specified as a scalar. Scale is unitless.
Data Types: single
| double
Object
— Rigid body tree robot platform
[]
(default) | rigidBodyTree
object
Rigid body tree robot platform, specified as a rigidBodyTree
object.
Version History
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)