1 /*global Simulator, TWEEN */
4 * Script operates all indicators that are present in Dashboard application:
6 * * Vehicle speed similar as {{#crossLink "SpeedDemo2"}}speedDemo2{{/crossLink}}
7 * * Transmission gear similar as {{#crossLink "SpeedDemo2"}}speedDemo2{{/crossLink}}
8 * * Battery status same as {{#crossLink "BatteryDemo"}}batteryDemo{{/crossLink}}
9 * * Exterior brightness same as {{#crossLink "BatteryDemo"}}batteryDemo{{/crossLink}}
10 * * Head, parking lights
11 * * Front wheel radius
13 * * Exterior temperature
14 * * Tire pressure same as {{#crossLink "TirePressureDemo"}}tirePressureDemo{{/crossLink}}
16 * @module AMBSimulatorApplication
17 * @class RandomizerDemo
20 setInterval(function() {
26 var neutralGear, firstGear, secondGear, thirdGear, fourthGear;
28 function getGearTween(time, gear, speedFrom, speedTo) {
30 return new TWEEN.Tween({
34 }, time).onStart(function() {
35 Simulator.set("vcan0", "TransmissionShiftPosition", gear, 0);
36 }).onUpdate(function() {
37 Simulator.set("vcan0", "VehicleSpeed", this.speed, 0);
40 neutralGear = getGearTween(3000, "0", 0, 0).onComplete(function() {
42 firstGear = getGearTween(2000, "1", 0, 20);
43 secondGear = getGearTween(3000, "2", 20, 40);
44 thirdGear = getGearTween(4000, "3", 40, 60);
45 fourthGear = getGearTween(5000, "4", 60, 100).onComplete(function() {
46 firstGear = getGearTween(2000, "1", 20, 0);
47 secondGear = getGearTween(3000, "2", 40, 20);
48 thirdGear = getGearTween(4000, "3", 60, 40);
49 fourthGear = getGearTween(5000, "4", 100, 60);
50 fourthGear.chain(thirdGear.chain(secondGear.chain(firstGear.chain(neutralGear)))).start();
53 firstGear.chain(secondGear.chain(thirdGear.chain(fourthGear))).start();
58 // battery level && exterior Brightness
59 var batteryStatus, exteriorBrightness, headLights, parkingLights;
61 batteryStatus = new TWEEN.Tween({
65 }, 10000).easing(TWEEN.Easing.Cubic.Out).onUpdate(function() {
67 Simulator.set("vcan0", "BatteryStatus", this.battery, 0);
68 }).repeat('Infinity').yoyo(true).start();
70 exteriorBrightness = new TWEEN.Tween({
74 }, 10000).onUpdate(function() {
76 if (this.brightness < 2000 && !headLights) {
79 Simulator.set("vcan0", "LightHead", headLights, 0);
80 Simulator.set("vcan0", "LightParking", parkingLights, 0);
81 } else if (this.brightness >= 2000 && headLights) {
83 parkingLights = false;
84 Simulator.set("vcan0", "LightHead", headLights, 0);
85 Simulator.set("vcan0", "LightParking", parkingLights, 0);
87 Simulator.set("vcan0", "ExteriorBrightness", this.brightness, 0);
88 }).repeat('Infinity').yoyo(true).start();
93 frontWheelRadius = new TWEEN.Tween({
97 }, 5000).onUpdate(function() {
99 Simulator.set("vcan0", "SteeringWheelAngle", this.radius, 0);
100 }).repeat('Infinity').yoyo(true).start();
102 // head lights, parking lights, childlock, exterior temperature, weather
103 var childLock, extTemp, rand;
105 parkingLights = false;
108 function setRandomValues() {
110 rand = Math.random();
112 parkingLights = !parkingLights;
113 Simulator.set("vcan0", "LightParking", parkingLights, 0);
115 extTemp = Math.floor(rand * 7) + (extTemp - 3);
116 extTemp = (extTemp < -21)? -21 : extTemp;
117 extTemp = (extTemp > 45)? 45 : extTemp;
118 Simulator.set("vcan0", "ExteriorTemperature", extTemp, 0);
119 Simulator.set("vcan0", "InteriorTemperature", extTemp+10, 0);
120 Simulator.set("vcan0", "Weather", Math.floor(rand * 3), 0);
121 childLock = !childLock;
122 Simulator.set("vcan0", "ChildLockStatus", childLock, 0);
123 setTimeout(setRandomValues, Math.floor(rand * 9500) + 500);
130 tirePressure = new TWEEN.Tween({
134 }, 5000).easing(TWEEN.Easing.Cubic.InOut).onUpdate(function() {
136 Simulator.set("vcan0", "TirePressureLeftFront", this.pressure, 0);
137 Simulator.set("vcan0", "TirePressureRightFront", this.pressure, 0);
138 Simulator.set("vcan0", "TirePressureLeftRear", this.pressure, 0);
139 Simulator.set("vcan0", "TirePressureRightRear", this.pressure, 0);
140 }).repeat('Infinity').yoyo(true).start();