Commit d63ec839 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

Rename functions for multicopters

See merge request !1891
parents 760e47a9 d240b5c2
Pipeline #33176 failed with stage
in 0 seconds
......@@ -23,6 +23,8 @@ var EnemyDroneAPI = /** @class */ (function () {
this._drone_dict_list = [];
this._acceleration = DEFAULT_ACCELERATION;
this._collision_sector = COLLISION_SECTOR;
this._is_landing = false;
this._is_ready_to_fly = true;
}
/*
** Function called on start phase of the drone, just before onStart AI script
......@@ -49,7 +51,6 @@ var EnemyDroneAPI = /** @class */ (function () {
if (drone._maxSinkRate > drone._maxSpeed) {
throw new Error('max sink rate cannot be superior to max speed');
}
drone._maxOrientation = this.getMaxOrientation();
return;
};
/*
......@@ -57,10 +58,12 @@ var EnemyDroneAPI = /** @class */ (function () {
*/
EnemyDroneAPI.prototype.internal_update = function (context, delta_time) {
context._speed += context._acceleration * delta_time / 1000;
if (context._speed > context._maxSpeed)
if (context._speed > context._maxSpeed) {
context._speed = context._maxSpeed;
if (context._speed < -context._maxSpeed)
}
if (context._speed < -context._maxSpeed) {
context._speed = -context._maxSpeed;
}
var updateSpeed = context._speed * delta_time / 1000;
if (context._direction.x !== 0 ||
context._direction.y !== 0 ||
......@@ -68,13 +71,9 @@ var EnemyDroneAPI = /** @class */ (function () {
context._controlMesh.position.addInPlace(
new BABYLON.Vector3(context._direction.x * updateSpeed,
context._direction.y * updateSpeed,
context._direction.z * updateSpeed));
context._direction.z * updateSpeed)
);
}
var orientationValue = context._maxOrientation *
(context._speed / context._maxSpeed);
context._mesh.rotation = new BABYLON.Vector3(
orientationValue * context._direction.z, 0,
-orientationValue * context._direction.x);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
return;
......@@ -119,7 +118,9 @@ var EnemyDroneAPI = /** @class */ (function () {
EnemyDroneAPI.prototype.internal_setTargetCoordinates =
function (drone, coordinates) {
if (!drone._canPlay) return;
if (!drone._canPlay) {
return;
}
var x = coordinates.x, y = coordinates.y, z = coordinates.z;
if (isNaN(x) || isNaN(y) || isNaN(z)) {
throw new Error('Target coordinates must be numbers');
......@@ -279,20 +280,17 @@ var EnemyDroneAPI = /** @class */ (function () {
EnemyDroneAPI.prototype.getMaxAcceleration = function () {
return this._flight_parameters.drone.maxAcceleration;
};
EnemyDroneAPI.prototype.getMaxOrientation = function () {
//TODO should be a game parameter (but how to force value to PI quarters?)
return Math.PI / 4;
};
EnemyDroneAPI.prototype.triggerParachute = function (drone) {
EnemyDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 5);
drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 0);
this._is_ready_to_fly = false;
this._is_landing = true;
};
EnemyDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition();
return Math.floor(drone_pos.altitude) < 10;
EnemyDroneAPI.prototype.isReadyToFly = function () {
return this._is_ready_to_fly;
};
EnemyDroneAPI.prototype.exit = function () {
return;
EnemyDroneAPI.prototype.isLanding = function () {
return this._is_landing;
};
EnemyDroneAPI.prototype.getInitialAltitude = function () {
return 0;
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.46035.33513.61849</string> </value>
<value> <string>1014.56714.1017.16076</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1697031010.99</float>
<float>1709221104.19</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -31,6 +31,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
this._loiter_radius = 100;
//this._start_altitude = 0;
this._loiter_mode = false;
this._is_landing = false;
this._is_ready_to_fly = true;
this._drone_dict_list = [];
}
/*
......@@ -86,45 +88,15 @@ var FixedWingDroneAPI = /** @class */ (function () {
if (drone._maxClimbRate > drone._maxSpeed) {
throw new Error('max climb rate cannot be superior to max speed');
}
drone._maxOrientation = this.getMaxOrientation();
return;
};
/*
** Function called on every drone update, right before onUpdate AI script
*/
FixedWingDroneAPI.prototype.internal_update = function (context, delta_time) {
var diff, newrot, orientationValue, rotStep;
//TODO rotation
if (context._rotationTarget) {
rotStep = BABYLON.Vector3.Zero();
diff = context._rotationTarget.subtract(context._controlMesh.rotation);
rotStep.x = (diff.x >= 1) ? 1 : diff.x;
rotStep.y = (diff.y >= 1) ? 1 : diff.y;
rotStep.z = (diff.z >= 1) ? 1 : diff.z;
if (rotStep === BABYLON.Vector3.Zero()) {
context._rotationTarget = null;
return;
}
newrot = new BABYLON.Vector3(context._controlMesh.rotation.x +
(rotStep.x * context._rotationSpeed),
context._controlMesh.rotation.y +
(rotStep.y * context._rotationSpeed),
context._controlMesh.rotation.z +
(rotStep.z * context._rotationSpeed)
);
context._controlMesh.rotation = newrot;
}
this._updateSpeed(context, delta_time);
this._updatePosition(context, delta_time);
//TODO rotation
orientationValue = context._maxOrientation *
(context._speed / context._maxSpeed);
context._mesh.rotation =
new BABYLON.Vector3(orientationValue * context._direction.z, 0,
-orientationValue * context._direction.x);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
};
......@@ -144,7 +116,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude,
'yaw': drone.getYaw(),
'speed': drone.getAirSpeed(),
'speed': drone.getSpeed(),
'climbRate': drone.getClimbRate()
};
_this._drone_dict_list[_this._id] = drone_info;
......@@ -158,7 +130,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) {
var speed = drone.getAirSpeed(), speedDiff, speedUpdate;
var speed = drone.get3DSpeed(), speedDiff, speedUpdate;
if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed;
speedUpdate = drone._acceleration * delta_time / 1000;
......@@ -231,7 +203,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt(
Math.pow(drone.getAirSpeed(), 2) - Math.pow(verticalSpeed, 2)
Math.pow(drone.get3DSpeed(), 2) - Math.pow(verticalSpeed, 2)
);
distance = (groundSpeed * delta_time / 1000) / R;
......@@ -293,39 +265,27 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._computeVerticalSpeed(
altitudeDiff,
this.getMaxClimbRate(),
drone.getAirSpeed(),
drone.get3DSpeed(),
this.getMaxPitchAngle()
);
} else {
verticalSpeed = -this._computeVerticalSpeed(
Math.abs(altitudeDiff),
this.getMaxSinkRate(),
drone.getAirSpeed(),
drone.get3DSpeed(),
-this.getMinPitchAngle()
);
}
return verticalSpeed;
};
FixedWingDroneAPI.prototype.setRotation = function (drone, x, y, z) {
//TODO rotation
drone._rotationTarget = new BABYLON.Vector3(x, z, y);
};
FixedWingDroneAPI.prototype.setRotationBy = function (drone, x, y, z) {
//TODO rotation
drone._rotationTarget = new BABYLON.Vector3(drone.rotation.x + x,
drone.rotation.y + z,
drone.rotation.z + y);
};
FixedWingDroneAPI.prototype.setSpeed = function (drone, speed) {
this._targetSpeed = Math.max(
Math.min(speed, this.getMaxSpeed()),
this.getMinSpeed()
);
drone._acceleration = (this._targetSpeed > drone.getAirSpeed()) ?
drone._acceleration = (this._targetSpeed > drone.get3DSpeed()) ?
this.getMaxAcceleration() : -this.getMaxDeceleration();
};
......@@ -490,14 +450,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
FixedWingDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxClimbRate;
};
FixedWingDroneAPI.prototype.getMaxOrientation = function () {
//TODO should be a game parameter (but how to force value to PI quarters?)
return Math.PI / 4;
};
FixedWingDroneAPI.prototype.getYawVelocity = function (drone) {
return 360 * EARTH_GRAVITY *
Math.tan(this._toRad(this.getMaxRollAngle())) /
(2 * Math.PI * drone.getAirSpeed());
(2 * Math.PI * drone.get3DSpeed());
};
FixedWingDroneAPI.prototype.getYaw = function (drone) {
var direction = drone.worldDirection;
......@@ -533,30 +489,34 @@ var FixedWingDroneAPI = /** @class */ (function () {
return angle * 180 / Math.PI;
};
FixedWingDroneAPI.prototype.getClimbRate = function (drone) {
return drone.worldDirection.y * drone.getAirSpeed();
return drone.worldDirection.y * drone.get3DSpeed();
};
FixedWingDroneAPI.prototype.getGroundSpeed = function (drone) {
FixedWingDroneAPI.prototype.getSpeed = function (drone) {
var direction = drone.worldDirection;
return Math.sqrt(
Math.pow(direction.x * drone.getAirSpeed(), 2) +
Math.pow(direction.z * drone.getAirSpeed(), 2)
Math.pow(direction.x * drone.get3DSpeed(), 2) +
Math.pow(direction.z * drone.get3DSpeed(), 2)
);
};
FixedWingDroneAPI.prototype.triggerParachute = function (drone) {
FixedWingDroneAPI.prototype.takeOff = function () {
return console.log("Fixed-wing drones can only be taken off manually.");
};
FixedWingDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
5,
drone.getAirSpeed()
0,
drone.get3DSpeed()
);
this._is_ready_to_fly = false;
this._is_landing = true;
};
FixedWingDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition();
return Math.floor(drone_pos.altitude) < 10;
FixedWingDroneAPI.prototype.isReadyToFly = function () {
return this._is_ready_to_fly;
};
FixedWingDroneAPI.prototype.exit = function () {
return;
FixedWingDroneAPI.prototype.isLanding = function () {
return this._is_landing;
};
FixedWingDroneAPI.prototype.getInitialAltitude = function () {
return this._map_dict.start_AMSL;
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.48041.44620.29337</string> </value>
<value> <string>1014.56746.48697.2713</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709113157.81</float>
<float>1709223091.4</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.48183.45277.7697</string> </value>
<value> <string>1014.56745.33504.26197</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709113192.28</float>
<float>1709223446.72</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -340,6 +340,24 @@
<div class="line"></div>
<!-- takeOff -->
<h4 class="item-name" id="takeOff"><span>takeOff</span><span>: void</span></h4>
<p class="item-descr">Trigger drone's takeoff (has only effect on multicopters as fixed wings drones need to take off manually).</p>
<div>
<h5 class="item-param-1">Param</h5>
<h5 class="item-param-2">Description</h5>
</div>
<div>
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-param-1">me.takeOff();<br>
</p>
<div class="line"></div>
<!-- setTargetCoordinates -->
<h4 class="item-name" id="setTargetCoordinates"><span>setTargetCoordinates</span><span>: void</span></h4>
<p class="item-descr">
......@@ -439,9 +457,9 @@
<div class="line"></div>
<!-- triggerParachute -->
<h4 class="item-name" id="triggerParachute"><span>triggerParachute</span><span>: void</span></h4>
<p class="item-descr">Indicates the drone to deploy the parachute to finish the landing.</p>
<!-- land -->
<h4 class="item-name" id="land"><span>land</span><span>: void</span></h4>
<p class="item-descr">Indicates the drone to trigger landing.</p>
<div>
<h5 class="item-param-1">Param</h5>
......@@ -452,23 +470,33 @@
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-param-1">me.triggerParachute();<br>
<p class="item-param-1">me.land();<br>
</p>
<div class="line"></div>
<!-- landed -->
<h4 class="item-name" id="landed"><span>landed</span><span>: boolean</span></h4>
<p class="item-descr">Indicates if the drone has landed (reached the floor altitude).</p>
<!-- isReadyToFly -->
<h4 class="item-name" id="isReadyToFly"><span>isReadyToFly</span><span>: void</span></h4>
<p class="item-descr">Check if drone takeoff is finished.</p>
<div>
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-example">
if (me.landed()) {<br>
&nbsp;&nbsp;//do something<br>
}<br>
<p class="item-param-1">me.isReadyToFly();<br>
</p>
<div class="line"></div>
<!-- isLanding -->
<h4 class="item-name" id="isLanding"><span>isLanding</span><span>: void</span></h4>
<p class="item-descr">Check if drone landing has been triggered.</p>
<div>
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-param-1">me.isLanding();<br>
</p>
<div class="line"></div>
......@@ -501,15 +529,15 @@
<div class="line"></div>
<!-- getAirSpeed -->
<h4 class="item-name" id="getAirSpeed"><span>getAirSpeed</span><span>: Float</span></h4>
<p class="item-descr">Get drone air speed in meters/second.</p>
<!-- getSpeed -->
<h4 class="item-name" id="getSpeed"><span>getSpeed</span><span>: Float</span></h4>
<p class="item-descr">Get drone ground speed in meters/second as wind is neglected in simulation. In real flights with fixed wings drones the returned value is the airspeed.</p>
<div>
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-param-1">me.getAirSpeed();<br>
<p class="item-param-1">me.getSpeed();<br>
</p>
<div class="line"></div>
......@@ -553,19 +581,6 @@
<div class="line"></div>
<!-- getSinkRate -->
<h4 class="item-name" id="getSinkRate"><span>getSinkRate</span><span>: Float</span></h4>
<p class="item-descr">Get drone sink rate in meters/second.</p>
<div>
<h5 class="item-param-1">Example</h5>
</div>
<p class="item-param-1">me.getSinkRate();<br>
</p>
<div class="line"></div>
<h3>Drone properties</h3>
<div class="line"></div>
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.45296.39536.30276</string> </value>
<value> <string>1014.46767.47211.3123</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -264,7 +264,7 @@
</tuple>
<state>
<tuple>
<float>1708536065.15</float>
<float>1708688564.0</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.55204.2137.9676</string> </value>
<value> <string>1014.46368.9372.48435</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709130500.2</float>
<float>1708616910.25</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -53,7 +53,7 @@
'}\n' +
'\n' +
'me.onStart = function () {\n' +
' assert(me.getAirSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getYaw(), 0, "Yaw angle")\n' +
' me.initialPosition = me.getCurrentPosition();\n' +
' me.setTargetCoordinates(\n' +
......@@ -73,7 +73,7 @@
' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\n' +
' time_interval = 1000 / 60,\n' +
' expectedDistance = (me.getAirSpeed() * time_interval / 1000).toFixed(8);\n' +
' expectedDistance = (me.getSpeed() * time_interval / 1000).toFixed(8);\n' +
' assert(timestamp, Math.floor(time_interval), "Timestamp");\n' +
' assert(realDistance, expectedDistance, "Distance");\n' +
' current_position.latitude = current_position.latitude.toFixed(7);\n' +
......@@ -82,7 +82,7 @@
' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' +
' });\n' +
' me.exit(me.triggerParachute());\n' +
' me.exit(me.land());\n' +
'};',
DRAW = true,
LOG = true,
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.55202.48917.18107</string> </value>
<value> <string>1014.55287.25371.8430</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709130419.7</float>
<float>1709136147.57</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -207,11 +207,8 @@ var DroneLogAPI = /** @class */ (function () {
DroneLogAPI.prototype.getFlightParameters = function () {
return this._flight_parameters;
};
DroneLogAPI.prototype.exit = function (drone) {
return;
};
DroneLogAPI.prototype.set_loiter_mode = function (loiter) {
return;
DroneLogAPI.prototype.isReadyToFly = function () {
return true;
};
return DroneLogAPI;
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1011.48679.53693.47701</string> </value>
<value> <string>1014.12050.13065.34372</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1697030760.48</float>
<float>1706542267.28</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -30,6 +30,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
this._loiter_radius = 100;
//this._start_altitude = 0;
this._loiter_mode = false;
this._is_landing = false;
this._is_ready_to_fly = true;
this._drone_dict_list = [];
}
Object.defineProperty(FixedWingDroneAPI.prototype, "isCollidable", {
......@@ -90,45 +92,15 @@ var FixedWingDroneAPI = /** @class */ (function () {
if (drone._maxClimbRate > drone._maxSpeed) {
throw new Error('max climb rate cannot be superior to max speed');
}
drone._maxOrientation = this.getMaxOrientation();
return;
};
/*
** Function called on every drone update, right before onUpdate AI script
*/
FixedWingDroneAPI.prototype.internal_update = function (context, delta_time) {
var diff, newrot, orientationValue, rotStep;
//TODO rotation
if (context._rotationTarget) {
rotStep = BABYLON.Vector3.Zero();
diff = context._rotationTarget.subtract(context._controlMesh.rotation);
rotStep.x = (diff.x >= 1) ? 1 : diff.x;
rotStep.y = (diff.y >= 1) ? 1 : diff.y;
rotStep.z = (diff.z >= 1) ? 1 : diff.z;
if (rotStep === BABYLON.Vector3.Zero()) {
context._rotationTarget = null;
return;
}
newrot = new BABYLON.Vector3(context._controlMesh.rotation.x +
(rotStep.x * context._rotationSpeed),
context._controlMesh.rotation.y +
(rotStep.y * context._rotationSpeed),
context._controlMesh.rotation.z +
(rotStep.z * context._rotationSpeed)
);
context._controlMesh.rotation = newrot;
}
this._updateSpeed(context, delta_time);
this._updatePosition(context, delta_time);
//TODO rotation
orientationValue = context._maxOrientation *
(context._speed / context._maxSpeed);
context._mesh.rotation =
new BABYLON.Vector3(orientationValue * context._direction.z, 0,
-orientationValue * context._direction.x);
context._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true);
};
......@@ -148,7 +120,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude,
'yaw': drone.getYaw(),
'speed': drone.getAirSpeed(),
'speed': drone.getSpeed(),
'climbRate': drone.getClimbRate()
};
_this._drone_dict_list[_this._id] = drone_info;
......@@ -162,7 +134,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) {
var speed = drone.getAirSpeed(), speedDiff, speedUpdate;
var speed = drone.get3DSpeed(), speedDiff, speedUpdate;
if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed;
speedUpdate = drone._acceleration * delta_time / 1000;
......@@ -235,7 +207,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt(
Math.pow(drone.getAirSpeed(), 2) - Math.pow(verticalSpeed, 2)
Math.pow(drone.get3DSpeed(), 2) - Math.pow(verticalSpeed, 2)
);
distance = (groundSpeed * delta_time / 1000) / R;
......@@ -297,39 +269,27 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._computeVerticalSpeed(
altitudeDiff,
this.getMaxClimbRate(),
drone.getAirSpeed(),
drone.get3DSpeed(),
this.getMaxPitchAngle()
);
} else {
verticalSpeed = -this._computeVerticalSpeed(
Math.abs(altitudeDiff),
this.getMaxSinkRate(),
drone.getAirSpeed(),
drone.get3DSpeed(),
-this.getMinPitchAngle()
);
}
return verticalSpeed;
};
FixedWingDroneAPI.prototype.setRotation = function (drone, x, y, z) {
//TODO rotation
drone._rotationTarget = new BABYLON.Vector3(x, z, y);
};
FixedWingDroneAPI.prototype.setRotationBy = function (drone, x, y, z) {
//TODO rotation
drone._rotationTarget = new BABYLON.Vector3(drone.rotation.x + x,
drone.rotation.y + z,
drone.rotation.z + y);
};
FixedWingDroneAPI.prototype.setSpeed = function (drone, speed) {
this._targetSpeed = Math.max(
Math.min(speed, this.getMaxSpeed()),
this.getMinSpeed()
);
drone._acceleration = (this._targetSpeed > drone.getAirSpeed())
drone._acceleration = (this._targetSpeed > drone.get3DSpeed())
? this.getMaxAcceleration() : -this.getMaxDeceleration();
};
......@@ -448,14 +408,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
FixedWingDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxClimbRate;
};
FixedWingDroneAPI.prototype.getMaxOrientation = function () {
//TODO should be a game parameter (but how to force value to PI quarters?)
return Math.PI / 4;
};
FixedWingDroneAPI.prototype.getYawVelocity = function (drone) {
return 360 * EARTH_GRAVITY
* Math.tan(this._toRad(this.getMaxRollAngle()))
/ (2 * Math.PI * drone.getAirSpeed());
/ (2 * Math.PI * drone.get3DSpeed());
};
FixedWingDroneAPI.prototype.getYaw = function (drone) {
var direction = drone.worldDirection;
......@@ -492,30 +448,34 @@ var FixedWingDroneAPI = /** @class */ (function () {
return angle * 180 / Math.PI;
};
FixedWingDroneAPI.prototype.getClimbRate = function (drone) {
return drone.worldDirection.y * drone.getAirSpeed();
return drone.worldDirection.y * drone.get3DSpeed();
};
FixedWingDroneAPI.prototype.getGroundSpeed = function (drone) {
FixedWingDroneAPI.prototype.getSpeed = function (drone) {
var direction = drone.worldDirection;
return Math.sqrt(
Math.pow(direction.x * drone.getAirSpeed(), 2)
+ Math.pow(direction.z * drone.getAirSpeed(), 2)
Math.pow(direction.x * drone.get3DSpeed(), 2)
+ Math.pow(direction.z * drone.get3DSpeed(), 2)
);
};
FixedWingDroneAPI.prototype.triggerParachute = function (drone) {
FixedWingDroneAPI.prototype.takeOff = function () {
return console.log("Fixed-wing drones can only be taken off manually.");
};
FixedWingDroneAPI.prototype.land = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(
drone_pos.latitude,
drone_pos.longitude,
5,
drone.getAirSpeed()
0,
drone.get3DSpeed()
);
this._is_ready_to_fly = false;
this._is_landing = true;
};
FixedWingDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition();
return Math.floor(drone_pos.altitude) < 10;
FixedWingDroneAPI.prototype.isReadyToFly = function () {
return this._is_ready_to_fly;
};
FixedWingDroneAPI.prototype.exit = function () {
return;
FixedWingDroneAPI.prototype.isLanding = function () {
return this._is_landing;
};
FixedWingDroneAPI.prototype.getInitialAltitude = function () {
return this._map_dict.start_AMSL;
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.11751.44914.51968</string> </value>
<value> <string>1014.12067.27492.45397</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1706523358.41</float>
<float>1706542739.07</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -25,11 +25,9 @@ var DroneManager = /** @class */ (function () {
this._maxRollAngle = 0;
this._maxSinkRate = 0;
this._maxClimbRate = 0;
this._maxOrientation = 0;
this._speed = 0;
this._acceleration = 0;
this._direction = new BABYLON.Vector3(0, 0, 1); // North
this._rotationSpeed = 0.4;
this._scene = scene;
this._canUpdate = true;
this._id = id;
......@@ -141,7 +139,7 @@ var DroneManager = /** @class */ (function () {
};
DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay) {
if (!this._canPlay || !this.isReadyToFly()) {
return;
}
//convert real geo-coordinates to virtual x-y coordinates
......@@ -209,20 +207,6 @@ var DroneManager = /** @class */ (function () {
this._direction = new BABYLON.Vector3(x, z, y).normalize();
};
//TODO rotation
DroneManager.prototype.setRotation = function (x, y, z) {
if (!this._canPlay) {
return;
}
return this._API.setRotation(this, x, y, z);
};
DroneManager.prototype.setRotationBy = function (x, y, z) {
if (!this._canPlay) {
return;
}
return this._API.setRotation(this, x, y, z);
};
/**
* Send a message to drones
* @param msg The message to send
......@@ -309,27 +293,29 @@ var DroneManager = /** @class */ (function () {
DroneManager.prototype.getYaw = function () {
return this._API.getYaw(this);
};
DroneManager.prototype.getAirSpeed = function () {
DroneManager.prototype.get3DSpeed = function () {
return this._speed;
};
DroneManager.prototype.getGroundSpeed = function () {
return this._API.getGroundSpeed(this);
DroneManager.prototype.getSpeed = function () {
return this._API.getSpeed(this);
};
DroneManager.prototype.getClimbRate = function () {
return this._API.getClimbRate(this);
};
DroneManager.prototype.getSinkRate = function () {
return this._API.getSinkRate();
DroneManager.prototype.takeOff = function () {
return this._API.takeOff();
};
DroneManager.prototype.triggerParachute = function () {
return this._API.triggerParachute(this);
DroneManager.prototype.land = function () {
return this._API.land(this);
};
DroneManager.prototype.exit = function () {
this._internal_crash();
return this._API.exit();
return this._internal_crash();
};
DroneManager.prototype.landed = function () {
return this._API.landed(this);
DroneManager.prototype.isReadyToFly = function () {
return this._API.isReadyToFly();
};
DroneManager.prototype.isLanding = function () {
return this._API.isLanding();
};
/**
* Set the drone last checkpoint reached
......@@ -347,7 +333,7 @@ var DroneManager = /** @class */ (function () {
* Function called on game update
* @param timestamp The tic value
*/
DroneManager.prototype.onUpdate = function () { return; };
DroneManager.prototype.onUpdate = function (timestamp) { return; };
/**
* Function called when drone crashes
*/
......@@ -668,8 +654,12 @@ var GameManager = /** @class */ (function () {
drone._tick += 1;
if (drone._API.isCollidable && drone.can_play) {
if (drone.getCurrentPosition().altitude <= 0) {
if (!drone.isLanding()) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.'));
} else {
drone._internal_crash();
}
} else {
_this._droneList.forEach(function (other) {
if (other.can_play && drone.id !== other.id) {
......@@ -722,7 +712,7 @@ var GameManager = /** @class */ (function () {
game_manager._game_duration, geo_coordinates.latitude,
geo_coordinates.longitude,
map_info.start_AMSL + drone_position.z,
drone_position.z, drone.getYaw(), drone.getGroundSpeed(),
drone_position.z, drone.getYaw(), drone.getSpeed(),
drone.getClimbRate()
]);
}
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.11746.34243.61149</string> </value>
<value> <string>1014.12072.47950.5358</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1706523386.8</float>
<float>1706542965.82</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.54902.15254.29337</string> </value>
<value> <string>1014.11755.64575.41864</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709130323.68</float>
<float>1706525997.75</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -57,7 +57,7 @@
'}\n' +
'\n' +
'me.onStart = function () {\n' +
' assert(me.getAirSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getSpeed(), ' + DEFAULT_SPEED + ', "Initial speed");\n' +
' assert(me.getYaw(), 0, "Yaw angle")\n' +
' me.initialPosition = me.getCurrentPosition();\n' +
' me.setTargetCoordinates(\n' +
......@@ -76,7 +76,7 @@
' me.getCurrentPosition().latitude,\n' +
' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\n' +
' expectedDistance = (me.getAirSpeed() * timestamp / 1000).toFixed(8);\n' +
' expectedDistance = (me.getSpeed() * timestamp / 1000).toFixed(8);\n' +
' assert(timestamp, 1000 / 60, "Timestamp");\n' +
' assert(realDistance, expectedDistance, "Distance");\n' +
' current_position.latitude = current_position.latitude.toFixed(7);\n' +
......@@ -85,7 +85,7 @@
' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' +
' });\n' +
' me.exit(me.triggerParachute());\n' +
' me.exit(me.land());\n' +
'};',
DRAW = true,
LOG = true,
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1014.55202.15664.53026</string> </value>
<value> <string>1014.55287.25371.8430</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1709130383.65</float>
<float>1709136309.62</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment