How to keep waypoints following multiple simulation running ?

Trying to mimic a real life scenario. I want to code a simulation that will have multiple differential drive cars in an occupancy grid. The cars will travel to multiple destination on the grid. For some reason, the simulation loop ends when one of the cars reach its final destination.How can I keep the loop running untill every cars reach the final destination? I also want to plot a time vs distance graph for all the cars individually.
What changes do I have to make inorder to change the waypoints following method to path planning using pure persuit method? Can I edit the path planning such that It suits the left hand drive ?
image = imread('Occupancy Grid 3.png');
grayimage = rgb2gray(image);
bwimage = grayimage < 1;
map = binaryOccupancyMap(bwimage, 27);
show(map);
P1 = [0.20 0.1;
1.55 0.1;
1.55 1.35;
2.65 1.35;
2.65 2.65;
5.70 2.65;
5.70 3.55;
9.35 3.55;
9.35 3.12;
7.85 3.12;
7.85 2.98];
P2 = [1.00 3.00;
0.80 3.00;
0.80 3.33;
0.35 3.33;
0.35 3.60;
1.30 3.60;
1.30 0.10;
2.65 0.10;
2.65 1.35;
3.95 1.35;
4.00 0.60];
P3 = [8.90 0.95;
9.35 0.95;
9.35 0.35;
7.45 0.35;
7.45 1.62;
2.60 1.65;
2.60 1.35;
3.95 1.35;
3.95 1.00;
3.21 1.00;
3.21 0.55];
FJ = differentialDriveKinematics("TrackWidth", 1, "VehicleInputs", "VehicleSpeedHeadingRate");
Lancer = differentialDriveKinematics("TrackWidth", 1, "VehicleInputs", "VehicleSpeedHeadingRate");
Yaris = differentialDriveKinematics("TrackWidth", 1, "VehicleInputs", "VehicleSpeedHeadingRate");
figure
FJcontroller = controllerPurePursuit;
FJcontroller.Waypoints = P1;
FJcontroller.DesiredLinearVelocity = 0.1;
FJcontroller.MaxAngularVelocity = 0.5;
FJcontroller.LookaheadDistance = 0.2;
Lancercontroller = controllerPurePursuit;
Lancercontroller.Waypoints = P2;
Lancercontroller.DesiredLinearVelocity = 0.1;
Lancercontroller.MaxAngularVelocity = 0.5;
Lancercontroller.LookaheadDistance = 0.2;
Yariscontroller = controllerPurePursuit;
Yariscontroller.Waypoints = P3;
Yariscontroller.DesiredLinearVelocity = 0.1;
Yariscontroller.MaxAngularVelocity = 0.5;
Yariscontroller.LookaheadDistance = 0.2;
FJInitialLocation = P1(1,:);
FJGoal = P1(end,:);
FJinitialOrientation = 0;
FJCurrentPose = [FJInitialLocation FJinitialOrientation]';
FJdistanceToGoal = norm(FJInitialLocation - FJGoal);
FJgoalRadius = 0.1;
LancerInitialLocation = P2(1,:);
LancerGoal = P2(end,:);
LancerinitialOrientation = pi;
LancerCurrentPose = [LancerInitialLocation LancerinitialOrientation]';
LancerdistanceToGoal = norm(LancerInitialLocation - LancerGoal);
LancergoalRadius = 0.1;
YarisInitialLocation = P3(1,:);
YarisGoal = P3(end,:);
YarisinitialOrientation = 0;
YarisCurrentPose = [YarisInitialLocation YarisinitialOrientation]';
YarisdistanceToGoal = norm(YarisInitialLocation - YarisGoal);
YarisgoalRadius = 0.1;
sampleTime = 0.1;
vizRate = rateControl(1/sampleTime);
figure
frameSize = FJ.TrackWidth/7;
frameSize2 = Lancer.TrackWidth/7;
frameSize3 = Yaris.TrackWidth/7;
while( FJdistanceToGoal > FJgoalRadius && LancerdistanceToGoal > LancergoalRadius && YarisdistanceToGoal > YarisgoalRadius)
[v, omega] = FJcontroller(FJCurrentPose);
[v2, omega2] = Lancercontroller(LancerCurrentPose);
[v3, omega3] = Yariscontroller(YarisCurrentPose);
vel = derivative(FJ, FJCurrentPose, [v omega]);
vel2 = derivative(Lancer,LancerCurrentPose, [v2 omega2]);
vel3 = derivative(Yaris, YarisCurrentPose, [v3 omega3]);
FJCurrentPose = FJCurrentPose + vel*sampleTime;
LancerCurrentPose = LancerCurrentPose + vel2*sampleTime;
YarisCurrentPose = YarisCurrentPose + vel3*sampleTime;
FJdistanceToGoal = norm(FJCurrentPose(1:2) - FJGoal(:));
LancerdistanceToGoal = norm(LancerCurrentPose(1:2) - LancerGoal(:));
YarisdistanceToGoal = norm(YarisCurrentPose(1:2) - LancerGoal(:));
hold off
show(map)
hold all
plotTrVec = [FJCurrentPose(1:2); 0];
plotTrVec2 = [LancerCurrentPose(1:2); 0];
plotTrVec3 = [YarisCurrentPose(1:2); 0];
plotRot = axang2quat([0 0 1 FJCurrentPose(3)]);
plotRot2 = axang2quat([0 0 1 LancerCurrentPose(3)]);
plotRot3 = axang2quat([0 0 1 YarisCurrentPose(3)]);
plotTransforms(plotTrVec', plotRot, 'MeshFilePath', 'groundvehicle.stl', 'Parent', gca, "View","2D", "FrameSize", frameSize);
plotTransforms(plotTrVec2', plotRot2, 'MeshFilePath', 'groundvehicle.stl', 'Parent', gca, "View","2D", "FrameSize", frameSize2);
plotTransforms(plotTrVec3', plotRot3, 'MeshFilePath', 'groundvehicle.stl', 'Parent', gca, "View","2D", "FrameSize", frameSize3);
light;
xlim([0 9.8148])
ylim([0 3.9630])
waitfor(vizRate);
end

Answers (0)

Asked:

on 10 May 2020

Edited:

on 10 May 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!