Simulate wheel encoder sensor readings for unicycle vehicle
System object™ computes wheel encoder tick readings based on the pose input of a unicycle
To obtain the encoder tick readings:
wheelEncoderUnicycleobject 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?
encoder = wheelEncoderUnicycle
wheelEncoderUnicycle System object
sets properties for the encoder using one or more name-value pairs. For example,
encoder = wheelEncoderUnicycle(
wheelEncoderUnicycle('SampleRate',120) sets the sample rate of the
encoder to 120 Hz. Unspecified properties have default values. Enclose each property name
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.
SampleRate — Sample rate of encoder
100 (default) | positive scalar
Sample rate of the encoder, specified as a positive scalar in Hz.
TicksPerRevolution — Number of encoder ticks per wheel revolution
2048 (default) | positive integer
Number of encoder ticks per wheel revolution, specified as a positive integer.
WheelRadius — Wheel radius
0.35 (default) | positive scalar
Wheel radius, specified as a positive scalar in meters.
WheelRadiusBias — Bias of wheel radius
0 (default) | scalar
Bias of the wheel radius, specified as a scalar in meters.
WheelPositionAccuracy — Standard deviation of wheel position error
0 (default) | nonnegative scalar
Standard deviation of wheel position error, specified as a nonnegative scalar in radians.
SlipRatio — Slip or skid ratio of wheel
0 (default) | scalar
Slip or skid ratio of the wheel, specified as a scalar larger than or equal to –1.
For a wheel that slips (over rotation), specify it as a positive value. A higher value denotes more slipping.
For a wheel that skids (under rotation), specify it as a negative value larger than or equal to –1. A lower value denotes more skidding. For a wheel that does not rotate, specify it as –1.
RandomStream — Random number source
'Global stream' (default) |
'mt19937ar with seed'
Random number source, specified as a character vector or string:
'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 — Initial seed of mt19937ar random number generator algorithm
67 (default) | nonnegative integer
Initial seed of an mt19937ar random number generator algorithm, specified as a nonnegative integer.
To enable this property, set
'mt19937ar with seed'.
return the wheel tick readings
ticks = encoder(
ticks from the specified velocity,
angular velocity, and orientation information.
velocity — Velocity of vehicle
N-by-3 matrix of scalars
Velocity of the vehicle in the local navigation frame, specified as an N-by-3 matrix of scalars in m/s. N is the number of samples.
angularVelocity — Angular velocity of vehicle
N-by-3 matrix of scalars
Angular velocity of the vehicle in the local navigation frame, specified as an N-by-3 matrix of scalars in rad/s. N is the number of samples.
orientation — orientation of vehicle
N-element vector of quaternion | 3-by-3-by-N array of rotation matrices
Orientation of the vehicle in the local navigation frame, specified as an
N-element vector of
a 3-by-3-by-N array of rotation matrices. N is
the number of samples. Each quaternion or rotation matrix is a frame rotation from
the local navigation coordinate system to the current vehicle body coordinate
ticks — Number of wheel ticks per time step
N-element vector of nonnegative integers
Number of wheel ticks the vehicle moved per time step, returned as an N-element vector of nonnegative integers. N is the number of samples.
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
Generate Wheel Ticks from Unicycle Vehicle Pose
Create the wheel encoder sensor.
encoder = wheelEncoderUnicycle;
Define poses of the vehicle.
orient = [quaternion([90 0 0],'eulerd','ZYX','frame'); quaternion([45 0 0], 'eulerd', 'ZYX', 'frame')]; vel = [1 0 0; 0 1 0]; angvel = [0 0 0.2; 0 0 0.1];
Generate wheel ticks from the poses.
ticks = encoder(vel,angvel,orient)
ticks = 2×1 0 6
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).
Introduced in R2020b