Inertial navigation and GPS simulation model
The insSensor
System object™ models data output from an inertial navigation and GPS.
To model output from an inertial navigation and GPS:
Create the insSensor
object and set its properties.
Call the object with arguments, as if it were a function.
To learn more about how System objects work, see What Are System Objects?.
Unless otherwise indicated, properties are nontunable, which means you cannot change their
values after calling the object. Objects lock when you call them, and the
release
function unlocks them.
If a property is tunable, you can change its value at any time.
For more information on changing property values, see System Design in MATLAB Using System Objects.
RollAccuracy
— Accuracy of roll measurement (deg)0.2
(default) | nonnegative real scalarAccuracy of the roll measurement of the sensor body in degrees, specified as a nonnegative real scalar.
Roll is defined as rotation around the x-axis of the sensor body.
Roll noise is modeled as a white noise process. RollAccuracy
sets
the standard deviation, in degrees, of the roll measurement noise.
Tunable: Yes
Data Types: single
| double
PitchAccuracy
— Accuracy of pitch measurement (deg)0.2
(default) | nonnegative real scalarAccuracy of the pitch measurement of the sensor body in degrees, specified as a nonnegative real scalar.
Pitch is defined as rotation around the y-axis of the sensor
body. Pitch noise is modeled as a white noise process.
PitchAccuracy
defines the standard deviation, in degrees, of the
pitch measurement noise.
Tunable: Yes
Data Types: single
| double
YawAccuracy
— Accuracy of yaw measurement (deg)1
(default) | nonnegative real scalarAccuracy of the yaw measurement of the sensor body in degrees, specified as a nonnegative real scalar.
Yaw is defined as rotation around the z-axis of the sensor body.
Yaw noise is modeled as a white noise process. YawAccuracy
defines
the standard deviation, in degrees, of the yaw measurement noise.
Tunable: Yes
Data Types: single
| double
PositionAccuracy
— Accuracy of position measurement (m)1
(default) | nonnegative real scalarAccuracy of the position measurement of the sensor body in meters, specified as a nonnegative real scalar.
Position noise is modeled as a white noise process.
PositionAccuracy
defines the standard deviation, in meters, of
the position measurement noise.
Tunable: Yes
Data Types: single
| double
VelocityAccuracy
— Accuracy of velocity measurement (m/s)0.05
(default) | nonnegative real scalarAccuracy of the velocity measurement of the sensor body in meters per second, specified as a nonnegative real scalar.
Velocity noise is modeled as a white noise process.
VelocityAccuracy
defines the standard deviation, in meters per
second, of the velocity measurement noise.
Tunable: Yes
Data Types: single
| double
RandomStream
— Random number source'Global stream'
(default) | 'mt19937ar with seed'
Random number source, specified as a character vector:
'Global stream'
–– Random numbers are generated using the
current global random number stream.
'mt19937ar with seed'
–– Random numbers are generated using
the mt19937ar algorithm with the seed specified by the Seed
property.
Data Types: char
| string
Seed
— Initial seed67
(default) | nonnegative integer scalarInitial seed of an mt19937ar random number generator algorithm, specified as a real, nonnegative integer scalar.
To enable this property, set RandomStream
to
'mt19937ar with seed'
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
models the data received from an inertial navigation and GPS reading. The measurement is
based on the input signal, measurement
= INS(motion
)motion
.
motion
— Ground-truth sensor body motion in local NEDmotion
is a struct with the following fields:
'Position'
–– Position of the sensor body in the local
NED coordinate system specified as a real finite N-by-3 array
in meters. N is the number of samples in the current
frame.
'Velocity'
–– Velocity of the sensor body in the local
NED coordinate system specified as a real finite N-by-3 array
in meters per second. N is the number of samples in the
current frame.
'Orientation'
–– Orientation of the sensor body with
respect to the local NED coordinate system specified as a
quaternion
N-element column vector or a single or double
3-by-3-by-N rotation matrix. Each quaternion or rotation
matrix is a frame rotation from the local NED coordinate system to the current
sensor body coordinate system. N is the number of samples in
the current frame.
Example: motion =
struct('Position',[0,0,0],'Velocity',[0,0,0],'Orientation',quaternion([1,0,0,0]))
measurement
— Measurement of sensor body motion in local NEDmeasurement
is a struct with the following fields:
'Position'
–– Position measurement of the sensor body in
the local NED coordinate system specified as a real finite
N-by-3 array in meters. N is the number of
samples in the current frame.
'Velocity'
–– Velocity measurement of the sensor body in
the local NED coordinate system specified as a real finite
N-by-3 array in meters per second. N is
the number of samples in the current frame.
'Orientation'
–– Orientation measurement of the sensor
body with respect to the local NED coordinate system specified as a quaternion
N-element column vector or a single or double
3-by-3-by-N rotation matrix. Each quaternion or rotation
matrix is a frame rotation from the local NED coordinate system to the current
sensor body coordinate system. N is the number of samples in
the current frame.
To use an object function, specify the
System object as the first input argument. For
example, to release system resources of a System object named obj
, use
this syntax:
release(obj)
insSensor
perturbations | Perturbation defined on object |
perturb | Apply perturbations to object |
Create a motion struct that defines a stationary position at the local NED origin. Because the platform is stationary, you only need to define a single sample. Assume the ground-truth motion is sampled for 10 seconds with a 100 Hz sample rate. Create a default insSensor
System object™. Preallocate variables to hold output from the insSensor
object.
Fs = 100; duration = 10; numSamples = Fs*duration; motion = struct( ... 'Position', zeros(1,3), ... 'Velocity', zeros(1,3), ... 'Orientation', ones(1,1,'quaternion')); INS = insSensor; positionMeasurements = zeros(numSamples,3); velocityMeasurements = zeros(numSamples,3); orientationMeasurements = zeros(numSamples,1,'quaternion');
In a loop, call INS
with the stationary motion struct to return the position, velocity, and orientation measurements in the local NED coordinate system. Log the position, velocity, and orientation measurements.
for i = 1:numSamples measurements = INS(motion); positionMeasurements(i,:) = measurements.Position; velocityMeasurements(i,:) = measurements.Velocity; orientationMeasurements(i) = measurements.Orientation; end
Convert the orientation from quaternions to Euler angles for visualization purposes. Plot the position, velocity, and orientation measurements over time.
orientationMeasurements = eulerd(orientationMeasurements,'ZYX','frame'); t = (0:(numSamples-1))/Fs; subplot(3,1,1) plot(t,positionMeasurements) title('Position') xlabel('Time (s)') ylabel('Position (m)') legend('North','East','Down') subplot(3,1,2) plot(t,velocityMeasurements) title('Velocity') xlabel('Time (s)') ylabel('Velocity (m/s)') legend('North','East','Down') subplot(3,1,3) plot(t,orientationMeasurements) title('Orientation') xlabel('Time (s)') ylabel('Rotation (degrees)') legend('Roll', 'Pitch', 'Yaw')
Generate INS measurements using the insSensor
System object™. Use waypointTrajectory
to generate the ground-truth path. Use trackingScenario
to organize the simulation and visualize the motion.
Specify the ground-truth trajectory as a figure-eight path in the North-East plane. Use a 50 Hz sample rate and 5 second duration.
Fs = 50; duration = 5; numSamples = Fs*duration; t = (0:(numSamples-1)).'/Fs; a = 2; x = a.*sqrt(2).*cos(t) ./ (sin(t).^2 + 1); y = sin(t) .* x; z = zeros(numSamples,1); waypoints = [x,y,z]; path = waypointTrajectory('Waypoints',waypoints,'TimeOfArrival',t);
Create an insSensor
System object to model receiving INS data. Set the PositionAccuracy
to 0.1
.
ins = insSensor('PositionAccuracy',0.1);
Create a tracking scenario with a single platform whose motion is defined by path
.
scenario = trackingScenario('UpdateRate',Fs);
quadcopter = platform(scenario);
quadcopter.Trajectory = path;
Create a theater plot to visualize the ground-truth quadcopter
motion and the quadcopter motion measurements modeled by insSensor
.
tp = theaterPlot('XLimits',[-3, 3],'YLimits', [-3, 3]); quadPlotter = platformPlotter(tp, ... 'DisplayName', 'Ground-Truth Motion', ... 'Marker', 's', ... 'MarkerFaceColor','blue'); insPlotter = detectionPlotter(tp, ... 'DisplayName','INS Measurement', ... 'Marker','d', ... 'MarkerFaceColor','red');
In a loop, advance the scenario until it is complete. For each time step, get the current motion sample, model INS measurements for the motion, and then plot the result.
while advance(scenario) motion = platformPoses(scenario,'quaternion'); insMeas = ins(motion); plotPlatform(quadPlotter,motion.Position); plotDetection(insPlotter,insMeas.Position); pause(1/scenario.UpdateRate) end
Generate INS measurements using the insSensor
System object™. Use waypointTrajectory
to generate the ground-truth path.
Specify a ground-truth orientation that begins with the sensor body x-axis aligned with North and ends with the sensor body x-axis aligned with East. Specify waypoints for an arc trajectory and a time-of-arrival vector for the corresponding waypoints. Use a 100 Hz sample rate. Create a waypointTrajectory
System object with the waypoint constraints, and set SamplesPerFrame
so that the entire trajectory is output with one call.
eulerAngles = [0,0,0; ... 0,0,0; ... 90,0,0; ... 90,0,0]; orientation = quaternion(eulerAngles,'eulerd','ZYX','frame'); r = 20; waypoints = [0,0,0; ... 100,0,0; ... 100+r,r,0; ... 100+r,100+r,0]; toa = [0,10,10+(2*pi*r/4),20+(2*pi*r/4)]; Fs = 100; numSamples = floor(Fs*toa(end)); path = waypointTrajectory('Waypoints',waypoints, ... 'TimeOfArrival',toa, ... 'Orientation',orientation, ... 'SampleRate',Fs, ... 'SamplesPerFrame',numSamples);
Create an insSensor
System object to model receiving INS data. Set the PositionAccuracy
to 0.1
.
ins = insSensor('PositionAccuracy',0.1);
Call the waypoint trajectory object, path
, to generate the ground-truth motion. Call the INS simulator, ins
, with the ground-truth motion to generate INS measurements.
[motion.Position,motion.Orientation,motion.Velocity] = path(); insMeas = ins(motion);
Convert the orientation returned by ins
to Euler angles in degrees for visualization purposes. Plot the full path and orientation over time.
orientationMeasurementEuler = eulerd(insMeas.Orientation,'ZYX','frame'); subplot(2,1,1) plot(insMeas.Position(:,1),insMeas.Position(:,2)); title('Path') xlabel('North (m)') ylabel('East (m)') subplot(2,1,2) t = (0:(numSamples-1)).'/Fs; plot(t,orientationMeasurementEuler(:,1), ... t,orientationMeasurementEuler(:,2), ... t,orientationMeasurementEuler(:,3)); title('Orientation') legend('Yaw','Pitch','Roll') xlabel('Time (s)') ylabel('Rotation (degrees)')
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
You have a modified version of this example. Do you want to open this example with your edits?