I want to define my custom state space in matlab for my robot,i followed this tutorial ,https://i​n.mathwork​s.com/help​/nav/ref/n​av.statesp​ace-class.​html

3 views (last 30 days)
In this as soon as i include this line
matlabshared.planning.internal.EnforceScalarHandle
it starts throwing error like illegal use of classdef ,kindly tell whats the solution to this problem

Answers (1)

Cameron Stabile
Cameron Stabile on 7 Dec 2021
Edited: Cameron Stabile on 7 Dec 2021
Hi Mukund,
Without any reproduction code it is hard to determine the problem. If you have not done so already, my suggestion would be to call createPlanningTemplate from your command line:
>> createPlanningTemplate()
This should create a new file which contains the definition to a generic state-space class named "MyCustomStateSpace". Save this file under the same name (i.e. MyCustomStateSpace.m) and you should be able to create an instance of the newly defined state-space:
ss = MyCustomStateSpace
If this works, then you should be able to edit the newly saved state-space to suit your needs, and note that you can also generate a default state-validator using the same template:
createPlanningTemplate('StateValidator')
Please let us know if this resolves the issue.
Best,
Cameron
  2 Comments
mukund shah
mukund shah on 8 Dec 2021
Actually i did this
classdef MyCustomStateSpace < nav.StateSpace
%matlabshared.planning.internal.EnforceScalarHandle
properties
UniformDistribution
NormalDistribution
% Specify additional properties here
end
methods
function obj = MyCustomStateSpace
spaceName = "MyCustomStateSpace";
numStateVariables = 3;
stateBounds = [0 256; % [min max]
0 256;
0 256];
obj@nav.StateSpace(spaceName, numStateVariables, stateBounds);
obj.NormalDistribution = matlabshared.tracking.internal.NormalDistribution(numStateVariables);
obj.UniformDistribution = matlabshared.tracking.internal.UniformDistribution(numStateVariables);
% User-defined property values here
end
function copyObj = copy(obj)
copyObj = feval(class(obj));
copyObj.StateBounds = obj.StateBounds;
copyObj.UniformDistribution = obj.UniformDistribution.copy;
copyObj.NormalDistribution = obj.NormalDistribution.copy;
end
function boundedState = enforceStateBounds(obj, state)
nav.internal.validation.validateStateMatrix(state, nan, obj.NumStateVariables, "enforceStateBounds", "state");
boundedState = state;
boundedState = min(max(boundedState, obj.StateBounds(:,1)'), ...
obj.StateBounds(:,2)');
end
function state = sampleUniform(obj, varargin)
narginchk(1,4);
[numSamples, stateBounds] = obj.validateSampleUniformInput(varargin{:});
obj.UniformDistribution.RandomVariableLimits = stateBounds;
state = obj.UniformDistribution.sample(numSamples);
end
function state = sampleGaussian(obj, meanState, stdDev, varargin)
narginchk(3,4);
[meanState, stdDev, numSamples] = obj.validateSampleGaussianInput(meanState, stdDev, varargin{:});
obj.NormalDistribution.Mean = meanState;
obj.NormalDistribution.Covariance = diag(stdDev.^2);
state = obj.NormalDistribution.sample(numSamples);
state = obj.enforceStateBounds(state);
end
function interpState = interpolate(obj, state1, state2, fraction)
narginchk(4,4);
[state1, state2, fraction] = obj.validateInterpolateInput(state1, state2, fraction);
stateDiff = state2 - state1;
interpState = state1 + fraction' * stateDiff;
end
function dist = distance(obj, state1, state2)
narginchk(3,3);
nav.internal.validation.validateStateMatrix(state1, nan, obj.NumStateVariables, "distance", "state1");
nav.internal.validation.validateStateMatrix(state2, size(state1,1), obj.NumStateVariables, "distance", "state2");
stateDiff = bsxfun(@minus, state2, state1);
dist = sqrt( sum( stateDiff.^2, 2 ) );
end
end
end
Cameron Stabile
Cameron Stabile on 16 Dec 2021
Hi Mukund,
It's unclear whether your last post was a self-answer to your original question, or additional information. Did commenting out the line resolve the problem for you?
One thing to note - if your original file looked like the following:
classdef MyCustomStateSpace < nav.StateSpace
matlabshared.planning.internal.EnforceScalarHandle
properties
UniformDistribution
...
Then you would likely have needed "& ..." at the end of the first line to continue inheriting from additional classes:
classdef MyCustomStateSpace < nav.StateSpace & ...
matlabshared.planning.internal.EnforceScalarHandle
properties
UniformDistribution
...
If the issue has been resolved, please mark this question as "Answered", otherwise let us know if you are encountering further problems.
Best,
Cameron

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!