面试了三家公司 对应的是高级工程师(P7)
最后去了外企做了产品经理 很狗血的一年 。专门负责自动驾驶仿真平台的设计开发。
自动驾驶仿真 说实话我也搞不清 到底是什么?
本人是基于Dspace系统跟德国人学习的知识、包括车辆模型 算法模型 高精度地图的制作 (还傻呵呵的把Gis的知识学了)测试用例设计 结果分析。
其实仿真测试 总结来说 输入车辆模型+算法+测试场景=输出 整体预期 多种信号交互
仿真玩渲染nefr都过时,现在大模型套小模型。
给仿真平台排个等级:代表个人观点
- Dspace 别问什么优点 你想要的他都有 缺点 贵!
- Nvada 别问什么优点 计算厉害 缺点 行业报价 5000万刀一年
- NI 别问什么优点 可改性强 缺点 我也不知道
- Apollo 别问什么优点 免费
- carmaker 别问什么优点 缺点我知道 厂家技术支持没有我懂得多
以下是一个基于MPC的速度控制示例代码,用于Carsim Simulink自动驾驶仿真中的应用:
在此代码中,首先定义了模型参数,包括采样时间、预测时域、状态权重矩阵和控制权重矩阵。然后,定义了车辆模型参数,包括质量、阻尼系数、弹簧系数和重力加速度。接下来,根据车辆模型参数构造了车辆模型。然后,使用车辆模型和MPC参数构造了MPC控制器。然后,设置了MPC控制器的权重。接下来,构造了仿真模型,并设置了仿真参数。最后,运行了仿真,并绘制了结果图。
% 定义模型参数
Ts = 0.01; % 采样时间
N = 10; % 预测时域
Q = diag([1, 1]); % 状态权重矩阵
R = 1; % 控制权重矩阵
% 车辆模型参数
m = 1000; % 质量
b = 50; % 阻尼系数
c = 5000; % 弹簧系数
g = 9.81; % 重力加速度
% 构造车辆模型
A = [0 1; -c/m -b/m];
B = [0; 1/m];
C = [1 0; 0 1];
D = 0;
% 构造MPC控制器
sys = ss(A, B, C, D);
mpc_controller = mpc(sys, Ts, N);
mpc_controller.Model.Nominal.T = Ts;
% 设置MPC控制器权重
mpc_controller.Weights.MVRate = 0.1;
mpc_controller.Weights.MV = 1;
% 构造仿真模型
sim_model = 'sim_model';
open_system(sim_model);
set_param(sim_model, 'SimulationMode', 'external');
set_param(sim_model, 'SimulationCommand', 'connect');
% 设置仿真参数
sim_time = 10;
sim_step = Ts;
sim_start_speed = 0;
% 运行仿真
sim(sim_model, sim_time);
% 绘制结果
figure;
subplot(3, 1, 1);
plot(simout.Time, simout.Speed);
xlabel('Time (s)');
ylabel('Speed (m/s)');
title('Vehicle Speed');
subplot(3, 1, 2);
plot(simout.Time, simout.Setpoint);
xlabel('Time (s)');
ylabel('Setpoint (m/s)');
title('Speed Setpoint');
subplot(3, 1, 3);
plot(simout.Time, simout.Acceleration);
xlabel('Time (s)');
ylabel('Acceleration (m/s^2)');
title('Vehicle Acceleration');
在MATLAB中进行雷达仿真可以使用MATLAB的雷达工具箱(Phased Array System Toolbox)和信号处理工具箱(Signal Processing Toolbox)。下面是一个使用MATLAB进行雷达仿真的简单示例:
这个示例中使用了FMCW(Frequency Modulated Continuous Wave)波形进行雷达信号的生成和处理。首先设置了雷达的参数,包括工作频率、发射功率、天线增益等。然后使用FMCWWaveform生成FMCW波形,并使用Transmitter模拟发射器,ReceiverPreamp模拟接收器。利用IsotropicAntennaElement模拟天线。
通过FreeSpace模拟自由空间传播信道,将发射的信号和目标位置传入传播信道进行接收信号的仿真。接收到的信号通过ReceiverPreamp进行增益处理。
最后使用AngleEstimator估计目标的方位角,并将结果显示出来。
% 雷达参数设置
frequency = 77e9; % 雷达工作频率
transmitPower = 1e3; % 发射功率
antennaGain = 20; % 天线增益
targetRange = 100; % 目标距离
targetRCS = 10; % 目标雷达散射截面
% 计算雷达返回信号
waveform = phased.FMCWWaveform('SampleRate', 1e6, 'SweepTime', 10e-6);
transmitter = phased.Transmitter('PeakPower', transmitPower);
receiver = phased.ReceiverPreamp('Gain', antennaGain);
antenna = phased.IsotropicAntennaElement('FrequencyRange', [1e9, 100e9]);
channel = phased.FreeSpace('PropagationSpeed', physconst('LightSpeed'), 'OperatingFrequency', frequency, 'TwoWayPropagation', true);
% 目标位置
targetPos = [targetRange; 0; 0];
% 发射雷达信号
transmittedSignal = step(waveform);
transmittedSignal = step(transmitter, transmittedSignal);
% 接收雷达信号
receivedSignal = step(channel, transmittedSignal, targetPos);
receivedSignal = step(receiver, receivedSignal);
% 目标信号处理
angleEstimator = phased.AngleEstimator('SampleRate', waveform.SampleRate, 'OperatingFrequency', frequency);
doa = step(angleEstimator, receivedSignal);
% 显示结果
disp(['目标方位角:', num2str(doa)]);
python ACC仿真器被定义为一个类ACCSimulator
,它具有目标速度和当前速度两个属性,并且有一个run_simulation
方法来运行仿真过程。在仿真过程中,通过调用get_distance_to_front_vehicle
方法获取前方车辆的距离,并根据距离计算出合适的加速度,然后调用update_speed
方法来更新当前速度。最后,通过打印当前速度和模拟ACC控制器的时间间隔,模拟整个ACC的工作过程。
基于pygame游戏引擎 使用前馈遗传 这个大家自己看吧
import pygame
import numpy
from car import car, entity
from menu import button, toggle, text
from network import load
from random import choice
pygame.init()
state = 'RUN'
SCREEN_SIZE = ( 450, 700)
SCREEN = pygame.display.set_mode(SCREEN_SIZE)
pygame.display.set_caption('Autodriven')
pygame.display.set_icon(pygame.image.load('./assets/favicon.png'))
MARK_FILL = 20
MARK_GAP = 10
lane_onset = -(MARK_FILL+MARK_GAP)
# manual = False
ROAD = pygame.Rect( 100, lane_onset, 300, 800)
SIDEWALL_LEFT = pygame.Rect( 90, lane_onset, 10, 800)
SIDEWALL_RIGHT = pygame.Rect( 400, lane_onset, 10, 800)
PLAYER_IMG = pygame.image.load('./assets/vehicles/yellow.png')
players = []
traffic = []
reload = button( (32,32), (40,120), './assets/sidebar/refresh.png', 'RELOAD')
save = button( (32,32), (40,200), './assets/sidebar/save.png', 'SAVE')
pause = toggle( (32,32), (40,280), './assets/sidebar/pause.png', './assets/sidebar/play.png', 'PAUSE', 'PLAY')
# TRAFFIC_XY = [ (350,-100), (240,-100), (130,-100), (180,-100), (290,-100) ]
TRAFFIC_XY = [ [(350,-100), (235,-100), (130,-100)], [(190,-100), (290,-100)] ]
TRAFFIC_IMG = [ './assets/vehicles/orange.png', './assets/vehicles/red.png', './assets/vehicles/truck.png',
'./assets/vehicles/orange.png', './assets/vehicles/red.png', './assets/vehicles/cyan.png',
'./assets/vehicles/semi.png', './assets/vehicles/white.png', './assets/vehicles/cyan.png',
'./assets/vehicles/semi.png', './assets/vehicles/white.png']
TRAFFIC_IMG = list(map( pygame.image.load, TRAFFIC_IMG))
crowd_control = 1
TRAFFIC_EVENT = pygame.USEREVENT
pygame.time.set_timer( TRAFFIC_EVENT, 1500)
# MUTATION_EVENT = pygame.USEREVENT
# pygame.time.set_timer( MUTATION_EVENT, 2000)
def reset():
global traffic, lane_onset, players, survivor, state
MUTATION_RATE = 0.12
NOC = 50
state = 'RUN'
# manual = False
traffic = [ ]
try:
players = [ car( PLAYER_IMG, (235,600), network=load('./exp.pickle')) ]
for _ in range(NOC-1):
players.append( car( PLAYER_IMG, (235,600), network=players[0].ai.mutate(MUTATION_RATE)))
except(FileNotFoundError):
players = [ car( PLAYER_IMG, (235,600)) for _ in range(NOC-1) ]
survivor = players[0]
lane_onset = -(MARK_FILL+MARK_GAP)
def mark_lanes( surface, color, start, end, length, gap):
marks = [ (i,i+length) for i in range( start[1], end[1], length+gap)]
for mark in marks:
pygame.draw.line( surface, color, ( start[0], mark[0]), ( end[0], mark[1]))
reset()
user_info = text( (50,16), (250,650))
info_time_window = 0
survivor = players[0]
# SIMULATION LOOP
while state != 'END':
# UPDATES
pygame.time.delay(60)
pygame.display.update()
keys = pygame.key.get_pressed()
clicked = False
for event in pygame.event.get():
# print(event)
# CLOSE
if event.type == pygame.QUIT:
state = 'END'
# MOUSE CLICK [ FOR SIDEBAR ]
if event.type == pygame.MOUSEBUTTONDOWN:
clicked = True
# EVOLVE NETWORK
# if event.type == MUTATION_EVENT and len(players):
# for new_cars in range(3):
# players.append( car( PLAYER_IMG, ( survivor.rect.x, survivor.rect.y),
# network = survivor.ai.mutate(0.15),
# speed = survivor.speed,
# angle = survivor.angle))
# INCREASE TRAFFIC
if event.type == TRAFFIC_EVENT and state != 'PAUSED':
# ELIMINATE OLD TRAFFIC
for obstacle in traffic:
if obstacle.rect.y > 800 or obstacle.rect.y < -40:
traffic.remove(obstacle)
# new_row = TRAFFIC_XY.copy()
# for i in range(crowd_control):
# new_row.remove(choice(new_row))
new_row = choice(TRAFFIC_XY)
mark = choice(new_row)
for place in new_row:
if place != mark:
traffic.append( entity( choice(TRAFFIC_IMG), place))
# CONTROLS
# if manual:
# LEFT = keys[pygame.K_LEFT] or keys[pygame.K_KP4]
# UP = keys[pygame.K_UP] or keys[pygame.K_KP8]
# RIGHT = keys[pygame.K_RIGHT] or keys[pygame.K_KP6]
if reload.listen(clicked):
reset()
if save.listen(clicked):
survivor.ai.serialize('./exp.pickle')
info_time_window = 20
if keys[pygame.K_SPACE] or pause.listen(clicked):
pygame.time.delay(60)
if state == 'RUN':
state = 'PAUSED'
elif state == 'PAUSED':
state = 'RUN'
elif state == 'PAUSED':
if info_time_window:
user_info.display( SCREEN, 'MODEL SAVED')
info_time_window -= 1
continue
if not len(players):
continue
# UPDATE SURVIVOR
lead = min( [ player.rect.y for player in players ] )
if survivor not in players or survivor.rect.y != lead:
for player in players:
if player.rect.y == lead:
survivor = player
# BG
SCREEN.fill((0,0,0))
if players:
lane_onset += int(numpy.cos(numpy.radians(survivor.angle))*survivor.speed)
if lane_onset > 0:
lane_onset = -( MARK_FILL + MARK_GAP)
for obstacle in traffic:
obstacle.move( 8-survivor.speed)
# SIDEBAR
save.display(SCREEN)
reload.display(SCREEN)
pause.display( SCREEN, state != 'PAUSED')
# ROAD AND SIDEWALL
pygame.draw.rect( SCREEN, ( 32, 32, 32), ROAD)
pygame.draw.rect( SCREEN, ( 255, 255, 255), SIDEWALL_LEFT)
pygame.draw.rect( SCREEN, ( 255, 255, 255), SIDEWALL_RIGHT)
# LANE MARKINGS
mark_lanes( SCREEN, ( 255, 255, 0), ( 200, lane_onset), ( 200, 900), 20, 10)
mark_lanes( SCREEN, ( 255, 255, 0), ( 300, lane_onset), ( 300, 900), 20, 10)
# CAR
for player in players:
# MOVEMENT
player.move([ SIDEWALL_LEFT, SIDEWALL_RIGHT] + [ i.rect for i in traffic])
# SENSOR
if player == survivor:
player.cast_rays( SCREEN, [ SIDEWALL_LEFT, SIDEWALL_RIGHT] + [ i.rect for i in traffic])
player.display(SCREEN)
else:
player.cast_rays( SCREEN, [ SIDEWALL_LEFT, SIDEWALL_RIGHT] + [ i.rect for i in traffic], False)
player.display( SCREEN, 50)
# ADJUST CAMERA
if survivor.rect.y > 500 :
player.rect.y -= 2
else:
player.rect.y += survivor.speed - player.speed
# REMOVE DAMAGED CAR
if player.damaged or player.rect.y > 800:
players.remove(player)
# TRAFFIC
for obstacle in traffic:
obstacle.display(SCREEN)
# USER - INFO
if state == 'PAUSED':
user_info.display( SCREEN, 'SIMULATION PAUSED')
if info_time_window:
user_info.display( SCREEN, 'MODEL SAVED')
info_time_window -= 1
pygame.quit()
import random
class ACCSimulator:
def __init__(self, target_speed):
self.target_speed = target_speed
self.current_speed = 0
def update_speed(self, acceleration):
self.current_speed += acceleration
def get_distance_to_front_vehicle(self):
# 在这里可以调用传感器获取到前方车辆的距离
# 这里我们使用随机数来模拟前方车辆的距离
return random.randint(1, 10)
def run_simulation(self):
while True:
# 获取到前方车辆的距离
distance = self.get_distance_to_front_vehicle()
# 计算加速度
acceleration = self.calculate_acceleration(distance)
# 更新速度
self.update_speed(acceleration)
# 打印当前速度
print("Current Speed:", self.current_speed)
# 模拟ACC控制器的时间间隔
time.sleep(0.1)
def calculate_acceleration(self, distance):
# 根据当前速度和前方车辆的距离,计算出合适的加速度
# 如果前方没有车辆,则加速至目标速度
if distance == float('inf'):
return 1.0
# 如果距离太近,则减速
if distance < 5:
return -1.0
# 如果距离适中,则维持当前速度
return 0.0
# 创建一个ACC仿真器,目标速度设定为60
simulator = ACCSimulator(60)
# 启动仿真
simulator.run_simulation()