資源簡介
matla運行APROBOT腳本即可實現人工勢場法的仿真。使用vrep中的三輪小車,構建其運動的環境,包括轉向角度,以及轉向速度等。
本程序尋找的并不是最優路徑,可適當改變轉彎角度以及轉彎速度進行優化。其中astart,m是經典的人工勢場法程序,非常好理解,potential.pdf是介紹該算法非常直觀的一篇論文。

代碼片段和文件信息
function?APRobot()
%UNtitleD2?此處顯示有關此函數的摘要
%???此處顯示詳細說明
%???定義vrep與matlab連接的相關模塊
????disp(‘Program?started‘);
????%?vrep=remApi(‘remoteApi‘‘extApi.h‘);?%?using?the?header?(requires?a?compiler)
????vrep=remApi(‘remoteApi‘);?%?using?the?prototype?file?(remoteApiProto.m)
????vrep.simxFinish(-1);?%?just?in?case?close?all?opened?connections
????clientID=vrep.simxStart(‘127.0.0.1‘19997truetrue50005);???
????[~MotorLeft]?=?vrep.simxGetobjectHandle(clientID‘leftmotor‘vrep.simx_opmode_blocking);
????[~MotorRight]?=?vrep.simxGetobjectHandle(clientID‘rightmotor‘vrep.simx_opmode_blocking);
%???五個超聲波傳感器,探測機器人左、左前、前、右前、右方向上的障礙物
????[~LeftSensingNoseHandle]?=?vrep.simxGetobjectHandle(clientID‘LeftSensing‘vrep.simx_opmode_blocking);
????[~RightSensingNoseHandle]?=?vrep.simxGetobjectHandle(clientID‘RightSensing‘vrep.simx_opmode_blocking);
????[~FrontSensingNoseHandle]?=?vrep.simxGetobjectHandle(clientID‘FrontSensing‘vrep.simx_opmode_blocking);
????[~RightFrontSensingNoseHandle]?=?vrep.simxGetobjectHandle(clientID‘RightFrontSensing‘vrep.simx_opmode_blocking);
????[~LeftfFrontSensingNoseHandle]?=?vrep.simxGetobjectHandle(clientID‘LeftFrontSensing‘vrep.simx_opmode_blocking);
%???機器人與目標句柄??
????[~BubbleRob]?=?vrep.simxGetobjectHandle(clientID‘BubbleRob‘vrep.simx_opmode_blocking);
????[~goalhandle]=vrep.simxGetobjectHandle(clientID‘goal‘vrep.simx_opmode_blocking);%獲得目標句柄
????%minMaxSpeed?=?{50*pi/180300*pi/180};??%Min?and?max?speeds?for?each?motor
%???各部分模塊定義結束
????pathFound=false;?%?has?goal?been?reached
%???人工勢場法相關定義
????robotSpeed=[-4?-4];?%?arbitrary?units?
????distanceThreshold?=?1;%障礙物影響的距離
????k=100;?%?degree?of?calculating?potential?
????attractivePotentialScaling=100;?%?scaling?factor?for?attractive?potential
????repulsivePotentialScaling=1000;?%?scaling?factor?for?repulsive?potential
????minAttractivePotential=0.5;?%?minimum?attractive?potential?at?any?point?????
????
%???全局變量用作計算勢能用
????distanceFront?=?0;
????distanceLeft?=?0;
????distanceRight?=?0;
????distanceFrontLeft?=?0;
????distanceFrontRight?=?0;?
????distanceGoal?=?0;
????angleGoal?=?0;
????currentDirection=0;
????speednew?=?0;
????if?(clientID>-1)?
????????tic;
????????disp(‘Connected?to?remote?API?server‘);
????????vrep.simxStartSimulation(clientIDvrep.simx_opmode_oneshot);
????????vrep.simxSetJointTargetVelocity(clientIDMotorLeftrobotSpeed(1)vrep.simx_opmode_oneshot);
????????vrep.simxSetJointTargetVelocity(clientIDMotorRightrobotSpeed(2)vrep.simx_opmode_oneshot);
?????????
%???????獲取目標的位置
????????[returnCodeGoalPositionXYZ]=vrep.simxGetobjectPosition(clientIDgoalhandle-1vrep.simx_opmode_blocking);%獲得目標的位置
????????if(returnCode==vrep.simx_return_ok)
????????????goal?=?GoalPositionXYZ(:1:2);%所有行的第一列和第二列
????????????fprintf(“goal?is:(%2.3f%2.3f)\n“goal);??????
????????else
????????????fprintf(“Invalid?Goal!?the?error?code?is:?%d\n“returnCode);??????
????????end?
????????%while?toc<10?
??????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????627121??2018-06-13?16:11??BubbleRob\20180607.ttt
?????文件?????625953??2018-06-05?13:32??BubbleRob\BubbleRob.ttt
?????文件??????12748??2018-06-13?11:06??BubbleRob\MATLAB_VREP_workspace\APRobot.m
?????文件???????7351??2018-06-07?20:49??BubbleRob\MATLAB_VREP_workspace\astart.m
?????文件????????557??2014-06-06?15:35??BubbleRob\MATLAB_VREP_workspace\distanceCost.m
?????文件????????792??2018-05-30?14:56??BubbleRob\MATLAB_VREP_workspace\feasiblePoint.m
?????文件?????251078??2014-06-06?15:35??BubbleRob\MATLAB_VREP_workspace\map1.bmp
?????文件?????251078??2018-06-05?09:40??BubbleRob\MATLAB_VREP_workspace\map2.bmp
?????文件?????251078??2014-06-06?15:35??BubbleRob\MATLAB_VREP_workspace\map3.bmp
?????文件?????251078??2014-06-06?15:35??BubbleRob\MATLAB_VREP_workspace\map4.bmp
?????文件?????251078??2014-06-06?15:35??BubbleRob\MATLAB_VREP_workspace\map5.bmp
?????文件????????848??2018-05-15?16:33??BubbleRob\MATLAB_VREP_workspace\matlab.mat
?????文件?????750054??2018-01-27?15:41??BubbleRob\MATLAB_VREP_workspace\my_map.bmp
?????文件???????5580??2018-06-04?21:33??BubbleRob\MATLAB_VREP_workspace\obstacle.m
?????文件???????1537??2018-05-31?11:00??BubbleRob\MATLAB_VREP_workspace\plotRobot.m
?????文件?????192524??2014-06-06?15:35??BubbleRob\MATLAB_VREP_workspace\potential.pdf
?????文件???????1089??2019-04-02?22:41??BubbleRob\MATLAB_VREP_workspace\readMe.txt
?????文件?????100875??2018-01-25?17:03??BubbleRob\MATLAB_VREP_workspace\remApi.m
?????文件??????70656??2018-01-25?17:03??BubbleRob\MATLAB_VREP_workspace\remoteApi.dll
?????文件??????35378??2018-01-25?17:03??BubbleRob\MATLAB_VREP_workspace\remoteApiProto.m
?????文件???????2716??2018-06-02?15:49??BubbleRob\MATLAB_VREP_workspace\simpleTest.m
?????文件???????9885??2018-06-04?21:43??BubbleRob\MATLAB_VREP_workspace\turn.m
?????文件???????1417??2018-06-12?16:05??BubbleRob\MATLAB_VREP_workspace\TurnSpeed.m
?????目錄??????????0??2019-04-02?22:29??BubbleRob\MATLAB_VREP_workspace
?????目錄??????????0??2019-04-02?22:29??BubbleRob
-----------?---------??----------?-----??----
??????????????3702471????????????????????25
- 上一篇:vwap算法交易詳解
- 下一篇:ZeroServer_01
評論
共有 條評論