Main Content

sample

Compute state samples using MPNet state sampler

Since R2023b

Description

states = sample(sampler)computes a state sample using a Motion Planning Networks (MPNet) state sampler.

example

states = sample(sampler,numsamples) computes the specified number of state samples.

Examples

collapse all

Load Pretrained MPNet

Load a data file containing a pretrained MPNet into the MATLAB® workspace. The MPNet has been trained on various 2-D maze maps with widths and heights of 10 meters and resolutions of 2.5 cells per meter. Each maze map contains a passage width of 5 grid cells and wall thickness of 1 grid cell.

data = load("mazeMapTrainedMPNET.mat")
data = struct with fields:
      encodingSize: [9 9]
       lossWeights: [100 100 0]
        mazeParams: {[5]  [1]  'MapSize'  [10 10]  'MapResolution'  [2.5000]}
       stateBounds: [3x2 double]
    trainedNetwork: [1x1 dlnetwork]

Create Maze Map for Sampling

Create a random maze map for sampling. The grid size (MapSize×MapResolution) must be the same as that of the maps used for training the MPNet.

map = mapMaze(5,1,MapSize=[10 10],MapResolution=2.5);

Specify the start pose and goal pose.

start = [1 1 0];
goal = [9 9 0];

Create MPNet State Sampler

Specify the state bounds, and create an SE(2) state space object.

x = map.XWorldLimits;
y = map.YWorldLimits;
z = [-pi pi];
stateBounds = [x; y; z];
stateSpace = stateSpaceSE2(stateBounds);

Configure the mpnetSE2 object to use the pretrained MPNet for predicting state samples on a random map. Set the EncodingSize property values of the mpnetSE2 object to that of the value used for training the network.

mpnet = mpnetSE2(Network=data.trainedNetwork,StateBounds=stateBounds,EncodingSize=data.encodingSize);

Create an MPNet state sampler for the computing state samples. Specify the map environment, the start pose and the goal pose as inputs to the state sampler.

sampler = stateSamplerMPNET(stateSpace,mpnet,Environment=map,StartState=start,GoalState=goal);

Compute State Samples and Plot Results

Generate 40 state samples using the MPNet state sampler.

states = sample(sampler,40);

Plot the input data and the computed samples.

show(map)
hold on
plot(start(1),start(2),plannerLineSpec.start{:})
plot(goal(1),goal(2),plannerLineSpec.goal{:})
plot(states(:,1),states(:,2),plannerLineSpec.state{:})
hold off
legend(Location="bestoutside")

Input Arguments

collapse all

MPNet state sampler, specified as a stateSamplerMPNET object.

Number of samples, specified as a positive integer.

Data Types: double

Output Arguments

collapse all

State samples, returned as an M-by-N matrix of real values. M is the number of state samples. N is the number of state variables. Each row of the matrix contains state variables corresponding to the input state space model. For the SE(2) state space model, N is 3 and each row is of the form [x y θ].

Data Types: double

Extended Capabilities

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

Version History

Introduced in R2023b

See Also

Objects

Functions