|
8 | 8 | persistent mppiObj
|
9 | 9 | persistent mapObj
|
10 | 10 | persistent vehicleObj;
|
11 |
| - persistent constraintViolated; |
| 11 | + persistent numberOfViolations; |
12 | 12 |
|
13 |
| - if isempty(constraintViolated) |
14 |
| - constraintViolated = 0; |
| 13 | + if isempty(numberOfViolations) |
| 14 | + numberOfViolations = 0; |
15 | 15 | end
|
16 | 16 |
|
17 | 17 | if isempty(mapObj)
|
|
30 | 30 | mppiObj.ReferencePath = refPathXY;
|
31 | 31 | end
|
32 | 32 |
|
33 |
| - [velcmds,optpath,info,numTrajs,needLocalReplan,needGlobalReplan] = stepImp(mppiObj, controllerParams, constraintViolated,curpose,curvel); |
| 33 | + [velcmds,optpath,info,numTrajs,needLocalReplan,needGlobalReplan,resetNumViolations] = stepImp(mppiObj, controllerParams, numberOfViolations,curpose,curvel); |
34 | 34 | sampleTime = mppiObj.SampleTime;
|
35 | 35 | trajs = info.Trajectories;
|
36 | 36 | lookaheadPoses = info.LookaheadPoses;
|
| 37 | + if resetNumViolations |
| 38 | + numberOfViolations = 0; |
| 39 | + else |
| 40 | + numberOfViolations = numberOfViolations + 1; |
| 41 | + end |
37 | 42 | end
|
38 | 43 |
|
39 | 44 |
|
|
65 | 70 | mppi.Parameter.VehicleCollisionInformation = struct("Dimension",[length, width],"Shape","Rectangle");
|
66 | 71 | end
|
67 | 72 |
|
68 |
| -function [velcmds,optpath,info,numTrajs,needLocalReplan,needGlobalReplan] = stepImp(mppiObj, controllerParams, constraintViolated,curpose,curvel) |
| 73 | +function [velcmds,optpath,info,numTrajs,needLocalReplan,needGlobalReplan,resetNumViolations] = stepImp(mppiObj, controllerParams, numberOfViolations,curpose,curvel) |
69 | 74 | % stepImp return the control commands from the MPPI controller.
|
70 | 75 |
|
71 | 76 | needLocalReplan = 0;
|
72 | 77 | needGlobalReplan = 0;
|
73 |
| - |
74 |
| -if constraintViolated == 1 |
| 78 | +resetNumViolations = true; |
| 79 | +if numberOfViolations > 0 |
75 | 80 | % When constraints are violated in previous MPPI output, relax the
|
76 | 81 | % parameters in MPPI temporarily. The number of trajectories are doubled
|
77 | 82 | % increase the standard deviation, and keep the PathFollowing cost
|
78 | 83 | % to 0 and restore them back after velocity commands are generated.
|
79 | 84 | mppiObj.NumTrajectory = 2*controllerParams.NumTrajectory;
|
80 | 85 | stdDev = controllerParams.StandardDeviation;
|
81 | 86 | mppiObj.StandardDeviation = [stdDev(1) 2*stdDev(2)];
|
82 |
| - mppiObj.Parameter.CostWeight.PathFollowing = 0.1; |
| 87 | + mppiObj.Parameter.CostWeight.PathAlignment = 0; |
83 | 88 | numTrajs = mppiObj.NumTrajectory;
|
84 | 89 | % Generate optimal local path
|
85 | 90 | [velcmds,optpath,info] = mppiObj(curpose(:)',curvel(:)');
|
86 | 91 | mppiObj.NumTrajectory = controllerParams.NumTrajectory;
|
87 | 92 | mppiObj.StandardDeviation = stdDev;
|
88 |
| - mppiObj.Parameter.CostWeight.PathFollowing = controllerParams.PathFollowingCost; |
| 93 | + mppiObj.Parameter.CostWeight.PathAlignment = controllerParams.PathAlignmentCost; |
89 | 94 | else
|
90 | 95 | [velcmds,optpath,info] = mppiObj(curpose(:)',curvel(:)');
|
91 | 96 | numTrajs = mppiObj.NumTrajectory;
|
92 | 97 | end
|
93 | 98 |
|
94 |
| -% Trigger local replan if the mppi output trajectory has constraints violated. |
95 | 99 | if info.ExitFlag == 1
|
96 |
| - needLocalReplan = 1; |
97 |
| -% Trigger global replan if the vehicle is far from reference path or it did |
98 |
| -% not move using previous controls. |
| 100 | + if numberOfViolations == 0 |
| 101 | + % Trigger local replan if the mppi output trajectory has constraints |
| 102 | + % violated and previous mppi call did not result in violation. |
| 103 | + needLocalReplan = 1; |
| 104 | + resetNumViolations = false; |
| 105 | + elseif numberOfViolations >= 1 |
| 106 | + % Trigger global replan if constraint violation occured on consecutive MPPI calls |
| 107 | + needGlobalReplan = 1; |
| 108 | + end |
99 | 109 | elseif info.ExitFlag == 2
|
| 110 | + % Trigger global replan if the vehicle is far from reference path. |
100 | 111 | needGlobalReplan = 1;
|
101 | 112 | end
|
102 | 113 |
|
|
0 commit comments