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

erp5_officejs_drone_simulator: rename triggerParachute into land

Rename triggerParachute function into land in DroneManager for
compliance with multicopters APIs.
parent 760e47a9
......@@ -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;
......@@ -240,7 +212,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
newLatRad = Math.asin(
currentSinLat * distanceCos +
currentCosLat * distanceSin * Math.cos(newYawRad)
currentCosLat * distanceSin * Math.cos(newYawRad)
);
newLonRad = currentLonRad + Math.atan2(
Math.sin(newYawRad) * distanceSin * currentCosLat,
......@@ -256,10 +228,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
// swap y and z axis so z axis represents altitude
drone._controlMesh.position.addInPlace(new BABYLON.Vector3(
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,
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);
drone.setDirection(
......@@ -293,40 +265,28 @@ 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()) ?
this.getMaxAcceleration() : -this.getMaxDeceleration();
drone._acceleration = (this._targetSpeed > drone.get3DSpeed()) ?
this.getMaxAcceleration() : -this.getMaxDeceleration();
};
FixedWingDroneAPI.prototype.setStartingPosition = function (drone, x, y, z) {
......@@ -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;
......@@ -523,7 +479,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
var maxVerticalSpeed =
Math.min(altitude_diff, Math.min(max_climb_rate, speed));
return (this._toDeg(Math.asin(maxVerticalSpeed / speed)) > max_pitch) ?
speed * Math.sin(this._toRad(max_pitch))
speed * Math.sin(this._toRad(max_pitch))
: maxVerticalSpeed;
};
FixedWingDroneAPI.prototype._toRad = function (angle) {
......@@ -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>
......
......@@ -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;
......@@ -155,7 +153,7 @@ var DroneManager = /** @class */ (function () {
};
DroneManager.prototype._internal_setTargetCoordinates =
function (latitude, longitude, altitude, speed, radius) {
if (!this._canPlay) {
if (!this._canPlay || !this.isReadyToFly()) {
return;
}
//each drone API process coordinates on its needs
......@@ -208,14 +206,15 @@ var DroneManager = /** @class */ (function () {
}
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._canCommunicate = false;
this._controlMesh = null;
this._mesh = null;
this._canPlay = false;
if (error) {
this._API._gameManager.logError(this, error);
this._API._gameManager.logError(this, error, print_stack);
}
this.onTouched();
};
......@@ -236,20 +235,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
......@@ -342,41 +327,40 @@ var DroneManager = /** @class */ (function () {
return null;
};
DroneManager.prototype.getYaw = function () {
if (typeof this._API.getYaw !== "undefined") {
if (this._API.getYaw !== undefined) {
return this._API.getYaw(this);
}
return;
};
DroneManager.prototype.getAirSpeed = function () {
DroneManager.prototype.get3DSpeed = function () {
return this._speed;
};
DroneManager.prototype.getGroundSpeed = function () {
if (typeof this._API.getGroundSpeed !== "undefined") {
return this._API.getGroundSpeed(this);
DroneManager.prototype.getSpeed = function () {
if (this._API.getSpeed !== "undefined") {
return this._API.getSpeed(this);
}
return;
};
DroneManager.prototype.getClimbRate = function () {
if (typeof this._API.getClimbRate !== "undefined") {
if (this._API.getClimbRate !== "undefined") {
return this._API.getClimbRate(this);
}
return;
};
DroneManager.prototype.getSinkRate = function () {
if (typeof this._API.getSinkRate !== "undefined") {
return this._API.getSinkRate(this);
}
return;
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
......@@ -394,7 +378,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
*/
......@@ -442,7 +426,12 @@ var MapManager = /** @class */ (function () {
function MapManager(scene, map_param) {
var _this = this, max_sky, skybox, skyboxMat, largeGroundMat, flag_material,
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) {
// Use default map base parameters
map_param = MAP;
......@@ -453,7 +442,8 @@ var MapManager = /** @class */ (function () {
_this.map_info.initial_position = _this.mapUtils.convertToLocalCoordinates(
_this.map_info.initial_position.latitude,
_this.map_info.initial_position.longitude,
_this.map_info.initial_position.altitude);
_this.map_info.initial_position.altitude
);
max = _this.map_info.width;
if (_this.map_info.depth > max) {
max = _this.map_info.depth;
......@@ -504,7 +494,8 @@ var MapManager = /** @class */ (function () {
enemy.position = _this.mapUtils.convertToLocalCoordinates(
geo_enemy.position.latitude,
geo_enemy.position.longitude,
geo_enemy.position.altitude);
geo_enemy.position.altitude
);
_this._enemy_list.push(enemy);
});
// Obstacles
......@@ -515,7 +506,8 @@ var MapManager = /** @class */ (function () {
obstacle.position = _this.mapUtils.convertToLocalCoordinates(
geo_obstacle.position.latitude,
geo_obstacle.position.longitude,
geo_obstacle.position.altitude);
geo_obstacle.position.altitude
);
switch (obstacle.type) {
case "box":
new_obstacle = BABYLON.MeshBuilder.CreateBox("obs_" + count,
......@@ -539,41 +531,41 @@ var MapManager = /** @class */ (function () {
return;
}
new_obstacle.type = obstacle.type;
var convertion = Math.PI / 180;
if ("position" in obstacle)
var convertion = Math.PI / 180,
obs_material = new BABYLON.StandardMaterial("obsmat_" + count, scene);
if (obstacle.hasOwnProperty("position")) {
new_obstacle.position = new BABYLON.Vector3(obstacle.position.x,
obstacle.position.z,
obstacle.position.y);
if ("rotation" in obstacle)
}
if (obstacle.hasOwnProperty("rotation")) {
new_obstacle.rotation =
new BABYLON.Vector3(obstacle.rotation.x * convertion,
obstacle.rotation.z * convertion,
obstacle.rotation.y * convertion);
if ("scale" in obstacle)
}
if (obstacle.hasOwnProperty("scale")) {
new_obstacle.scaling = new BABYLON.Vector3(obstacle.scale.x,
obstacle.scale.z,
obstacle.scale.y);
var obs_material = new BABYLON.StandardMaterial("obsmat_" + count, scene);
}
obs_material.alpha = 1;
obs_material.diffuseColor = new BABYLON.Color3(255, 153, 0);
new_obstacle.material = obs_material;
_this._obstacle_list.push(new_obstacle);
count++;
count += 1;
});
// Flags
_this._flag_list = [];
var FLAG_SIZE = {
'x': 1,
'y': 1,
'z': 6
};
_this.map_info.flag_list.forEach(function (geo_flag, index) {
flag_info = {};
Object.assign(flag_info, geo_flag);
flag_info.position = _this.mapUtils.convertToLocalCoordinates(
geo_flag.position.latitude,
geo_flag.position.longitude,
geo_flag.position.altitude);
geo_flag.position.altitude
);
flag_material = new BABYLON.StandardMaterial("flag_mat_" + index, scene);
flag_material.alpha = 1;
flag_material.diffuseColor = BABYLON.Color3.Green();
......@@ -607,7 +599,8 @@ var MapManager = /** @class */ (function () {
mast.scaling = new BABYLON.Vector3(
FLAG_SIZE.x,
FLAG_SIZE.z, //swap
FLAG_SIZE.y);
FLAG_SIZE.y
);
mast.material = flag_material;
flag = BABYLON.Mesh.MergeMeshes([flag_a, flag_b, mast]);
flag.id = index;
......@@ -633,7 +626,10 @@ var MapManager = /** @class */ (function () {
MapManager.prototype.convertToLocalCoordinates =
function (latitude, longitude, altitude) {
return this.mapUtils.convertToLocalCoordinates(
latitude, longitude, altitude);
latitude,
longitude,
altitude
);
};
MapManager.prototype.convertToGeoCoordinates = function (x, y, z) {
return this.mapUtils.convertToGeoCoordinates(x, y, z);
......@@ -712,7 +708,7 @@ var GameManager = /** @class */ (function () {
console.log = function () {
baseLogFunction.apply(console, 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";
}
};
......@@ -753,13 +749,13 @@ var GameManager = /** @class */ (function () {
(0 < _this.waiting_update_count)) {
_this.ongoing_update_promise = _this._update(TIME_DELTA, fullscreen)
.push(function () {
_this.waiting_update_count -= 1;
_this.ongoing_update_promise = null;
triggerUpdateIfPossible();
}).push(undefined, function (error) {
console.log("ERROR on Game Manager update:", error);
_this.finish_deferred.reject.bind(_this.finish_deferred);
});
_this.waiting_update_count -= 1;
_this.ongoing_update_promise = null;
triggerUpdateIfPossible();
}).push(undefined, function (error) {
console.log("ERROR on Game Manager update:", error);
_this.finish_deferred.reject.bind(_this.finish_deferred);
});
}
}
try {
......@@ -775,9 +771,12 @@ var GameManager = /** @class */ (function () {
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
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 () {
};
GameManager.prototype._checkObstacleCollision = function (drone, obstacle) {
var closest = void 0, projected = BABYLON.Vector3.Zero();
if (drone.colliderMesh &&
drone.colliderMesh.intersectsMesh(obstacle, true)) {
drone.colliderMesh.intersectsMesh(obstacle, true)) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched an obstacle.'));
' touched an obstacle.'), false);
//Following workaround seems not needed with new babylonjs versions
/**
* Closest facet check is needed for sphere and cylinder,
......@@ -821,7 +819,9 @@ var GameManager = /** @class */ (function () {
};
GameManager.prototype._checkFlagCollision = function (drone, flag) {
if (drone.team == TEAM_ENEMY) return;
if (drone.team === TEAM_ENEMY) {
return;
}
function distance(a, b) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) +
Math.pow((a.z - b.z), 2));
......@@ -830,9 +830,9 @@ var GameManager = /** @class */ (function () {
//TODO epsilon distance is 15 because of fixed wing loiter flights
//there is not a proper collision
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 +
' touched flag ' + flag.id));
' touched flag ' + flag.id), false);
if (flag.weight > 0) {
flag.weight -= 1;
drone.score += flag.score; // move score to a global place? GM, MM?
......@@ -842,17 +842,19 @@ var GameManager = /** @class */ (function () {
};
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) {
return Math.sqrt(Math.pow((a.x - b.x), 2) + Math.pow((a.y - b.y), 2) +
Math.pow((a.z - b.z), 2));
}
if (drone.team != other.team) {
if (drone.team !== other.team) {
var enemy, prey;
if (drone.team == TEAM_ENEMY) {
if (drone.team === TEAM_ENEMY) {
enemy = drone;
prey = other;
} else if (other.team == TEAM_ENEMY) {
} else if (other.team === TEAM_ENEMY) {
enemy = other;
prey = drone;
}
......@@ -860,18 +862,18 @@ var GameManager = /** @class */ (function () {
if (distance(drone.position, other.position) <
enemy.getCollisionSector()) {
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 +
' bumped drone ' + prey.id + '.'));
' bumped drone ' + prey.id + '.'), false);
}
}
}
if (drone.colliderMesh && other.colliderMesh &&
drone.colliderMesh.intersectsMesh(other.colliderMesh, false)) {
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 +
' touched drone ' + other.id + '.'));
' touched drone ' + other.id + '.'), false);
}
};
......@@ -907,20 +909,21 @@ var GameManager = /** @class */ (function () {
this._droneList.forEach(function (drone) {
queue.push(function () {
var msg = '';
drone._tick += 1;
if (drone.can_play) {
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 +
' touched the floor.'));
}
else if (_this._checkDroneOut(drone)) {
drone._internal_crash(new Error('Drone ' + drone.id +
' out of limits.'));
}
else {
' out of limits.'), false);
} else {
_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);
}
});
......@@ -941,7 +944,9 @@ var GameManager = /** @class */ (function () {
if (_this._timeOut()) {
console.log("TIMEOUT!");
_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!";
return _this._finish();
......@@ -986,7 +991,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()
]);
}
......@@ -1052,7 +1057,9 @@ var GameManager = /** @class */ (function () {
if (drone.last_position) {
dist = Math.sqrt(Math.pow((drone.last_position.x - base.x), 2)
+ Math.pow((drone.last_position.y - base.y), 2));
if (dist < BASE_DISTANCE) score += 1;
if (dist < BASE_DISTANCE) {
score += 1;
}
}
});
return score;
......@@ -1072,8 +1079,8 @@ var GameManager = /** @class */ (function () {
};
GameManager.prototype._init = function () {
var _this = this,
canvas, hemi_north, hemi_south, camera, cam_radius, on3DmodelsReady;
var _this = this, canvas, hemi_north, hemi_south, camera, cam_radius,
on3DmodelsReady, map_size = 900; //GAMEPARAMETERS.map.map_size
canvas = this._canvas;
this._delayed_defer_list = [];
this._dispose();
......@@ -1111,7 +1118,6 @@ var GameManager = /** @class */ (function () {
);
hemi_south.intensity = 0.75;
//HARDCODE camera to a hardcoded map_size
var map_size = 900; //GAMEPARAMETERS.map.map_size
//skybox scene limit
cam_radius = (map_size * 1.10 < 6000) ? map_size * 1.10 : 6000;
camera = new BABYLON.ArcRotateCamera("camera", 0, 1.25, cam_radius,
......@@ -1146,7 +1152,7 @@ var GameManager = /** @class */ (function () {
DroneManager.Prefab.isVisible = false;
//Hack to make advanced texture work
var documentTmp = document, advancedTexture, count,
controlMesh, rect, label;
controlMesh, rect;
document = undefined;
advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateFullscreenUI(
"UI",
......@@ -1287,7 +1293,7 @@ var GameManager = /** @class */ (function () {
GameManager.prototype._spawnDrones = function (init_position, drone_list,
team, ctx, drone_location) {
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) {
var el;
for (el = 0; el < list.length; el += 1) {
......@@ -1363,10 +1369,7 @@ var GameManager = /** @class */ (function () {
}
} else {
position_list.push(position);
var id_offset = 0;
if (team == TEAM_ENEMY) {
id_offset = GAMEPARAMETERS.drone.list.length;
}
id_offset = team === TEAM_ENEMY ? GAMEPARAMETERS.drone.list.length : 0;
api = new this.APIs_dict[drone_list[i].type](
this,
drone_list[i],
......
......@@ -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) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.'));
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