插
班级:导航.StateSpace
Package:导航
状态之间的插值
Input Arguments
ssObj
—状态空间对象
object of a subclass of导航.StateSpace
状态空间对象,指定为导航.StateSpace
.
state1
—初始状态位置
n-element vector
初始状态位置, specified as an- 元素矢量。n是在NumStateVariables
property ofssObj
.
state2
—Final state position
n-element vector|m-经过-nmatrix of row vectors
Final state position, specified as an- 元素矢量。n是在NumStateVariables
property ofssObj
.
比率
—Ratio values for interpolating along path
m-element vector
Ratio values for interpolating along path, specified as anm- 元素矢量。These ratios determine how to sample between the two states.
Output Arguments
例子
创建自定义状态空间以进行路径规划
此示例显示了如何使用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.
在此示例中,您使用预定义指定正常和统一的分布属性值
NormalDistribution
和UniformDistribution
课程。在此处指定任何其他用户定义的属性值。
方法功能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
指定复制
方法定义。将用户定义变量的所有值复制到新对象中,因此CopyObj
is 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 thestate1
和state2
输入以定义开始和终点位置。两个输入都可以是单个状态(行矢量)或多个状态(行向量的矩阵)。在此示例中,根据每对状态位置之间的欧几里得距离计算距离。
功能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
matlab命令
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择一个网站
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:.
您还可以从以下列表中选择一个网站:
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.
美洲
- AméricaLatina(Español)
- 加拿大(英语)
- 美国(英语)