Commit ba5a3f09 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾 Committed by Kazuhiko Shiozaki

erp5_officejs_drone_simulator: rename triggerParachute into land

Rename triggerParachute function into land in DroneManager for
compliance with multicopters APIs.
parent 324a3ea3
...@@ -23,6 +23,8 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -23,6 +23,8 @@ var EnemyDroneAPI = /** @class */ (function () {
this._drone_dict_list = []; this._drone_dict_list = [];
this._acceleration = DEFAULT_ACCELERATION; this._acceleration = DEFAULT_ACCELERATION;
this._collision_sector = COLLISION_SECTOR; 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 ** Function called on start phase of the drone, just before onStart AI script
...@@ -49,7 +51,6 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -49,7 +51,6 @@ var EnemyDroneAPI = /** @class */ (function () {
if (drone._maxSinkRate > drone._maxSpeed) { if (drone._maxSinkRate > drone._maxSpeed) {
throw new Error('max sink rate cannot be superior to max speed'); throw new Error('max sink rate cannot be superior to max speed');
} }
drone._maxOrientation = this.getMaxOrientation();
return; return;
}; };
/* /*
...@@ -57,10 +58,12 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -57,10 +58,12 @@ var EnemyDroneAPI = /** @class */ (function () {
*/ */
EnemyDroneAPI.prototype.internal_update = function (context, delta_time) { EnemyDroneAPI.prototype.internal_update = function (context, delta_time) {
context._speed += context._acceleration * delta_time / 1000; context._speed += context._acceleration * delta_time / 1000;
if (context._speed > context._maxSpeed) if (context._speed > context._maxSpeed) {
context._speed = context._maxSpeed; context._speed = context._maxSpeed;
if (context._speed < -context._maxSpeed) }
if (context._speed < -context._maxSpeed) {
context._speed = -context._maxSpeed; context._speed = -context._maxSpeed;
}
var updateSpeed = context._speed * delta_time / 1000; var updateSpeed = context._speed * delta_time / 1000;
if (context._direction.x !== 0 || if (context._direction.x !== 0 ||
context._direction.y !== 0 || context._direction.y !== 0 ||
...@@ -68,13 +71,9 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -68,13 +71,9 @@ var EnemyDroneAPI = /** @class */ (function () {
context._controlMesh.position.addInPlace( context._controlMesh.position.addInPlace(
new BABYLON.Vector3(context._direction.x * updateSpeed, new BABYLON.Vector3(context._direction.x * updateSpeed,
context._direction.y * 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._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true); context._mesh.computeWorldMatrix(true);
return; return;
...@@ -119,7 +118,9 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -119,7 +118,9 @@ var EnemyDroneAPI = /** @class */ (function () {
EnemyDroneAPI.prototype.internal_setTargetCoordinates = EnemyDroneAPI.prototype.internal_setTargetCoordinates =
function (drone, coordinates) { function (drone, coordinates) {
if (!drone._canPlay) return; if (!drone._canPlay) {
return;
}
var x = coordinates.x, y = coordinates.y, z = coordinates.z; var x = coordinates.x, y = coordinates.y, z = coordinates.z;
if (isNaN(x) || isNaN(y) || isNaN(z)) { if (isNaN(x) || isNaN(y) || isNaN(z)) {
throw new Error('Target coordinates must be numbers'); throw new Error('Target coordinates must be numbers');
...@@ -279,20 +280,17 @@ var EnemyDroneAPI = /** @class */ (function () { ...@@ -279,20 +280,17 @@ var EnemyDroneAPI = /** @class */ (function () {
EnemyDroneAPI.prototype.getMaxAcceleration = function () { EnemyDroneAPI.prototype.getMaxAcceleration = function () {
return this._flight_parameters.drone.maxAcceleration; return this._flight_parameters.drone.maxAcceleration;
}; };
EnemyDroneAPI.prototype.getMaxOrientation = function () { EnemyDroneAPI.prototype.land = function (drone) {
//TODO should be a game parameter (but how to force value to PI quarters?)
return Math.PI / 4;
};
EnemyDroneAPI.prototype.triggerParachute = function (drone) {
var drone_pos = drone.getCurrentPosition(); 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) { EnemyDroneAPI.prototype.isReadyToFly = function () {
var drone_pos = drone.getCurrentPosition(); return this._is_ready_to_fly;
return Math.floor(drone_pos.altitude) < 10;
}; };
EnemyDroneAPI.prototype.exit = function () { EnemyDroneAPI.prototype.isLanding = function () {
return; return this._is_landing;
}; };
EnemyDroneAPI.prototype.getInitialAltitude = function () { EnemyDroneAPI.prototype.getInitialAltitude = function () {
return 0; return 0;
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.46035.33513.61849</string> </value> <value> <string>1014.56714.1017.16076</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1697031010.99</float> <float>1709221104.19</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -31,6 +31,8 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -31,6 +31,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
this._loiter_radius = 100; this._loiter_radius = 100;
//this._start_altitude = 0; //this._start_altitude = 0;
this._loiter_mode = false; this._loiter_mode = false;
this._is_landing = false;
this._is_ready_to_fly = true;
this._drone_dict_list = []; this._drone_dict_list = [];
} }
/* /*
...@@ -86,45 +88,15 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -86,45 +88,15 @@ var FixedWingDroneAPI = /** @class */ (function () {
if (drone._maxClimbRate > drone._maxSpeed) { if (drone._maxClimbRate > drone._maxSpeed) {
throw new Error('max climb rate cannot be superior to max speed'); throw new Error('max climb rate cannot be superior to max speed');
} }
drone._maxOrientation = this.getMaxOrientation();
return; return;
}; };
/* /*
** Function called on every drone update, right before onUpdate AI script ** Function called on every drone update, right before onUpdate AI script
*/ */
FixedWingDroneAPI.prototype.internal_update = function (context, delta_time) { 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._updateSpeed(context, delta_time);
this._updatePosition(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._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true); context._mesh.computeWorldMatrix(true);
}; };
...@@ -144,7 +116,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -144,7 +116,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
'latitude' : drone_position.latitude, 'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude, 'longitude' : drone_position.longitude,
'yaw': drone.getYaw(), 'yaw': drone.getYaw(),
'speed': drone.getAirSpeed(), 'speed': drone.getSpeed(),
'climbRate': drone.getClimbRate() 'climbRate': drone.getClimbRate()
}; };
_this._drone_dict_list[_this._id] = drone_info; _this._drone_dict_list[_this._id] = drone_info;
...@@ -158,7 +130,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -158,7 +130,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
}; };
FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) { FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) {
var speed = drone.getAirSpeed(), speedDiff, speedUpdate; var speed = drone.get3DSpeed(), speedDiff, speedUpdate;
if (speed !== this._targetSpeed) { if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed; speedDiff = this._targetSpeed - speed;
speedUpdate = drone._acceleration * delta_time / 1000; speedUpdate = drone._acceleration * delta_time / 1000;
...@@ -231,7 +203,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -231,7 +203,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._getVerticalSpeed(drone); verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt( 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; distance = (groundSpeed * delta_time / 1000) / R;
...@@ -240,7 +212,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -240,7 +212,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
newLatRad = Math.asin( newLatRad = Math.asin(
currentSinLat * distanceCos + currentSinLat * distanceCos +
currentCosLat * distanceSin * Math.cos(newYawRad) currentCosLat * distanceSin * Math.cos(newYawRad)
); );
newLonRad = currentLonRad + Math.atan2( newLonRad = currentLonRad + Math.atan2(
Math.sin(newYawRad) * distanceSin * currentCosLat, Math.sin(newYawRad) * distanceSin * currentCosLat,
...@@ -256,10 +228,10 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -256,10 +228,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
// swap y and z axis so z axis represents altitude // swap y and z axis so z axis represents altitude
drone._controlMesh.position.addInPlace(new BABYLON.Vector3( drone._controlMesh.position.addInPlace(new BABYLON.Vector3(
Math.abs(newCoordinates.x - drone.position.x) * Math.abs(newCoordinates.x - drone.position.x) *
(newCoordinates.x < drone.position.x ? -1 : 1), (newCoordinates.x < drone.position.x ? -1 : 1),
verticalSpeed * delta_time / 1000, verticalSpeed * delta_time / 1000,
Math.abs(newCoordinates.y - drone.position.y) * Math.abs(newCoordinates.y - drone.position.y) *
(newCoordinates.y < drone.position.y ? -1 : 1) (newCoordinates.y < drone.position.y ? -1 : 1)
)); ));
yawToDirection = this._toRad(-newYaw + 90); yawToDirection = this._toRad(-newYaw + 90);
drone.setDirection( drone.setDirection(
...@@ -293,40 +265,28 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -293,40 +265,28 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._computeVerticalSpeed( verticalSpeed = this._computeVerticalSpeed(
altitudeDiff, altitudeDiff,
this.getMaxClimbRate(), this.getMaxClimbRate(),
drone.getAirSpeed(), drone.get3DSpeed(),
this.getMaxPitchAngle() this.getMaxPitchAngle()
); );
} else { } else {
verticalSpeed = -this._computeVerticalSpeed( verticalSpeed = -this._computeVerticalSpeed(
Math.abs(altitudeDiff), Math.abs(altitudeDiff),
this.getMaxSinkRate(), this.getMaxSinkRate(),
drone.getAirSpeed(), drone.get3DSpeed(),
-this.getMinPitchAngle() -this.getMinPitchAngle()
); );
} }
return verticalSpeed; 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) { FixedWingDroneAPI.prototype.setSpeed = function (drone, speed) {
this._targetSpeed = Math.max( this._targetSpeed = Math.max(
Math.min(speed, this.getMaxSpeed()), Math.min(speed, this.getMaxSpeed()),
this.getMinSpeed() this.getMinSpeed()
); );
drone._acceleration = (this._targetSpeed > drone.getAirSpeed()) ? drone._acceleration = (this._targetSpeed > drone.get3DSpeed()) ?
this.getMaxAcceleration() : -this.getMaxDeceleration(); this.getMaxAcceleration() : -this.getMaxDeceleration();
}; };
FixedWingDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) { FixedWingDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) {
...@@ -490,14 +450,10 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -490,14 +450,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
FixedWingDroneAPI.prototype.getMaxClimbRate = function () { FixedWingDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxClimbRate; 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) { FixedWingDroneAPI.prototype.getYawVelocity = function (drone) {
return 360 * EARTH_GRAVITY * return 360 * EARTH_GRAVITY *
Math.tan(this._toRad(this.getMaxRollAngle())) / Math.tan(this._toRad(this.getMaxRollAngle())) /
(2 * Math.PI * drone.getAirSpeed()); (2 * Math.PI * drone.get3DSpeed());
}; };
FixedWingDroneAPI.prototype.getYaw = function (drone) { FixedWingDroneAPI.prototype.getYaw = function (drone) {
var direction = drone.worldDirection; var direction = drone.worldDirection;
...@@ -523,7 +479,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -523,7 +479,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
var maxVerticalSpeed = var maxVerticalSpeed =
Math.min(altitude_diff, Math.min(max_climb_rate, speed)); Math.min(altitude_diff, Math.min(max_climb_rate, speed));
return (this._toDeg(Math.asin(maxVerticalSpeed / speed)) > max_pitch) ? return (this._toDeg(Math.asin(maxVerticalSpeed / speed)) > max_pitch) ?
speed * Math.sin(this._toRad(max_pitch)) speed * Math.sin(this._toRad(max_pitch))
: maxVerticalSpeed; : maxVerticalSpeed;
}; };
FixedWingDroneAPI.prototype._toRad = function (angle) { FixedWingDroneAPI.prototype._toRad = function (angle) {
...@@ -533,30 +489,34 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -533,30 +489,34 @@ var FixedWingDroneAPI = /** @class */ (function () {
return angle * 180 / Math.PI; return angle * 180 / Math.PI;
}; };
FixedWingDroneAPI.prototype.getClimbRate = function (drone) { 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; var direction = drone.worldDirection;
return Math.sqrt( return Math.sqrt(
Math.pow(direction.x * drone.getAirSpeed(), 2) + Math.pow(direction.x * drone.get3DSpeed(), 2) +
Math.pow(direction.z * drone.getAirSpeed(), 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(); var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates( drone.setTargetCoordinates(
drone_pos.latitude, drone_pos.latitude,
drone_pos.longitude, drone_pos.longitude,
5, 0,
drone.getAirSpeed() drone.get3DSpeed()
); );
this._is_ready_to_fly = false;
this._is_landing = true;
}; };
FixedWingDroneAPI.prototype.landed = function (drone) { FixedWingDroneAPI.prototype.isReadyToFly = function () {
var drone_pos = drone.getCurrentPosition(); return this._is_ready_to_fly;
return Math.floor(drone_pos.altitude) < 10;
}; };
FixedWingDroneAPI.prototype.exit = function () { FixedWingDroneAPI.prototype.isLanding = function () {
return; return this._is_landing;
}; };
FixedWingDroneAPI.prototype.getInitialAltitude = function () { FixedWingDroneAPI.prototype.getInitialAltitude = function () {
return this._map_dict.start_AMSL; return this._map_dict.start_AMSL;
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.48041.44620.29337</string> </value> <value> <string>1014.56746.48697.2713</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709113157.81</float> <float>1709223091.4</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -25,11 +25,9 @@ var DroneManager = /** @class */ (function () { ...@@ -25,11 +25,9 @@ var DroneManager = /** @class */ (function () {
this._maxRollAngle = 0; this._maxRollAngle = 0;
this._maxSinkRate = 0; this._maxSinkRate = 0;
this._maxClimbRate = 0; this._maxClimbRate = 0;
this._maxOrientation = 0;
this._speed = 0; this._speed = 0;
this._acceleration = 0; this._acceleration = 0;
this._direction = new BABYLON.Vector3(0, 0, 1); // North this._direction = new BABYLON.Vector3(0, 0, 1); // North
this._rotationSpeed = 0.4;
this._scene = scene; this._scene = scene;
this._canUpdate = true; this._canUpdate = true;
this._id = id; this._id = id;
...@@ -155,7 +153,7 @@ var DroneManager = /** @class */ (function () { ...@@ -155,7 +153,7 @@ var DroneManager = /** @class */ (function () {
}; };
DroneManager.prototype._internal_setTargetCoordinates = DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) { function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay) { if (!this._canPlay || !this.isReadyToFly()) {
return; return;
} }
//each drone API process coordinates on its needs //each drone API process coordinates on its needs
...@@ -208,14 +206,15 @@ var DroneManager = /** @class */ (function () { ...@@ -208,14 +206,15 @@ var DroneManager = /** @class */ (function () {
} }
return; return;
}; };
DroneManager.prototype._internal_crash = function (error) { DroneManager.prototype._internal_crash = function (error, print_stack) {
if (print_stack === "undefined") { print_stack = true; }
this.last_position = this.position; this.last_position = this.position;
this._canCommunicate = false; this._canCommunicate = false;
this._controlMesh = null; this._controlMesh = null;
this._mesh = null; this._mesh = null;
this._canPlay = false; this._canPlay = false;
if (error) { if (error) {
this._API._gameManager.logError(this, error); this._API._gameManager.logError(this, error, print_stack);
} }
this.onTouched(); this.onTouched();
}; };
...@@ -236,20 +235,6 @@ var DroneManager = /** @class */ (function () { ...@@ -236,20 +235,6 @@ var DroneManager = /** @class */ (function () {
this._direction = new BABYLON.Vector3(x, z, y).normalize(); 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 * Send a message to drones
* @param msg The message to send * @param msg The message to send
...@@ -342,41 +327,40 @@ var DroneManager = /** @class */ (function () { ...@@ -342,41 +327,40 @@ var DroneManager = /** @class */ (function () {
return null; return null;
}; };
DroneManager.prototype.getYaw = function () { DroneManager.prototype.getYaw = function () {
if (typeof this._API.getYaw !== "undefined") { if (this._API.getYaw !== undefined) {
return this._API.getYaw(this); return this._API.getYaw(this);
} }
return; return;
}; };
DroneManager.prototype.getAirSpeed = function () { DroneManager.prototype.get3DSpeed = function () {
return this._speed; return this._speed;
}; };
DroneManager.prototype.getGroundSpeed = function () { DroneManager.prototype.getSpeed = function () {
if (typeof this._API.getGroundSpeed !== "undefined") { if (this._API.getSpeed !== "undefined") {
return this._API.getGroundSpeed(this); return this._API.getSpeed(this);
} }
return; return;
}; };
DroneManager.prototype.getClimbRate = function () { DroneManager.prototype.getClimbRate = function () {
if (typeof this._API.getClimbRate !== "undefined") { if (this._API.getClimbRate !== "undefined") {
return this._API.getClimbRate(this); return this._API.getClimbRate(this);
} }
return; return;
}; };
DroneManager.prototype.getSinkRate = function () { DroneManager.prototype.takeOff = function () {
if (typeof this._API.getSinkRate !== "undefined") { return this._API.takeOff();
return this._API.getSinkRate(this);
}
return;
}; };
DroneManager.prototype.triggerParachute = function () { DroneManager.prototype.land = function () {
return this._API.triggerParachute(this); return this._API.land(this);
}; };
DroneManager.prototype.exit = function () { DroneManager.prototype.exit = function () {
this._internal_crash(); return this._internal_crash();
return this._API.exit();
}; };
DroneManager.prototype.landed = function () { DroneManager.prototype.isReadyToFly = function () {
return this._API.landed(this); return this._API.isReadyToFly();
};
DroneManager.prototype.isLanding = function () {
return this._API.isLanding();
}; };
/** /**
* Set the drone last checkpoint reached * Set the drone last checkpoint reached
...@@ -394,7 +378,7 @@ var DroneManager = /** @class */ (function () { ...@@ -394,7 +378,7 @@ var DroneManager = /** @class */ (function () {
* Function called on game update * Function called on game update
* @param timestamp The tic value * @param timestamp The tic value
*/ */
DroneManager.prototype.onUpdate = function () { return; }; DroneManager.prototype.onUpdate = function (timestamp) { return; };
/** /**
* Function called when drone crashes * Function called when drone crashes
*/ */
...@@ -442,7 +426,12 @@ var MapManager = /** @class */ (function () { ...@@ -442,7 +426,12 @@ var MapManager = /** @class */ (function () {
function MapManager(scene, map_param) { function MapManager(scene, map_param) {
var _this = this, max_sky, skybox, skyboxMat, largeGroundMat, flag_material, var _this = this, max_sky, skybox, skyboxMat, largeGroundMat, flag_material,
largeGroundBottom, width, depth, terrain, max, flag_a, flag_b, mast, flag, largeGroundBottom, width, depth, terrain, max, flag_a, flag_b, mast, flag,
count = 0, new_obstacle, obstacle, flag_info, enemy; count = 0, new_obstacle, obstacle, flag_info, enemy,
FLAG_SIZE = {
'x': 1,
'y': 1,
'z': 6
};
if (!map_param) { if (!map_param) {
// Use default map base parameters // Use default map base parameters
map_param = MAP; map_param = MAP;
...@@ -453,7 +442,8 @@ var MapManager = /** @class */ (function () { ...@@ -453,7 +442,8 @@ var MapManager = /** @class */ (function () {
_this.map_info.initial_position = _this.mapUtils.convertToLocalCoordinates( _this.map_info.initial_position = _this.mapUtils.convertToLocalCoordinates(
_this.map_info.initial_position.latitude, _this.map_info.initial_position.latitude,
_this.map_info.initial_position.longitude, _this.map_info.initial_position.longitude,
_this.map_info.initial_position.altitude); _this.map_info.initial_position.altitude
);
max = _this.map_info.width; max = _this.map_info.width;
if (_this.map_info.depth > max) { if (_this.map_info.depth > max) {
max = _this.map_info.depth; max = _this.map_info.depth;
...@@ -504,7 +494,8 @@ var MapManager = /** @class */ (function () { ...@@ -504,7 +494,8 @@ var MapManager = /** @class */ (function () {
enemy.position = _this.mapUtils.convertToLocalCoordinates( enemy.position = _this.mapUtils.convertToLocalCoordinates(
geo_enemy.position.latitude, geo_enemy.position.latitude,
geo_enemy.position.longitude, geo_enemy.position.longitude,
geo_enemy.position.altitude); geo_enemy.position.altitude
);
_this._enemy_list.push(enemy); _this._enemy_list.push(enemy);
}); });
// Obstacles // Obstacles
...@@ -515,7 +506,8 @@ var MapManager = /** @class */ (function () { ...@@ -515,7 +506,8 @@ var MapManager = /** @class */ (function () {
obstacle.position = _this.mapUtils.convertToLocalCoordinates( obstacle.position = _this.mapUtils.convertToLocalCoordinates(
geo_obstacle.position.latitude, geo_obstacle.position.latitude,
geo_obstacle.position.longitude, geo_obstacle.position.longitude,
geo_obstacle.position.altitude); geo_obstacle.position.altitude
);
switch (obstacle.type) { switch (obstacle.type) {
case "box": case "box":
new_obstacle = BABYLON.MeshBuilder.CreateBox("obs_" + count, new_obstacle = BABYLON.MeshBuilder.CreateBox("obs_" + count,
...@@ -539,41 +531,41 @@ var MapManager = /** @class */ (function () { ...@@ -539,41 +531,41 @@ var MapManager = /** @class */ (function () {
return; return;
} }
new_obstacle.type = obstacle.type; new_obstacle.type = obstacle.type;
var convertion = Math.PI / 180; var convertion = Math.PI / 180,
if ("position" in obstacle) obs_material = new BABYLON.StandardMaterial("obsmat_" + count, scene);
if (obstacle.hasOwnProperty("position")) {
new_obstacle.position = new BABYLON.Vector3(obstacle.position.x, new_obstacle.position = new BABYLON.Vector3(obstacle.position.x,
obstacle.position.z, obstacle.position.z,
obstacle.position.y); obstacle.position.y);
if ("rotation" in obstacle) }
if (obstacle.hasOwnProperty("rotation")) {
new_obstacle.rotation = new_obstacle.rotation =
new BABYLON.Vector3(obstacle.rotation.x * convertion, new BABYLON.Vector3(obstacle.rotation.x * convertion,
obstacle.rotation.z * convertion, obstacle.rotation.z * convertion,
obstacle.rotation.y * convertion); obstacle.rotation.y * convertion);
if ("scale" in obstacle) }
if (obstacle.hasOwnProperty("scale")) {
new_obstacle.scaling = new BABYLON.Vector3(obstacle.scale.x, new_obstacle.scaling = new BABYLON.Vector3(obstacle.scale.x,
obstacle.scale.z, obstacle.scale.z,
obstacle.scale.y); obstacle.scale.y);
var obs_material = new BABYLON.StandardMaterial("obsmat_" + count, scene); }
obs_material.alpha = 1; obs_material.alpha = 1;
obs_material.diffuseColor = new BABYLON.Color3(255, 153, 0); obs_material.diffuseColor = new BABYLON.Color3(255, 153, 0);
new_obstacle.material = obs_material; new_obstacle.material = obs_material;
_this._obstacle_list.push(new_obstacle); _this._obstacle_list.push(new_obstacle);
count++; count += 1;
}); });
// Flags // Flags
_this._flag_list = []; _this._flag_list = [];
var FLAG_SIZE = {
'x': 1,
'y': 1,
'z': 6
};
_this.map_info.flag_list.forEach(function (geo_flag, index) { _this.map_info.flag_list.forEach(function (geo_flag, index) {
flag_info = {}; flag_info = {};
Object.assign(flag_info, geo_flag); Object.assign(flag_info, geo_flag);
flag_info.position = _this.mapUtils.convertToLocalCoordinates( flag_info.position = _this.mapUtils.convertToLocalCoordinates(
geo_flag.position.latitude, geo_flag.position.latitude,
geo_flag.position.longitude, geo_flag.position.longitude,
geo_flag.position.altitude); geo_flag.position.altitude
);
flag_material = new BABYLON.StandardMaterial("flag_mat_" + index, scene); flag_material = new BABYLON.StandardMaterial("flag_mat_" + index, scene);
flag_material.alpha = 1; flag_material.alpha = 1;
flag_material.diffuseColor = BABYLON.Color3.Green(); flag_material.diffuseColor = BABYLON.Color3.Green();
...@@ -607,7 +599,8 @@ var MapManager = /** @class */ (function () { ...@@ -607,7 +599,8 @@ var MapManager = /** @class */ (function () {
mast.scaling = new BABYLON.Vector3( mast.scaling = new BABYLON.Vector3(
FLAG_SIZE.x, FLAG_SIZE.x,
FLAG_SIZE.z, //swap FLAG_SIZE.z, //swap
FLAG_SIZE.y); FLAG_SIZE.y
);
mast.material = flag_material; mast.material = flag_material;
flag = BABYLON.Mesh.MergeMeshes([flag_a, flag_b, mast]); flag = BABYLON.Mesh.MergeMeshes([flag_a, flag_b, mast]);
flag.id = index; flag.id = index;
...@@ -633,7 +626,10 @@ var MapManager = /** @class */ (function () { ...@@ -633,7 +626,10 @@ var MapManager = /** @class */ (function () {
MapManager.prototype.convertToLocalCoordinates = MapManager.prototype.convertToLocalCoordinates =
function (latitude, longitude, altitude) { function (latitude, longitude, altitude) {
return this.mapUtils.convertToLocalCoordinates( return this.mapUtils.convertToLocalCoordinates(
latitude, longitude, altitude); latitude,
longitude,
altitude
);
}; };
MapManager.prototype.convertToGeoCoordinates = function (x, y, z) { MapManager.prototype.convertToGeoCoordinates = function (x, y, z) {
return this.mapUtils.convertToGeoCoordinates(x, y, z); return this.mapUtils.convertToGeoCoordinates(x, y, z);
...@@ -712,7 +708,7 @@ var GameManager = /** @class */ (function () { ...@@ -712,7 +708,7 @@ var GameManager = /** @class */ (function () {
console.log = function () { console.log = function () {
baseLogFunction.apply(console, arguments); baseLogFunction.apply(console, arguments);
var args = Array.prototype.slice.call(arguments); var args = Array.prototype.slice.call(arguments);
for (i = 0;i < args.length;i++) { for (i = 0; i < args.length; i += 1) {
console_log += args[i] + "\n"; console_log += args[i] + "\n";
} }
}; };
...@@ -753,13 +749,13 @@ var GameManager = /** @class */ (function () { ...@@ -753,13 +749,13 @@ var GameManager = /** @class */ (function () {
(0 < _this.waiting_update_count)) { (0 < _this.waiting_update_count)) {
_this.ongoing_update_promise = _this._update(TIME_DELTA, fullscreen) _this.ongoing_update_promise = _this._update(TIME_DELTA, fullscreen)
.push(function () { .push(function () {
_this.waiting_update_count -= 1; _this.waiting_update_count -= 1;
_this.ongoing_update_promise = null; _this.ongoing_update_promise = null;
triggerUpdateIfPossible(); triggerUpdateIfPossible();
}).push(undefined, function (error) { }).push(undefined, function (error) {
console.log("ERROR on Game Manager update:", error); console.log("ERROR on Game Manager update:", error);
_this.finish_deferred.reject.bind(_this.finish_deferred); _this.finish_deferred.reject.bind(_this.finish_deferred);
}); });
} }
} }
try { try {
...@@ -775,9 +771,12 @@ var GameManager = /** @class */ (function () { ...@@ -775,9 +771,12 @@ var GameManager = /** @class */ (function () {
this._delayed_defer_list.push([callback, millisecond]); this._delayed_defer_list.push([callback, millisecond]);
}; };
GameManager.prototype.logError = function (drone, error) { GameManager.prototype.logError = function (drone, error, print_stack) {
if (drone._id < this._flight_log.length) { // don't log enemies if (drone._id < this._flight_log.length) { // don't log enemies
this._flight_log[drone._id].push(error.stack); this._flight_log[drone._id].push(error.message);
if (print_stack) {
this._flight_log[drone._id].push(error.stack);
}
} }
}; };
...@@ -793,11 +792,10 @@ var GameManager = /** @class */ (function () { ...@@ -793,11 +792,10 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._checkObstacleCollision = function (drone, obstacle) { GameManager.prototype._checkObstacleCollision = function (drone, obstacle) {
var closest = void 0, projected = BABYLON.Vector3.Zero();
if (drone.colliderMesh && if (drone.colliderMesh &&
drone.colliderMesh.intersectsMesh(obstacle, true)) { drone.colliderMesh.intersectsMesh(obstacle, true)) {
drone._internal_crash(new Error('Drone ' + drone.id + drone._internal_crash(new Error('Drone ' + drone.id +
' touched an obstacle.')); ' touched an obstacle.'), false);
//Following workaround seems not needed with new babylonjs versions //Following workaround seems not needed with new babylonjs versions
/** /**
* Closest facet check is needed for sphere and cylinder, * Closest facet check is needed for sphere and cylinder,
...@@ -821,7 +819,9 @@ var GameManager = /** @class */ (function () { ...@@ -821,7 +819,9 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._checkFlagCollision = function (drone, flag) { GameManager.prototype._checkFlagCollision = function (drone, flag) {
if (drone.team == TEAM_ENEMY) return; if (drone.team === TEAM_ENEMY) {
return;
}
function distance(a, b) { function distance(a, b) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) + return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) +
Math.pow((a.z - b.z), 2)); Math.pow((a.z - b.z), 2));
...@@ -830,9 +830,9 @@ var GameManager = /** @class */ (function () { ...@@ -830,9 +830,9 @@ var GameManager = /** @class */ (function () {
//TODO epsilon distance is 15 because of fixed wing loiter flights //TODO epsilon distance is 15 because of fixed wing loiter flights
//there is not a proper collision //there is not a proper collision
if (distance(drone.position, flag.location) <= if (distance(drone.position, flag.location) <=
this._mapManager.getMapInfo().flag_distance_epsilon) { this._mapManager.getMapInfo().flag_distance_epsilon) {
drone._internal_crash(new Error('Drone ' + drone.id + drone._internal_crash(new Error('Drone ' + drone.id +
' touched flag ' + flag.id)); ' touched flag ' + flag.id), false);
if (flag.weight > 0) { if (flag.weight > 0) {
flag.weight -= 1; flag.weight -= 1;
drone.score += flag.score; // move score to a global place? GM, MM? drone.score += flag.score; // move score to a global place? GM, MM?
...@@ -842,17 +842,19 @@ var GameManager = /** @class */ (function () { ...@@ -842,17 +842,19 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._checkCollision = function (drone, other) { GameManager.prototype._checkCollision = function (drone, other) {
if (drone.team == TEAM_ENEMY && other.team == TEAM_ENEMY) return; if (drone.team === TEAM_ENEMY && other.team === TEAM_ENEMY) {
return;
}
function distance(a, b) { function distance(a, b) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) + return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) +
Math.pow((a.z - b.z), 2)); Math.pow((a.z - b.z), 2));
} }
if (drone.team != other.team) { if (drone.team !== other.team) {
var enemy, prey; var enemy, prey;
if (drone.team == TEAM_ENEMY) { if (drone.team === TEAM_ENEMY) {
enemy = drone; enemy = drone;
prey = other; prey = other;
} else if (other.team == TEAM_ENEMY) { } else if (other.team === TEAM_ENEMY) {
enemy = other; enemy = other;
prey = drone; prey = drone;
} }
...@@ -860,18 +862,18 @@ var GameManager = /** @class */ (function () { ...@@ -860,18 +862,18 @@ var GameManager = /** @class */ (function () {
if (distance(drone.position, other.position) < if (distance(drone.position, other.position) <
enemy.getCollisionSector()) { enemy.getCollisionSector()) {
drone._internal_crash(new Error('enemy drone ' + enemy.id + drone._internal_crash(new Error('enemy drone ' + enemy.id +
' bumped drone ' + prey.id + '.')); ' bumped drone ' + prey.id + '.'), false);
other._internal_crash(new Error('enemy drone ' + enemy.id + other._internal_crash(new Error('enemy drone ' + enemy.id +
' bumped drone ' + prey.id + '.')); ' bumped drone ' + prey.id + '.'), false);
} }
} }
} }
if (drone.colliderMesh && other.colliderMesh && if (drone.colliderMesh && other.colliderMesh &&
drone.colliderMesh.intersectsMesh(other.colliderMesh, false)) { drone.colliderMesh.intersectsMesh(other.colliderMesh, false)) {
drone._internal_crash(new Error('drone ' + drone.id + drone._internal_crash(new Error('drone ' + drone.id +
' touched drone ' + other.id + '.')); ' touched drone ' + other.id + '.'), false);
other._internal_crash(new Error('drone ' + drone.id + other._internal_crash(new Error('drone ' + drone.id +
' touched drone ' + other.id + '.')); ' touched drone ' + other.id + '.'), false);
} }
}; };
...@@ -907,20 +909,21 @@ var GameManager = /** @class */ (function () { ...@@ -907,20 +909,21 @@ var GameManager = /** @class */ (function () {
this._droneList.forEach(function (drone) { this._droneList.forEach(function (drone) {
queue.push(function () { queue.push(function () {
var msg = '';
drone._tick += 1; drone._tick += 1;
if (drone.can_play) { if (drone.can_play) {
if (drone.getCurrentPosition().altitude <= 0) { if (drone.getCurrentPosition().altitude <= 0) {
if (!drone.isLanding()) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.'), false);
} else {
drone._internal_crash();
}
} else if (_this._checkDroneOut(drone)) {
drone._internal_crash(new Error('Drone ' + drone.id + drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.')); ' out of limits.'), false);
} } else {
else if (_this._checkDroneOut(drone)) {
drone._internal_crash(new Error('Drone ' + drone.id +
' out of limits.'));
}
else {
_this._droneList.forEach(function (other) { _this._droneList.forEach(function (other) {
if (other.can_play && drone.id != other.id) { if (other.can_play && drone.id !== other.id) {
_this._checkCollision(drone, other); _this._checkCollision(drone, other);
} }
}); });
...@@ -941,7 +944,9 @@ var GameManager = /** @class */ (function () { ...@@ -941,7 +944,9 @@ var GameManager = /** @class */ (function () {
if (_this._timeOut()) { if (_this._timeOut()) {
console.log("TIMEOUT!"); console.log("TIMEOUT!");
_this._droneList.forEach(function (drone) { _this._droneList.forEach(function (drone) {
if (drone.can_play) drone._internal_crash(new Error('Timeout.')); if (drone.can_play) {
drone._internal_crash(new Error('Timeout.'), false);
}
}); });
_this._result_message += "TIMEOUT!"; _this._result_message += "TIMEOUT!";
return _this._finish(); return _this._finish();
...@@ -986,7 +991,7 @@ var GameManager = /** @class */ (function () { ...@@ -986,7 +991,7 @@ var GameManager = /** @class */ (function () {
game_manager._game_duration, geo_coordinates.latitude, game_manager._game_duration, geo_coordinates.latitude,
geo_coordinates.longitude, geo_coordinates.longitude,
map_info.start_AMSL + drone_position.z, map_info.start_AMSL + drone_position.z,
drone_position.z, drone.getYaw(), drone.getGroundSpeed(), drone_position.z, drone.getYaw(), drone.getSpeed(),
drone.getClimbRate() drone.getClimbRate()
]); ]);
} }
...@@ -1052,7 +1057,9 @@ var GameManager = /** @class */ (function () { ...@@ -1052,7 +1057,9 @@ var GameManager = /** @class */ (function () {
if (drone.last_position) { if (drone.last_position) {
dist = Math.sqrt(Math.pow((drone.last_position.x - base.x), 2) dist = Math.sqrt(Math.pow((drone.last_position.x - base.x), 2)
+ Math.pow((drone.last_position.y - base.y), 2)); + Math.pow((drone.last_position.y - base.y), 2));
if (dist < BASE_DISTANCE) score += 1; if (dist < BASE_DISTANCE) {
score += 1;
}
} }
}); });
return score; return score;
...@@ -1072,8 +1079,8 @@ var GameManager = /** @class */ (function () { ...@@ -1072,8 +1079,8 @@ var GameManager = /** @class */ (function () {
}; };
GameManager.prototype._init = function () { GameManager.prototype._init = function () {
var _this = this, var _this = this, canvas, hemi_north, hemi_south, camera, cam_radius,
canvas, hemi_north, hemi_south, camera, cam_radius, on3DmodelsReady; on3DmodelsReady, map_size = 900; //GAMEPARAMETERS.map.map_size
canvas = this._canvas; canvas = this._canvas;
this._delayed_defer_list = []; this._delayed_defer_list = [];
this._dispose(); this._dispose();
...@@ -1111,7 +1118,6 @@ var GameManager = /** @class */ (function () { ...@@ -1111,7 +1118,6 @@ var GameManager = /** @class */ (function () {
); );
hemi_south.intensity = 0.75; hemi_south.intensity = 0.75;
//HARDCODE camera to a hardcoded map_size //HARDCODE camera to a hardcoded map_size
var map_size = 900; //GAMEPARAMETERS.map.map_size
//skybox scene limit //skybox scene limit
cam_radius = (map_size * 1.10 < 6000) ? map_size * 1.10 : 6000; cam_radius = (map_size * 1.10 < 6000) ? map_size * 1.10 : 6000;
camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, cam_radius, camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, cam_radius,
...@@ -1146,7 +1152,7 @@ var GameManager = /** @class */ (function () { ...@@ -1146,7 +1152,7 @@ var GameManager = /** @class */ (function () {
DroneManager.Prefab.isVisible = false; DroneManager.Prefab.isVisible = false;
//Hack to make advanced texture work //Hack to make advanced texture work
var documentTmp = document, advancedTexture, count, var documentTmp = document, advancedTexture, count,
controlMesh, rect, label; controlMesh, rect;
document = undefined; document = undefined;
advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI( advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI(
"UI", "UI",
...@@ -1287,7 +1293,7 @@ var GameManager = /** @class */ (function () { ...@@ -1287,7 +1293,7 @@ var GameManager = /** @class */ (function () {
GameManager.prototype._spawnDrones = function (init_position, drone_list, GameManager.prototype._spawnDrones = function (init_position, drone_list,
team, ctx, drone_location) { team, ctx, drone_location) {
var position, i, position_list = [], max_collision = 10 * drone_list.length, var position, i, position_list = [], max_collision = 10 * drone_list.length,
collision_nb = 0, api, center; collision_nb = 0, api, center, id_offset;
function checkCollision(position, list) { function checkCollision(position, list) {
var el; var el;
for (el = 0; el < list.length; el += 1) { for (el = 0; el < list.length; el += 1) {
...@@ -1363,10 +1369,7 @@ var GameManager = /** @class */ (function () { ...@@ -1363,10 +1369,7 @@ var GameManager = /** @class */ (function () {
} }
} else { } else {
position_list.push(position); position_list.push(position);
var id_offset = 0; id_offset = team === TEAM_ENEMY ? GAMEPARAMETERS.drone.list.length : 0;
if (team == TEAM_ENEMY) {
id_offset = GAMEPARAMETERS.drone.list.length;
}
api = new this.APIs_dict[drone_list[i].type]( api = new this.APIs_dict[drone_list[i].type](
this, this,
drone_list[i], drone_list[i],
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.48183.45277.7697</string> </value> <value> <string>1014.56745.33504.26197</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709113192.28</float> <float>1709223446.72</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -340,6 +340,24 @@ ...@@ -340,6 +340,24 @@
<div class="line"></div> <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 --> <!-- setTargetCoordinates -->
<h4 class="item-name" id="setTargetCoordinates"><span>setTargetCoordinates</span><span>: void</span></h4> <h4 class="item-name" id="setTargetCoordinates"><span>setTargetCoordinates</span><span>: void</span></h4>
<p class="item-descr"> <p class="item-descr">
...@@ -439,9 +457,9 @@ ...@@ -439,9 +457,9 @@
<div class="line"></div> <div class="line"></div>
<!-- triggerParachute --> <!-- land -->
<h4 class="item-name" id="triggerParachute"><span>triggerParachute</span><span>: void</span></h4> <h4 class="item-name" id="land"><span>land</span><span>: void</span></h4>
<p class="item-descr">Indicates the drone to deploy the parachute to finish the landing.</p> <p class="item-descr">Indicates the drone to trigger landing.</p>
<div> <div>
<h5 class="item-param-1">Param</h5> <h5 class="item-param-1">Param</h5>
...@@ -452,23 +470,33 @@ ...@@ -452,23 +470,33 @@
<h5 class="item-param-1">Example</h5> <h5 class="item-param-1">Example</h5>
</div> </div>
<p class="item-param-1">me.triggerParachute();<br> <p class="item-param-1">me.land();<br>
</p> </p>
<div class="line"></div> <div class="line"></div>
<!-- landed --> <!-- isReadyToFly -->
<h4 class="item-name" id="landed"><span>landed</span><span>: boolean</span></h4> <h4 class="item-name" id="isReadyToFly"><span>isReadyToFly</span><span>: void</span></h4>
<p class="item-descr">Indicates if the drone has landed (reached the floor altitude).</p> <p class="item-descr">Check if drone takeoff is finished.</p>
<div> <div>
<h5 class="item-param-1">Example</h5> <h5 class="item-param-1">Example</h5>
</div> </div>
<p class="item-example"> <p class="item-param-1">me.isReadyToFly();<br>
if (me.landed()) {<br> </p>
&nbsp;&nbsp;//do something<br>
}<br> <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> </p>
<div class="line"></div> <div class="line"></div>
...@@ -501,15 +529,15 @@ ...@@ -501,15 +529,15 @@
<div class="line"></div> <div class="line"></div>
<!-- getAirSpeed --> <!-- getSpeed -->
<h4 class="item-name" id="getAirSpeed"><span>getAirSpeed</span><span>: Float</span></h4> <h4 class="item-name" id="getSpeed"><span>getSpeed</span><span>: Float</span></h4>
<p class="item-descr">Get drone air speed in meters/second.</p> <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> <div>
<h5 class="item-param-1">Example</h5> <h5 class="item-param-1">Example</h5>
</div> </div>
<p class="item-param-1">me.getAirSpeed();<br> <p class="item-param-1">me.getSpeed();<br>
</p> </p>
<div class="line"></div> <div class="line"></div>
...@@ -553,19 +581,6 @@ ...@@ -553,19 +581,6 @@
<div class="line"></div> <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> <h3>Drone properties</h3>
<div class="line"></div> <div class="line"></div>
......
...@@ -244,7 +244,7 @@ ...@@ -244,7 +244,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.45296.39536.30276</string> </value> <value> <string>1014.46767.47211.3123</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -264,7 +264,7 @@ ...@@ -264,7 +264,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1708536065.15</float> <float>1708688564.0</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.55204.2137.9676</string> </value> <value> <string>1014.46368.9372.48435</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709130500.2</float> <float>1708616910.25</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
'}\n' + '}\n' +
'\n' + '\n' +
'me.onStart = function () {\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' + ' assert(me.getYaw(), 0, "Yaw angle")\n' +
' me.initialPosition = me.getCurrentPosition();\n' + ' me.initialPosition = me.getCurrentPosition();\n' +
' me.setTargetCoordinates(\n' + ' me.setTargetCoordinates(\n' +
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
' me.getCurrentPosition().longitude\n' + ' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\n' + ' ).toFixed(8),\n' +
' time_interval = 1000 / 60,\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(timestamp, Math.floor(time_interval), "Timestamp");\n' +
' assert(realDistance, expectedDistance, "Distance");\n' + ' assert(realDistance, expectedDistance, "Distance");\n' +
' current_position.latitude = current_position.latitude.toFixed(7);\n' + ' current_position.latitude = current_position.latitude.toFixed(7);\n' +
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
' longitude: me.initialPosition.longitude,\n' + ' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' + ' altitude: me.initialPosition.altitude\n' +
' });\n' + ' });\n' +
' me.exit(me.triggerParachute());\n' + ' me.exit(me.land());\n' +
'};', '};',
DRAW = true, DRAW = true,
LOG = true, LOG = true,
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.55202.48917.18107</string> </value> <value> <string>1014.55287.25371.8430</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709130419.7</float> <float>1709136147.57</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -207,11 +207,8 @@ var DroneLogAPI = /** @class */ (function () { ...@@ -207,11 +207,8 @@ var DroneLogAPI = /** @class */ (function () {
DroneLogAPI.prototype.getFlightParameters = function () { DroneLogAPI.prototype.getFlightParameters = function () {
return this._flight_parameters; return this._flight_parameters;
}; };
DroneLogAPI.prototype.exit = function (drone) { DroneLogAPI.prototype.isReadyToFly = function () {
return; return true;
};
DroneLogAPI.prototype.set_loiter_mode = function (loiter) {
return;
}; };
return DroneLogAPI; return DroneLogAPI;
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1011.48679.53693.47701</string> </value> <value> <string>1014.12050.13065.34372</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1697030760.48</float> <float>1706542267.28</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -30,6 +30,8 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -30,6 +30,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
this._loiter_radius = 100; this._loiter_radius = 100;
//this._start_altitude = 0; //this._start_altitude = 0;
this._loiter_mode = false; this._loiter_mode = false;
this._is_landing = false;
this._is_ready_to_fly = true;
this._drone_dict_list = []; this._drone_dict_list = [];
} }
Object.defineProperty(FixedWingDroneAPI.prototype, "isCollidable", { Object.defineProperty(FixedWingDroneAPI.prototype, "isCollidable", {
...@@ -90,45 +92,15 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -90,45 +92,15 @@ var FixedWingDroneAPI = /** @class */ (function () {
if (drone._maxClimbRate > drone._maxSpeed) { if (drone._maxClimbRate > drone._maxSpeed) {
throw new Error('max climb rate cannot be superior to max speed'); throw new Error('max climb rate cannot be superior to max speed');
} }
drone._maxOrientation = this.getMaxOrientation();
return; return;
}; };
/* /*
** Function called on every drone update, right before onUpdate AI script ** Function called on every drone update, right before onUpdate AI script
*/ */
FixedWingDroneAPI.prototype.internal_update = function (context, delta_time) { 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._updateSpeed(context, delta_time);
this._updatePosition(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._controlMesh.computeWorldMatrix(true);
context._mesh.computeWorldMatrix(true); context._mesh.computeWorldMatrix(true);
}; };
...@@ -148,7 +120,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -148,7 +120,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
'latitude' : drone_position.latitude, 'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude, 'longitude' : drone_position.longitude,
'yaw': drone.getYaw(), 'yaw': drone.getYaw(),
'speed': drone.getAirSpeed(), 'speed': drone.getSpeed(),
'climbRate': drone.getClimbRate() 'climbRate': drone.getClimbRate()
}; };
_this._drone_dict_list[_this._id] = drone_info; _this._drone_dict_list[_this._id] = drone_info;
...@@ -162,7 +134,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -162,7 +134,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
}; };
FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) { FixedWingDroneAPI.prototype._updateSpeed = function (drone, delta_time) {
var speed = drone.getAirSpeed(), speedDiff, speedUpdate; var speed = drone.get3DSpeed(), speedDiff, speedUpdate;
if (speed !== this._targetSpeed) { if (speed !== this._targetSpeed) {
speedDiff = this._targetSpeed - speed; speedDiff = this._targetSpeed - speed;
speedUpdate = drone._acceleration * delta_time / 1000; speedUpdate = drone._acceleration * delta_time / 1000;
...@@ -235,7 +207,7 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -235,7 +207,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._getVerticalSpeed(drone); verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt( 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; distance = (groundSpeed * delta_time / 1000) / R;
...@@ -297,39 +269,27 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -297,39 +269,27 @@ var FixedWingDroneAPI = /** @class */ (function () {
verticalSpeed = this._computeVerticalSpeed( verticalSpeed = this._computeVerticalSpeed(
altitudeDiff, altitudeDiff,
this.getMaxClimbRate(), this.getMaxClimbRate(),
drone.getAirSpeed(), drone.get3DSpeed(),
this.getMaxPitchAngle() this.getMaxPitchAngle()
); );
} else { } else {
verticalSpeed = -this._computeVerticalSpeed( verticalSpeed = -this._computeVerticalSpeed(
Math.abs(altitudeDiff), Math.abs(altitudeDiff),
this.getMaxSinkRate(), this.getMaxSinkRate(),
drone.getAirSpeed(), drone.get3DSpeed(),
-this.getMinPitchAngle() -this.getMinPitchAngle()
); );
} }
return verticalSpeed; 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) { FixedWingDroneAPI.prototype.setSpeed = function (drone, speed) {
this._targetSpeed = Math.max( this._targetSpeed = Math.max(
Math.min(speed, this.getMaxSpeed()), Math.min(speed, this.getMaxSpeed()),
this.getMinSpeed() this.getMinSpeed()
); );
drone._acceleration = (this._targetSpeed > drone.getAirSpeed()) drone._acceleration = (this._targetSpeed > drone.get3DSpeed())
? this.getMaxAcceleration() : -this.getMaxDeceleration(); ? this.getMaxAcceleration() : -this.getMaxDeceleration();
}; };
...@@ -448,14 +408,10 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -448,14 +408,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
FixedWingDroneAPI.prototype.getMaxClimbRate = function () { FixedWingDroneAPI.prototype.getMaxClimbRate = function () {
return this._flight_parameters.drone.maxClimbRate; 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) { FixedWingDroneAPI.prototype.getYawVelocity = function (drone) {
return 360 * EARTH_GRAVITY return 360 * EARTH_GRAVITY
* Math.tan(this._toRad(this.getMaxRollAngle())) * Math.tan(this._toRad(this.getMaxRollAngle()))
/ (2 * Math.PI * drone.getAirSpeed()); / (2 * Math.PI * drone.get3DSpeed());
}; };
FixedWingDroneAPI.prototype.getYaw = function (drone) { FixedWingDroneAPI.prototype.getYaw = function (drone) {
var direction = drone.worldDirection; var direction = drone.worldDirection;
...@@ -492,30 +448,34 @@ var FixedWingDroneAPI = /** @class */ (function () { ...@@ -492,30 +448,34 @@ var FixedWingDroneAPI = /** @class */ (function () {
return angle * 180 / Math.PI; return angle * 180 / Math.PI;
}; };
FixedWingDroneAPI.prototype.getClimbRate = function (drone) { 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; var direction = drone.worldDirection;
return Math.sqrt( return Math.sqrt(
Math.pow(direction.x * drone.getAirSpeed(), 2) Math.pow(direction.x * drone.get3DSpeed(), 2)
+ Math.pow(direction.z * drone.getAirSpeed(), 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(); var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates( drone.setTargetCoordinates(
drone_pos.latitude, drone_pos.latitude,
drone_pos.longitude, drone_pos.longitude,
5, 0,
drone.getAirSpeed() drone.get3DSpeed()
); );
this._is_ready_to_fly = false;
this._is_landing = true;
}; };
FixedWingDroneAPI.prototype.landed = function (drone) { FixedWingDroneAPI.prototype.isReadyToFly = function () {
var drone_pos = drone.getCurrentPosition(); return this._is_ready_to_fly;
return Math.floor(drone_pos.altitude) < 10;
}; };
FixedWingDroneAPI.prototype.exit = function () { FixedWingDroneAPI.prototype.isLanding = function () {
return; return this._is_landing;
}; };
FixedWingDroneAPI.prototype.getInitialAltitude = function () { FixedWingDroneAPI.prototype.getInitialAltitude = function () {
return this._map_dict.start_AMSL; return this._map_dict.start_AMSL;
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.11751.44914.51968</string> </value> <value> <string>1014.12067.27492.45397</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1706523358.41</float> <float>1706542739.07</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -25,11 +25,9 @@ var DroneManager = /** @class */ (function () { ...@@ -25,11 +25,9 @@ var DroneManager = /** @class */ (function () {
this._maxRollAngle = 0; this._maxRollAngle = 0;
this._maxSinkRate = 0; this._maxSinkRate = 0;
this._maxClimbRate = 0; this._maxClimbRate = 0;
this._maxOrientation = 0;
this._speed = 0; this._speed = 0;
this._acceleration = 0; this._acceleration = 0;
this._direction = new BABYLON.Vector3(0, 0, 1); // North this._direction = new BABYLON.Vector3(0, 0, 1); // North
this._rotationSpeed = 0.4;
this._scene = scene; this._scene = scene;
this._canUpdate = true; this._canUpdate = true;
this._id = id; this._id = id;
...@@ -141,7 +139,7 @@ var DroneManager = /** @class */ (function () { ...@@ -141,7 +139,7 @@ var DroneManager = /** @class */ (function () {
}; };
DroneManager.prototype._internal_setTargetCoordinates = DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) { function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay) { if (!this._canPlay || !this.isReadyToFly()) {
return; return;
} }
//convert real geo-coordinates to virtual x-y coordinates //convert real geo-coordinates to virtual x-y coordinates
...@@ -209,20 +207,6 @@ var DroneManager = /** @class */ (function () { ...@@ -209,20 +207,6 @@ var DroneManager = /** @class */ (function () {
this._direction = new BABYLON.Vector3(x, z, y).normalize(); 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 * Send a message to drones
* @param msg The message to send * @param msg The message to send
...@@ -309,27 +293,29 @@ var DroneManager = /** @class */ (function () { ...@@ -309,27 +293,29 @@ var DroneManager = /** @class */ (function () {
DroneManager.prototype.getYaw = function () { DroneManager.prototype.getYaw = function () {
return this._API.getYaw(this); return this._API.getYaw(this);
}; };
DroneManager.prototype.getAirSpeed = function () { DroneManager.prototype.get3DSpeed = function () {
return this._speed; return this._speed;
}; };
DroneManager.prototype.getGroundSpeed = function () { DroneManager.prototype.getSpeed = function () {
return this._API.getGroundSpeed(this); return this._API.getSpeed(this);
}; };
DroneManager.prototype.getClimbRate = function () { DroneManager.prototype.getClimbRate = function () {
return this._API.getClimbRate(this); return this._API.getClimbRate(this);
}; };
DroneManager.prototype.getSinkRate = function () { DroneManager.prototype.takeOff = function () {
return this._API.getSinkRate(); return this._API.takeOff();
}; };
DroneManager.prototype.triggerParachute = function () { DroneManager.prototype.land = function () {
return this._API.triggerParachute(this); return this._API.land(this);
}; };
DroneManager.prototype.exit = function () { DroneManager.prototype.exit = function () {
this._internal_crash(); return this._internal_crash();
return this._API.exit();
}; };
DroneManager.prototype.landed = function () { DroneManager.prototype.isReadyToFly = function () {
return this._API.landed(this); return this._API.isReadyToFly();
};
DroneManager.prototype.isLanding = function () {
return this._API.isLanding();
}; };
/** /**
* Set the drone last checkpoint reached * Set the drone last checkpoint reached
...@@ -347,7 +333,7 @@ var DroneManager = /** @class */ (function () { ...@@ -347,7 +333,7 @@ var DroneManager = /** @class */ (function () {
* Function called on game update * Function called on game update
* @param timestamp The tic value * @param timestamp The tic value
*/ */
DroneManager.prototype.onUpdate = function () { return; }; DroneManager.prototype.onUpdate = function (timestamp) { return; };
/** /**
* Function called when drone crashes * Function called when drone crashes
*/ */
...@@ -668,8 +654,12 @@ var GameManager = /** @class */ (function () { ...@@ -668,8 +654,12 @@ var GameManager = /** @class */ (function () {
drone._tick += 1; drone._tick += 1;
if (drone._API.isCollidable && drone.can_play) { if (drone._API.isCollidable && drone.can_play) {
if (drone.getCurrentPosition().altitude <= 0) { if (drone.getCurrentPosition().altitude <= 0) {
drone._internal_crash(new Error('Drone ' + drone.id + if (!drone.isLanding()) {
' touched the floor.')); drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.'));
} else {
drone._internal_crash();
}
} else { } else {
_this._droneList.forEach(function (other) { _this._droneList.forEach(function (other) {
if (other.can_play && drone.id !== other.id) { if (other.can_play && drone.id !== other.id) {
...@@ -722,7 +712,7 @@ var GameManager = /** @class */ (function () { ...@@ -722,7 +712,7 @@ var GameManager = /** @class */ (function () {
game_manager._game_duration, geo_coordinates.latitude, game_manager._game_duration, geo_coordinates.latitude,
geo_coordinates.longitude, geo_coordinates.longitude,
map_info.start_AMSL + drone_position.z, map_info.start_AMSL + drone_position.z,
drone_position.z, drone.getYaw(), drone.getGroundSpeed(), drone_position.z, drone.getYaw(), drone.getSpeed(),
drone.getClimbRate() drone.getClimbRate()
]); ]);
} }
......
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.11746.34243.61149</string> </value> <value> <string>1014.12072.47950.5358</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1706523386.8</float> <float>1706542965.82</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.54902.15254.29337</string> </value> <value> <string>1014.11755.64575.41864</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709130323.68</float> <float>1706525997.75</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
'}\n' + '}\n' +
'\n' + '\n' +
'me.onStart = function () {\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' + ' assert(me.getYaw(), 0, "Yaw angle")\n' +
' me.initialPosition = me.getCurrentPosition();\n' + ' me.initialPosition = me.getCurrentPosition();\n' +
' me.setTargetCoordinates(\n' + ' me.setTargetCoordinates(\n' +
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
' me.getCurrentPosition().latitude,\n' + ' me.getCurrentPosition().latitude,\n' +
' me.getCurrentPosition().longitude\n' + ' me.getCurrentPosition().longitude\n' +
' ).toFixed(8),\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(timestamp, 1000 / 60, "Timestamp");\n' +
' assert(realDistance, expectedDistance, "Distance");\n' + ' assert(realDistance, expectedDistance, "Distance");\n' +
' current_position.latitude = current_position.latitude.toFixed(7);\n' + ' current_position.latitude = current_position.latitude.toFixed(7);\n' +
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
' longitude: me.initialPosition.longitude,\n' + ' longitude: me.initialPosition.longitude,\n' +
' altitude: me.initialPosition.altitude\n' + ' altitude: me.initialPosition.altitude\n' +
' });\n' + ' });\n' +
' me.exit(me.triggerParachute());\n' + ' me.exit(me.land());\n' +
'};', '};',
DRAW = true, DRAW = true,
LOG = true, LOG = true,
......
...@@ -246,7 +246,7 @@ ...@@ -246,7 +246,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>1014.55202.15664.53026</string> </value> <value> <string>1014.55287.25371.8430</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -266,7 +266,7 @@ ...@@ -266,7 +266,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1709130383.65</float> <float>1709136309.62</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </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