主要内容

班级:导航.StateSpace
Package:导航

状态之间的插值

描述

example

地间=插值(ssObj,state1,state2,比率)根据给定的比率.

Input Arguments

展开全部

状态空间对象,指定为导航.StateSpace.

初始状态位置, specified as an- 元素矢量。n是在NumStateVariablesproperty ofssObj.

Final state position, specified as an- 元素矢量。n是在NumStateVariablesproperty ofssObj.

Ratio values for interpolating along path, specified as anm- 元素矢量。These ratios determine how to sample between the two states.

Output Arguments

展开全部

Interpolated states, returned as anm-经过-nmatrix of row vectors.mis the length of比率n是在NumStateVariablesproperty ofssObj.

例子

展开全部

此示例显示了如何使用CreatePlanningTemplate函数生成一个模板,用于自定义您自己的状态空间定义和采样器,以与路径计划算法一起使用。模板提供了简单的实现。

Call the create template function. This function generates a class definition file for you to modify for your own implementation.

CreatePlanningTemplate

Class and Property Definition

The first part of the template specifies the class definition and any properties for the class. Derive from the导航.StateSpace班级。对于此示例,为统一和正常分布创建属性。您可以在此处指定任何其他用户定义的属性。

classdefMyCustomStateSpace < nav.StateSpace &...matlabshared.planning.internal.EnforceScalarHandle特性统一分布正常分布% Specify additional properties hereend

Save your custom state space class and ensure your file name matches the class name.

类构造函数

使用构造函数设置状态空间的名称,状态变量的数量,并定义其边界。另外,您可以将输入参数添加到函数中,并在创建对象时传递变量。

  • 对于每个状态变量,定义[min max]状态边界的值。

  • Call the constructor of the base class.

  • 在此示例中,您使用预定义指定正常和统一的分布属性值NormalDistributionUniformDistribution课程。

  • 在此处指定任何其他用户定义的属性值。

方法功能obj = MyCustomStateSpace spaceName =“ mycustomStatespace”;numStateVariables = 3;statebounds = [-100 100;% [min max]-100 100; -100 100]; obj@nav.StateSpace(spaceName, numStateVariables, stateBounds); obj.NormalDistribution = matlabshared.tracking.internal.NormalDistribution(numStateVariables); obj.UniformDistribution = matlabshared.tracking.internal.UniformDistribution(numStateVariables);%用户定义的属性值此处end

Copy Semantics

指定复制方法定义。将用户定义变量的所有值复制到新对象中,因此CopyObjis a deep copy. The default behavior given in this example creates a new copy of the object with the same name, state bounds, and distributions.

功能copyObj =复制(obj) copyObj =函数宏指令(类(obj));CopyObj.StateBounds = obj.StateBounds; copyObj.UniformDistribution = obj.UniformDistribution.copy; copyObj.NormalDistribution = obj.NormalDistribution.copy;end

Enforce State Bounds

Specify how to ensure states are always within the state bounds. For this example, the state values get saturated at the minimum or maximum values for the state bounds.

功能boundedstate = enforcestateBounds(obj,state)nav.internal.validation.validateTestateMatrix(state,nan,obj.numstatevariables,“执行驱动器”,“状态”);boundedState = state; boundedState = min(max(boundedState, obj.StateBounds(:,1)'),...OBJ.StateBounds(:,2)');end

Sample Uniformly

指定behavior for sampling across a uniform distribution. support multiple syntaxes to constrain the uniform distribution to a nearby state within a certain distance and sample multiple states.

STATE = sampleUniform(OBJ) STATE = sampleUniform(OBJ,NUMSAMPLES) STATE = sampleUniform(OBJ,NEARSTATE,DIST) STATE = sampleUniform(OBJ,NEARSTATE,DIST,NUMSAMPLES)

对于此示例,使用验证功能来处理varargin输入可以处理不同输入参数的输入。

功能状态= sample Uniform(obj,varargin)narginchk(1,4);[numsamples,stateBounds] = obj.validates ampamplemuniftionInput(varargin {:});obj.uniformdistribution.randomvariablelimits = state -bounds;状态= obj.uniformdistribution.sample(numsamples);end

Sample from Gaussian Distribution

指定跨高斯分布采样的行为。金宝app支持多个语法来取样单个状态或多个状态。

state = samplegaussian(obj,卑鄙,stddev)state = samplegaussian(obj,卑鄙,stddev,numsamples)

功能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

状态之间的插值

Define how to interpolate between two states in your state space. Use an input,分数, to determine how to sample along the path between two states. For this example, define a basic linear interpolation method using the difference between states.

功能Interpstate = interpaly(obj,state1,state2,分数)narginchk(4,4);[state1,state2,分数] = obj.validateInterpalypalyPate(state1,state2,ration);newatediff = state2 -state1;Interpstate = state1 +分数' * natediff;end

Calculate Distance Between States

Specify how to calculate the distance between two states in your state space. Use thestate1state2输入以定义开始和终点位置。两个输入都可以是单个状态(行矢量)或多个状态(行向量的矩阵)。在此示例中,根据每对状态位置之间的欧几里得距离计算距离。

功能dist =距离(obj,state1,state2)narginchk(3,3);nav.internal.validation.validateTestateMatrix(state1,nan,obj.numstatevariables,"distance","state1");nav.internal.validation.validateTestateMatrix(state2,size(state1,1),obj.numstatevariobles,"distance","state2");newatediff = bsxfun(@minus,state2,state1);dist = sqrt(sum(sentediff。^2,2));end

终止方法和类部分。

endend

保存您的州空间类定义。现在,您可以使用类构造函数为您的状态空间创建对象。

Version History

Introduced in R2019b