generate off-凯发k8网页登录
this example shows how to generate inertial measurement unit (imu) readings from a sensor that is mounted on a ground vehicle. depending on the location of the sensor, the imu accelerations are different.
create trajectory
specify the waypoint trajectory of a vehicle and compute the vehicle poses using lookuppose
.
% sampling rate. fs = 100; % waypoints and times of arrival. waypoints = [1 1 1; 3 1 1; 3 0 0; 0 0 0]; t = [1; 10; 20; 30]; % create trajectory and compute pose. traj = waypointtrajectory(waypoints, t, "samplerate", fs); [posveh, orientveh, velveh, accveh, angvelveh] = lookuppose(traj, ... t(1):1/fs:t(end));
create sensor and define offset
create two 9-axis imusensor
objects composed of accelerometer, gyroscope, and magnetometer sensors. one imusensor
object generates readings of an imu mounted at the vehicle's origin and the other one generates readings of an imu mounted at the driver's seat. next, specify the offset between the vehicle origin and the imu mounted at the driver's seat. call helperplotimu
to visualize the locations of the sensors.
% imu at vehicle origin. imu = imusensor("accel-gyro-mag", "samplerate", fs); % imu at driver's seat. mountedimu = imusensor("accel-gyro-mag", "samplerate", fs); % position and orientation offset of the vehicle and the mounted imu. posveh2imu = [2.4 0.5 0.4]; orientveh2imu = quaternion([0 0 90], "eulerd", "zyx", "frame"); % visualization. helperplotimu(posveh(1,:), orientveh(1,:), posveh2imu, orientveh2imu);
calculate imu trajectory using vehicle trajectory
compute the ground truth trajectory of the imu mounted at the driver's seat using the transformmotion
function. this function uses the position and orientation offsets and the vehicle trajectory to compute the imu trajectory.
[posimu, orientimu, velimu, accimu, angvelimu] = transformmotion( ... posveh2imu, orientveh2imu, ... posveh, orientveh, velveh, accveh, angvelveh);
generate sensor readings
generate the imu readings for both the imu mounted at the vehicle origin and the imu mounted at the driver's seat.
% imu at vehicle origin. [accel, gyro, mag] = imu(accveh, angvelveh, orientveh); % imu at driver's seat. [accelmounted, gyromounted, magmounted] = mountedimu( ... accimu, angvelimu, orientimu);
compare accelerometer readings
compare the accelerometer readings of the two imus. notice that the x-axis acceleration is different because of the off-center location.
figure('name', 'accelerometer comparison') subplot(3, 1, 1) plot([accel(:,1), accelmounted(:,1)]) legend('aligned with vehicle', 'off-centered') title('accelerometer') ylabel('x-axis (m/s^2)') subplot(3, 1, 2) plot([accel(:,2), accelmounted(:,2)]) ylabel('y-axis (m/s^2)') subplot(3, 1, 3) plot([accel(:,3), accelmounted(:,3)]) ylabel('z-axis (m/s^2)')
compare gyroscope readings
compare the gyroscope readings of the two imus.
figure('name', 'gyroscope comparison') subplot(3, 1, 1) plot([gyro(:,1), gyromounted(:,1)]) ylim([-0.22 0.1]) legend('aligned with vehicle', 'off-centered') title('gyroscope') ylabel('x-axis (rad/s)') subplot(3, 1, 2) plot([gyro(:,2), gyromounted(:,2)]) ylabel('y-axis (rad/s)') subplot(3, 1, 3) plot([gyro(:,3), gyromounted(:,3)]) ylabel('z-axis (rad/s)')
compare magnetometer readings
compare the magnetometer readings of the two imus.
figure('name', 'magnetometer comparison') subplot(3, 1, 1) plot([mag(:,1), magmounted(:,1)]) legend('aligned with vehicle', 'off-centered') title('magnetometer') ylabel('x-axis (\mut)') subplot(3, 1, 2) plot([mag(:,2), magmounted(:,2)]) ylabel('y-axis (\mut)') subplot(3, 1, 3) plot([mag(:,3), magmounted(:,3)]) ylabel('z-axis (\mut)')