基于強化學習實現(xiàn)智能泊車附matlab代碼
?作者簡介:熱愛科研的
開發(fā)者,修心和技術(shù)同步精進,matlab項目合作可私信。??個人主頁:
??個人信條:格物致知。
更多Matlab仿真內(nèi)容點擊??
?? ? ?
? ? ? ? ?
? 內(nèi)容介紹
基于強化學習的數(shù)字孿生智慧停車方法,為智慧城市信息物理融合物聯(lián)網(wǎng)構(gòu)建提供了一個智能,易用的系統(tǒng)模型.該智慧停車系統(tǒng)支持對實際場景下多車輛自動泊車過程進行實時控制,并能有效避免碰撞,降低人工停車時間成本,減少人為操作失誤安全事故的發(fā)生.
? 部分代碼
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');
? 運行結(jié)果



? 參考文獻
[1]肖蓬勃. 基于MATLAB中高檔轎車智能泊車系統(tǒng)開發(fā)及應(yīng)用研究[D]. 桂林電子科技大學.
[2]陳慧, 宋紹禹, 孫宏偉,等. 一種基于模型強化學習的智能泊車方法:.?
? Matlab代碼關(guān)注
??部分理論引用網(wǎng)絡(luò)文獻,若有侵權(quán)聯(lián)系博主刪除
?? 關(guān)注我領(lǐng)取海量matlab電子書和數(shù)學建模資料