Main Content

Esta página se ha traducido mediante traducción automática. Haga clic aquí para ver la última versión en inglés.

Simule lecturas de sensores inerciales desde un escenario de conducción

Genere datos de sensores sintéticos desde IMU, GPS y codificadores de ruedas utilizando herramientas de generación de escenarios de conducción de Automated Driving Toolbox™. El objeto drivingScenario simula el escenario de conducción y los datos del sensor se generan a partir de imuSensor, gpsSensor y wheelEncoderAckermann objetos.

Definir escenario

Crea un escenario de conducción con un vehículo. Defina puntos de referencia para que el vehículo avance y gire. Para simular lecturas de GPS, especifique la ubicación de referencia en coordenadas geodésicas. Generar la trayectoria del vehículo con la función de objeto smoothTrajectory . Trazar los puntos de referencia.

lla0 = [42 -71 50];
s = drivingScenario('GeoReference',lla0);
v = vehicle(s);

waypoints = [-11 -0.25 0;
    -1 -0.25 0;
    -0.6 -0.4 0;
    -0.6 -9.3 0];
speed = [1.5;0;0.5;1.5];
smoothTrajectory(v,waypoints,speed);

figure
plot(waypoints(:,1),waypoints(:,2),'-o')
xlabel('X (m)')
ylabel('Y (m)')
title('Vehicle Position Waypoints')

Figure contains an axes object. The axes object with title Vehicle Position Waypoints, xlabel X (m), ylabel Y (m) contains an object of type line.

Crear sensores

Cree los sensores IMU, GPS y codificador de ruedas. Especifique la ubicación de compensación y los ángulos de la IMU y el GPS. Estos se pueden editar para cambiar la posición de montaje y la orientación de los sensores en el vehículo.

mountingLocationIMU = [1 2 3];
mountingAnglesIMU = [0 0 0];
% Convert orientation offset from Euler angles to quaternion.
orientVeh2IMU = quaternion(mountingAnglesIMU,'eulerd','ZYX','frame');
% ReferenceFrame must be specified as ENU.
imu = imuSensor('SampleRate',1/s.SampleTime,'ReferenceFrame','ENU');

mountingLocationGPS = [1 2 3];
mountingAnglesGPS = [50 40 30];
% Convert orientation offset from Euler angles to quaternion.
orientVeh2GPS = quaternion(mountingAnglesGPS,'eulerd','ZYX','frame');
% The GeoReference property in drivingScenario is equivalent to
% the ReferenceLocation property in gpsSensor.
% ReferenceFrame must be specified as ENU.
gps = gpsSensor('ReferenceLocation',lla0,'ReferenceFrame','ENU');

encoder = wheelEncoderAckermann('TrackWidth',v.Width,...
    'WheelBase',v.Wheelbase,'SampleRate',1/s.SampleTime);

Ejecutar simulación

Ejecute la simulación y registre las lecturas del sensor generadas.

% IMU readings.
accel = [];
gyro = [];
% Wheel encoder readings.
ticks = [];
% GPS readings.
lla = [];
gpsVel = [];
% Define the rate of the GPS compared to the simulation rate.
simSamplesPerGPS = (1/s.SampleTime)/gps.SampleRate;
idx = 0;
while advance(s)
    groundTruth = state(v);
    
    % Unpack the ground truth struct by converting the orientations from
    % Euler angles to quaternions and converting angular velocities form
    % degrees per second to radians per second.
    posVeh = groundTruth.Position;
    orientVeh = quaternion(fliplr(groundTruth.Orientation), 'eulerd', 'ZYX', 'frame');
    velVeh = groundTruth.Velocity;
    accVeh = groundTruth.Acceleration;
    angvelVeh = deg2rad(groundTruth.AngularVelocity);
    
    % Convert motion quantities from vehicle frame to IMU frame.
    [posIMU,orientIMU,velIMU,accIMU,angvelIMU] = transformMotion( ...
        mountingLocationIMU,orientVeh2IMU, ...
        posVeh,orientVeh,velVeh,accVeh,angvelVeh);
    [accel(end+1,:), gyro(end+1,:)] = imu(accIMU,angvelIMU,orientIMU); 
    
    ticks(end+1,:) = encoder(velVeh, angvelVeh, orientVeh); 
    
    % Only generate a new GPS sample when the simulation has advanced
    % enough.
    if (mod(idx, simSamplesPerGPS) == 0)
        % Convert motion quantities from vehicle frame to GPS frame.
        [posGPS,orientGPS,velGPS,accGPS,angvelGPS] = transformMotion(...
            mountingLocationGPS, orientVeh2GPS,...
            posVeh,orientVeh,velVeh,accVeh,angvelVeh);
        [lla(end+1,:), gpsVel(end+1,:)] = gps(posGPS,velGPS);
    end
    idx = idx + 1;
end

Visualizar resultados

Trazar las lecturas del sensor generado.

figure
plot(ticks)
ylabel('Wheel Ticks')
title('Wheel Encoder')

Figure contains an axes object. The axes object with title Wheel Encoder, ylabel Wheel Ticks contains 4 objects of type line.

figure
plot(accel)
ylabel('m/s^2')
title('Accelerometer')

Figure contains an axes object. The axes object with title Accelerometer, ylabel m/s Squared baseline contains 3 objects of type line.

figure
plot(gyro)
ylabel('rad/s')
title('Gyroscope')

Figure contains an axes object. The axes object with title Gyroscope, ylabel rad/s contains 3 objects of type line.

figure
geoplot(lla(:,1),lla(:,2))
title('GPS Position')

Figure contains an axes object with type geoaxes. The geoaxes object contains an object of type line.

figure
plot(gpsVel)
ylabel('m/s')
title('GPS Velocity')

Figure contains an axes object. The axes object with title GPS Velocity, ylabel m/s contains 3 objects of type line.