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.junit.Test;
16 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
17 import org.opentrafficsim.core.geometry.OTSGeometryException;
18 import org.opentrafficsim.core.geometry.OTSLine3D;
19 import org.opentrafficsim.core.geometry.OTSPoint3D;
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.road.car.CarTest;
24 import org.opentrafficsim.road.gtu.lane.LaneBasedIndividualGTU;
25 import org.opentrafficsim.road.gtu.lane.tactical.following.FixedAccelerationModel;
26 import org.opentrafficsim.road.gtu.lane.tactical.lanechangemobil.FixedLaneChangeModel;
27 import org.opentrafficsim.road.network.OTSRoadNetwork;
28 import org.opentrafficsim.road.network.factory.LaneFactory;
29
30 import nl.tudelft.simulation.dsol.SimRuntimeException;
31 import nl.tudelft.simulation.dsol.formalisms.eventscheduling.SimEventInterface;
32
33
34
35
36
37
38
39
40
41
42
43
44 public class CurveTest
45 {
46
47
48
49
50
51
52
53
54
55 @Test
56 public final void curveTest()
57 throws OTSGeometryException, SimRuntimeException, NamingException, NetworkException, GTUException
58 {
59 final int laneCount = 1;
60 OTSSimulatorInterface simulator = CarTest.makeSimulator();
61 OTSRoadNetwork network = new OTSRoadNetwork("curve test network", true, simulator);
62 GTUType gtuType = network.getGtuType(GTUType.DEFAULTS.CAR);
63 LaneType laneType = network.getLaneType(LaneType.DEFAULTS.TWO_WAY_LANE);
64 Speed speedLimit = new Speed(50, SpeedUnit.KM_PER_HOUR);
65 OTSRoadNode origin = new OTSRoadNode(network, "origin", new OTSPoint3D(10, 10, 0), Direction.ZERO);
66 OTSRoadNode curveStart = new OTSRoadNode(network, "curveStart", new OTSPoint3D(100, 10, 0), Direction.ZERO);
67 OTSRoadNode curveEnd = new OTSRoadNode(network, "curveEnd", new OTSPoint3D(150, 60, 0),
68 new Direction(90, DirectionUnit.EAST_DEGREE));
69 OTSRoadNode destination = new OTSRoadNode(network, "destination", new OTSPoint3D(150, 150, 0),
70 new Direction(90, DirectionUnit.EAST_DEGREE));
71 Lane[] straight1 = LaneFactory.makeMultiLane(network, "straight1", origin, curveStart, null, laneCount, laneType,
72 speedLimit, simulator);
73 Lane[] straight2 = LaneFactory.makeMultiLane(network, "straight2", curveEnd, destination, null, laneCount, laneType,
74 speedLimit, simulator);
75 OTSLine3D curveLine = LaneFactory.makeBezier(origin, curveStart, curveEnd, destination);
76 Lane[] curve = LaneFactory.makeMultiLane(network, "bezier", curveStart, curveEnd, curveLine.getPoints(), laneCount,
77 laneType, speedLimit, simulator);
78 Lane[][] laneSets = new Lane[][] {straight1, curve, straight2};
79 Length initialPosition = new Length(5, LengthUnit.METER);
80 Speed speed = new Speed(10, SpeedUnit.SI);
81 for (int lane = 0; lane < laneCount; lane++)
82 {
83
84 double cumulativeLength = 0;
85 for (Lane[] set : laneSets)
86 {
87 cumulativeLength += set[lane].getLength().si;
88 double timeAtEnd = simulator.getSimulatorTime().si + (cumulativeLength - initialPosition.si) / speed.si;
89 System.out.println("lane " + set[lane] + " length is " + set[lane].getLength()
90 + " time for reference to get to end " + timeAtEnd);
91 }
92 LaneBasedIndividualGTU car = CarTest.makeReferenceCar("car", gtuType, straight1[lane], initialPosition, speed,
93 simulator,
94 new FixedAccelerationModel(new Acceleration(0, AccelerationUnit.SI), new Duration(25, DurationUnit.SI)),
95 new FixedLaneChangeModel(null), (OTSRoadNetwork) network);
96 printEventList(simulator);
97 System.out.println("STEP");
98 simulator.step();
99 printEventList(simulator);
100 System.out.println("STEP");
101 simulator.step();
102 printEventList(simulator);
103
104 }
105 }
106
107
108
109
110
111 public final void printEventList(final OTSSimulatorInterface simulator)
112 {
113 for (SimEventInterface<Duration> se : simulator.getEventList())
114 {
115 System.out.println("se: " + se);
116 }
117
118 }
119
120 }