modelstates
Description
Examples
Customize a 1-D constant velocity motion model used with an insEKF object. Customize the motion model by inheriting from the positioning.INSMotionModel interface class and implement the modelstates and stateTranistion methods. You can also optionally implement the stateTransitionJacobian method. These sections provide an overview of how the ConstantVelocityMotion class implements the positioning.INSMotionModel methods, but for more details on their implementation, see the attached ConstantVelocityMotion.m file.
Implement modelstates method
To model 1-D constant velocity motion, you need to return only the 1-D position and velocity state as a structure. When you add a ConstantVelocityMotion object to an insEKF filter object, the filter adds the Position and Velocity components to the state vector of the filter.
Implement stateTransition method
The stateTransition method returns the derivatives of the state defined by the motion model as a structure. The derivative of the Position is the Velocity, and the derivative of the Velocity is 0.
Implement stateTransitionJacobian method
The stateTransitionJacobian method returns the partial derivatives of stateTransition method, with respect to the state vector of the filter, as a structure. All the partial derivatives are 0, except the partial derivative of the derivative of the Position component, which is the Velocity, with respect to the Velocity state, is 1.
Create and add inherited object
Create a ConstantVelocityMotion object.
cvModel = ConstantVelocityMotion
cvModel = ConstantVelocityMotion with no properties.
Create an insEKF object with the created cvModel object.
filter = insEKF(insAccelerometer,cvModel)
filter =
insEKF with properties:
State: [5×1 double]
StateCovariance: [5×5 double]
AdditiveProcessNoise: [5×5 double]
MotionModel: [1×1 ConstantVelocityMotion]
Sensors: {[1×1 insAccelerometer]}
SensorNames: {'Accelerometer'}
ReferenceFrame: 'NED'
The filter state contains the Position and Velocity components.
stateinfo(filter)
ans = struct with fields:
Position: 1
Velocity: 2
Accelerometer_Bias: [3 4 5]
Show customized ConstantVelocityMotion class
type ConstantVelocityMotion.mclassdef ConstantVelocityMotion < positioning.INSMotionModel
% CONSTANTVELOCITYMOTION Constant velocity motion in 1-D
% Copyright 2021 The MathWorks, Inc.
methods
function m = modelstates(~,~)
% Return the state of motion model (added to the state of the
% filter) as a structure.
% Since the motion is 1-D constant velocity motion,
% retrun only 1-D position and velocity state.
m = struct('Position',0,'Velocity',0);
end
function sdot = stateTransition(~,filter,~, varargin)
% Return the derivative of each state with respect to time as a
% structure.
% Derivative of position = velocity.
% Derivative of velocity = 0 because this model assumes constant
% velocity.
% Find the current estimated velocity
currentVelocityEstimate = stateparts(filter,'Velocity');
% Return the derivatives
sdot = struct( ...
'Position',currentVelocityEstimate, ...
'Velocity',0);
end
function dfdx = stateTransitionJacobian(~,filter,~,varargin)
% Return the Jacobian of the stateTransition method with
% respect to the state vector. The output is a structure with the
% same fields as stateTransition but the value of each field is a
% vector containing the derivative of that state relative to
% all other states.
% First, figure out the number of state components in the filter
% and the corresponding indices
N = numel(filter.State);
idx = stateinfo(filter);
% Compute the N partial derivatives of Position with respect to
% the N states. The partial derivative of the derivative of the
% Position stateTransition function with respect to Velocity is
% just 1. All others are 0.
dpdx = zeros(1,N);
dpdx(1,idx.Velocity) = 1;
% Compute the N partial derivatives of Velocity with respect to
% the N states. In this case all the partial derivatives are 0.
dvdx = zeros(1,N);
% Return the partial derivatives as a structure.
dfdx = struct('Position',dpdx,'Velocity',dvdx);
end
end
end
Input Arguments
INS filter, specified as an insEKF object.
Options for the INS filter, specified as an insOptions
object.
Output Arguments
State structure, returned as a structure. The field names of the structure are the
names of the states that you want estimate. The insEKF filter object
uses the value of each field as the default value of its corresponding state component,
and uses the size of the value as the size of the corresponding state component.
Tip
You can use the stateparts object
function of the insEKF object to access the states, saved in the
filter.
Version History
Introduced in R2022a
See Also
MATLAB Command
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.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)