✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
⛄ 内容介绍
基于强化学习的数字孪生智慧停车方法,为智慧城市信息物理融合物联网构建提供了一个智能,易用的系统模型.该智慧停车系统支持对实际场景下多车辆自动泊车过程进行实时控制,并能有效避免碰撞,降低人工停车时间成本,减少人为操作失误安全事故的发生.
⛄ 部分代码
clear all; close all;
freeSpotIdx = 26;
map = ParkingLot(freeSpotIdx);
egoInitialPose = [20, 15, 0];
egoTargetPose = createTargetPose(map,freeSpotIdx)
autoParkingValetParams
mdl = 'rlAutoParkingValet';
open_system(mdl)
createMPCForParking
numObservations = 16;
observationInfo = rlNumericSpec([numObservations 1]);
observationInfo.Name = 'observations';
steerMax = pi/4;
discreteSteerAngles = -steerMax : deg2rad(1) : steerMax;
actionInfo = rlFiniteSetSpec(num2cell(discreteSteerAngles));
actionInfo.Name = 'actions';
numActions = numel(actionInfo.Elements);
blk = [mdl '/RL Controller/RL Agent'];
env = rlSimulinkEnv(mdl,blk,observationInfo,actionInfo);
env.ResetFcn = @autoParkingValetResetFcn;
rng(0)
criticNetwork = [
featureInputLayer(numObservations,'Normalization','none','Name','observations')
fullyConnectedLayer(128,'Name','fc1')
reluLayer('Name','relu1')
fullyConnectedLayer(128,'Name','fc2')
reluLayer('Name','relu2')
fullyConnectedLayer(128,'Name','fc3')
reluLayer('Name','relu3')
fullyConnectedLayer(1,'Name','fc4')];
criticOptions = rlRepresentationOptions('LearnRate',1e-3,'GradientThreshold',1);
critic = rlValueRepresentation(criticNetwork,observationInfo,...
'Observation',{'observations'},criticOptions);
actorNetwork = [
featureInputLayer(numObservations,'Normalization','none','Name','observations')
fullyConnectedLayer(128,'Name','fc1')
reluLayer('Name','relu1')
fullyConnectedLayer(128,'Name','fc2')
reluLayer('Name','relu2')
fullyConnectedLayer(numActions, 'Name', 'out')
softmaxLayer('Name','actionProb')];
actorOptions = rlRepresentationOptions('LearnRate',2e-4,'GradientThreshold',1);
actor = rlStochasticActorRepresentation(actorNetwork,observationInfo,actionInfo,...
'Observation',{'observations'},actorOptions);
agentOpts = rlPPOAgentOptions(...
'SampleTime',Ts,...
'ExperienceHorizon',512,...
'ClipFactor',0.2,...
'EntropyLossWeight',0.01,...
'MiniBatchSize',64,...
'NumEpoch',3,...
'AdvantageEstimateMethod',"gae",...
'GAEFactor',0.95,...
'DiscountFactor',0.99);
% 'DiscountFactor',0.998);
agent = rlPPOAgent(actor,critic,agentOpts);
trainOpts = rlTrainingOptions(...
'MaxEpisodes',10000,...
'MaxStepsPerEpisode',200,...
'ScoreAveragingWindowLength',200,...
'Plots','training-progress',...
'StopTrainingCriteria','AverageReward',...
'StopTrainingValue',80,...
'UseParallel',true);
doTraining =0;
if doTraining
tic
trainingStats = train(agent,env,trainOpts);
toc
save('7_Self_rlAutoParkingValetAgent.mat');
else
load('6_Self_rlAutoParkingValetAgent.mat','agent');
end
set(gcf,'position',[500 600 1500 1000])
pause(1)
freeSpotIdx = 26; % free spot location
sim(mdl);
% save('Self_rlAutoParkingValetAgent.mat');
% load('Self_rlAutoParkingValetAgent.mat');
⛄ 运行结果
⛄ 参考文献
[1]肖蓬勃. 基于MATLAB中高档轿车智能泊车系统开发及应用研究[D]. 桂林电子科技大学.
[2]陈慧, 宋绍禹, 孙宏伟,等. 一种基于模型强化学习的智能泊车方法:.