# modelstates

States for motion model

## Description

## Examples

### Customize Motion Model Used with `insEKF`

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: [5x1 double] StateCovariance: [5x5 double] AdditiveProcessNoise: [5x5 double] MotionModel: [1x1 ConstantVelocityMotion] Sensors: {[1x1 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.m`

classdef 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. % Deriviative of position = velocity. % Deriviative 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

`filter`

— INS filter

`insEKF`

object

INS filter, specified as an `insEKF`

object.

`options`

— Options for INS filter

`insOptions`

object

Options for the INS filter, specified as an `insOptions`

object.

## Output Arguments

`s`

— State structure

structure

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

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## 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.

# Select a Web Site

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: .

You can also select a web site from the following list:

## 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.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- 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)