Main Content

obstaclePose

Poses of obstacles

Since R2020b

Description

[obstacleIDs,poseStruct] = obstaclePose(capsuleListObj) returns the obstacle ID and states for each obstacle in the specified capsule list.

example

[obstacleIDs,poseStruct] = obstaclePose(capsuleListObj,selectObstacleIDs) specifies which obstacles to return the ID and states for.

[obstacleIDs,poseStruct,status] = obstaclePose(capsuleListObj,selectObstacleIDs) returns an indicator of whether each ID in selectObstacleIDs exists.

Examples

collapse all

Add obstacles to an environment using the dynamicCapsuleList object. Modify the properties of the obstacles. Remove an obstacle from the environment. Visualize the states of all objects in the environment at different timestamps.

Create the dynamicCapsuleList object. Extract the maximum number of steps to use as the number of time stamps for the object paths.

capsuleList = dynamicCapsuleList;
numSteps = capsuleList.MaxNumSteps;

Add Obstacles

Specify the states for the two obstacles as a linear path from x = 0 m to x = 100 m. The two obstacles are separated by 10 m in opposite directions on the y-axis.

obsState = linspace(0,1,numSteps)'.*[100 0 0];
obsState1 = obsState+[0 10 0];
obsState2 = obsState+[0 -10 0];

Generate default poses and geometric structures for the two obstacles using obstacle IDs.

[obsIDs,obsPoseStruct] = obstaclePose(capsuleList,[1 2]);
[obsIDs,obsGeomStruct] = obstacleGeometry(capsuleList,obsIDs);

Update Obstacles

Assign the states to the obstacles.

obsPoseStruct(1).States = obsState1;
obsPoseStruct(2).States = obsState2;

Increase the radius of the first obstacle to 2 m.

obsGeomStruct(1).Geometry.Radius = 2;

update the obstacles using the updateObstaclePose and updateObstacleGeometry object functions.

updateObstaclePose(capsuleList,obsIDs,obsPoseStruct);
updateObstacleGeometry(capsuleList,obsIDs,obsGeomStruct);

Visualize the obstacles.

show(capsuleList,'TimeStep',1:numSteps);
axis equal

Remove Obstacles

Remove the first obstacle from the capsule list by specifying its ID.

removeObstacle(capsuleList,1);

Visualize the obstacles again.

show(capsuleList,'TimeStep',1:numSteps);
axis equal

Input Arguments

collapse all

Dynamic capsule list, specified as a dynamicCapsuleList or dynamicCapsuleList3D object.

Obstacle IDs, specified as a vector of positive integers. The function returns the obstacle IDs and states for only the obstacles specified in this vector.

Output Arguments

collapse all

IDs of obstacles, specified as a vector of positive integers.

States for obstacles, returned as a structure or structure array. Each structure contains a matrix of states for each obstacle. The state matrix size depends on whether you are using a dynamicCapsuleList or dynamicCapsuleList3D object.

Data Types: struct

Indication of obstacle existence, returned as a N-element column vector of ones, zeros, and negative ones. Each value indicates whether the associated obstacle exists (1), updated (0), or a duplicate (-1). If you specify the same obstacle ID more than once in the selectObstacleIDs argument, then the function marks all instances of that ID after the first as duplicates and ignores them.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2020b