Main Content

isMotionValid

Class:NAV.StateValidator
包裹:nav

Check if path between states is valid

Description

例子

[[isValid,,,,LASTVALID] = isMotionValid(validatorObj,,,,state1,,,,state2确定两个状态之间的运动是否通过在状态之间插值来有效。该函数还返回沿路径的最后一个有效状态。

A default implementation for this method is provided when you callcreatePlanningTemplate

输入参数

expand all

状态验证器对象,从一个子类指定为对象NAV.StateValidator。对于提供的状态验证器对象,请参阅validatorOccupancyMapor验证器弗切切克斯特图

初始状态位置,指定为n- 元素矢量orm-by-n行向量的矩阵。n是在状态空间属性中指定的状态空间的维度validatorObj

最终状态位置,指定为n- 元素矢量orm-by-n行向量的矩阵。n是在状态空间属性中指定的状态空间的维度validatorObj

输出参数

expand all

有效状态,指定为m- 元素矢量of10s。

数据类型:逻辑

Final valid state along path, specified as an- 元素矢量。n是在状态空间属性中指定的状态空间的维度validatorObj

Examples

expand all

This example shows how to use thecreatePlanningTemplate函数以生成用于自定义您自己的状态验证类的模板。状态验证与路径规划算法一起使用,以确保有效的路径。模板功能提供了一个基本实现,例如目的。

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

createPlanningTemplate("StateValidator"

班级和属性定义

模板的第一部分指定类定义和类的任何属性。来自NAV.StateValidator班级。您可以在此处指定任何其他用户定义的属性。

ClassDefmycustomStateValidator ...matlabshared.planning.internal.enforcescalarhandleproperties%用户定义的属性结尾

保存您的自定义状态验证器类,并确保您的文件名与类名称匹配。

Class Constructor

使用构造函数设置状态空间验证器的名称并指定状态空间对象。如果未提供一个状态空间,请为状态空间设置默认值。调用基类的构造函数。初始化任何其他用户定义的属性。此示例使用默认MyCustomStateSpace,,,,which was illustrated in the previous example.

methodsfunctionobj = mycustomStateValidator(Space)Narginchk(0,1)ifnargin == 0 space = MyCustomStateSpace;结尾obj@nav.StateValidator(space);%初始化用户定义的属性结尾

复制语义

Specify thecopymethod definition. Copy all the values of your user-defined variables into a new object, socopyObjis a deep copy. The default behavior given in this example creates a new copy of the object with the same type.

functioncopyObj = copy(obj) copyObj = feval(class(obj), obj.StateSpace);结尾

检查状态有效性

定义如何验证给定状态。这状态输入可以是单行向量,也可以是多个状态的行向量的矩阵。自定义此功能,以适用于您的状态空间的任何特殊验证行为,例如碰撞检查障碍。

functionisValid = isStateValid(obj, state) narginchk(2,2); nav.internal.validation.validateStateMatrix(state, nan, obj.StateSpace.NumStateVariables,..."isStateValid",,,,"state");bounds = obj.StateSpace.StateBounds'; inBounds = state >= bounds(1,:) & state <= bounds(2,:); isValid = all(inBounds, 2);结尾

检查运动有效性

定义如何生成状态之间的运动并确定其是否有效。对于此示例,请使用linspace在状态之间均匀插值并检查这些状态是否有效isStateValid。自定义此功能以在状态之间进行样本或考虑其他分析方法,以确定车辆是否可以在给定状态之间移动。

function[Isvalid,lastValid] = ismotionValid(obj,state1,state2)narginchk(3,3);state1 = nav.internal.validation.ValidateStateTateVector(state1,...obj.Statespace.numstatevariables,"isMotionValid",,,,“ state1”);state2 = nav.internal.validation.ValidateStateTateVector(state2,...obj.Statespace.numstatevariables,"isMotionValid",,,,“ state2”);if(〜OBJ.ISSTATEVALID(state1))错误(“状态活动:StartStateInvalid”,,,,“运动的开始状态无效。”);结尾%以状态和检查状态有效性之间的固定间隔插值%numInterppoints = 100;interpstates = obj.statespace.interpaly(state1,state2,linspace(0,1,num InterPlaints)));interpvalid = obj.isstatevalid(interpstates);% Look for invalid states. Set lastValid state to index-1.firstInvalidIdx = find(~interpValid, 1);ifIsempty(first invalidx)isvalid = true;lastValid = state2;elseiSvalid = false;lastValid = interpstates(first invalidx-1,:);结尾结尾

Terminate the methods and class sections.

结尾结尾

保存您的状态空间验证器类定义。现在,您可以使用类构造函数创建一个对象,以验证给定状态空间的状态。

版本历史记录

在R2019b中引入