1 package org.opentrafficsim.road.network.lane;
2
3 import javax.naming.NamingException;
4
5 import org.djunits.unit.AccelerationUnit;
6 import org.djunits.unit.DirectionUnit;
7 import org.djunits.unit.DurationUnit;
8 import org.djunits.unit.LengthUnit;
9 import org.djunits.unit.SpeedUnit;
10 import org.djunits.value.vdouble.scalar.Acceleration;
11 import org.djunits.value.vdouble.scalar.Direction;
12 import org.djunits.value.vdouble.scalar.Duration;
13 import org.djunits.value.vdouble.scalar.Length;
14 import org.djunits.value.vdouble.scalar.Speed;
15 import org.djutils.draw.point.Point2d;
16 import org.junit.jupiter.api.Test;
17 import org.opentrafficsim.base.geometry.OtsLine2d;
18 import org.opentrafficsim.core.definitions.DefaultsNl;
19 import org.opentrafficsim.core.dsol.OtsSimulatorInterface;
20 import org.opentrafficsim.core.gtu.GtuException;
21 import org.opentrafficsim.core.gtu.GtuType;
22 import org.opentrafficsim.core.network.NetworkException;
23 import org.opentrafficsim.core.network.Node;
24 import org.opentrafficsim.road.car.CarTest;
25 import org.opentrafficsim.road.definitions.DefaultsRoadNl;
26 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
27 import org.opentrafficsim.road.gtu.lane.tactical.following.FixedAccelerationModel;
28 import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.FixedLaneChangeModel;
29 import org.opentrafficsim.road.network.RoadNetwork;
30 import org.opentrafficsim.road.network.factory.LaneFactory;
31
32 import nl.tudelft.simulation.dsol.SimRuntimeException;
33 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEventInterface;
34
35
36
37
38
39
40
41
42
43
44
45 public class CurveTest
46 {
47
48
49
50
51
52
53
54
55 @Test
56 public final void curveTest() throws SimRuntimeException, NamingException, NetworkException, GtuException
57 {
58 final int laneCount = 1;
59 OtsSimulatorInterface simulator = CarTest.makeSimulator();
60 RoadNetwork network = new RoadNetwork("curve test network", simulator);
61 GtuType gtuType = DefaultsNl.CAR;
62 LaneType laneType = DefaultsRoadNl.TWO_WAY_LANE;
63 Speed speedLimit = new Speed(50, SpeedUnit.KM_PER_HOUR);
64 Node origin = new Node(network, "origin", new Point2d(10, 10), Direction.ZERO);
65 Node curveStart = new Node(network, "curveStart", new Point2d(100, 10), Direction.ZERO);
66 Node curveEnd = new Node(network, "curveEnd", new Point2d(150, 60), new Direction(90, DirectionUnit.EAST_DEGREE));
67 Node destination =
68 new Node(network, "destination", new Point2d(150, 150), new Direction(90, DirectionUnit.EAST_DEGREE));
69 Lane[] straight1 = LaneFactory.makeMultiLane(network, "straight1", origin, curveStart, null, laneCount, laneType,
70 speedLimit, simulator, DefaultsNl.VEHICLE);
71 Lane[] straight2 = LaneFactory.makeMultiLane(network, "straight2", curveEnd, destination, null, laneCount, laneType,
72 speedLimit, simulator, DefaultsNl.VEHICLE);
73 OtsLine2d curveLine = LaneFactory.makeBezier(origin, curveStart, curveEnd, destination);
74 Lane[] curve = LaneFactory.makeMultiLane(network, "bezier", curveStart, curveEnd,
75 curveLine.getPointList().toArray(new Point2d[curveLine.size()]), laneCount, laneType, speedLimit, simulator,
76 DefaultsNl.VEHICLE);
77 Lane[][] laneSets = new Lane[][] {straight1, curve, straight2};
78 Length initialPosition = new Length(5, LengthUnit.METER);
79 Speed speed = new Speed(10, SpeedUnit.SI);
80 for (int lane = 0; lane < laneCount; lane++)
81 {
82
83 double cumulativeLength = 0;
84 for (Lane[] set : laneSets)
85 {
86 cumulativeLength += set[lane].getLength().si;
87 double timeAtEnd = simulator.getSimulatorTime().si + (cumulativeLength - initialPosition.si) / speed.si;
88 System.out.println("lane " + set[lane] + " length is " + set[lane].getLength()
89 + " time for reference to get to end " + timeAtEnd);
90 }
91 LaneBasedGtu car = CarTest.makeReferenceCar("car", gtuType, straight1[lane], initialPosition, speed,
92 new FixedAccelerationModel(new Acceleration(0, AccelerationUnit.SI), new Duration(25, DurationUnit.SI)),
93 new FixedLaneChangeModel(null), (RoadNetwork) network);
94 printEventList(simulator);
95 System.out.println("STEP");
96 simulator.step();
97 printEventList(simulator);
98 System.out.println("STEP");
99 simulator.step();
100 printEventList(simulator);
101
102 }
103 }
104
105
106
107
108
109 public final void printEventList(final OtsSimulatorInterface simulator)
110 {
111 for (SimEventInterface<Duration> se : simulator.getEventList())
112 {
113 System.out.println("se: " + se);
114 }
115
116 }
117
118 }