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

erp5_officejs_drone_simulator: refactor x-y-z / lat-lon-alt method/properies to be consistent

parent 3dd0da8e
......@@ -199,9 +199,9 @@ var DroneLogAPI = /** @class */ (function () {
DroneLogAPI.prototype.getCurrentPosition = function (x, y, z) {
return {
x: x,
y: y,
z: z
latitude: x,
longitude: y,
altitude: z
};
};
DroneLogAPI.prototype.getFlightParameters = function () {
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.13501.40623.51950</string> </value>
<value> <string>1011.48679.53693.47701</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1691588429.76</float>
<float>1697030760.48</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -142,11 +142,11 @@ var FixedWingDroneAPI = /** @class */ (function () {
}*/
if (drone_position) {
drone_info = {
'altitudeRel' : drone_position.z,
'altitudeRel' : drone_position.altitude,
'altitudeAbs' : _this._mapManager.getMapInfo().start_AMSL +
drone_position.z,
'latitude' : drone_position.x,
'longitude' : drone_position.y,
drone_position.altitude,
'latitude' : drone_position.latitude,
'longitude' : drone_position.longitude,
'yaw': drone.getYaw(),
'speed': drone.getAirSpeed(),
'climbRate': drone.getClimbRate()
......@@ -188,10 +188,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
drone._targetCoordinates.z
),
bearing = this._computeBearing(
currentGeoCoordinates.x,
currentGeoCoordinates.y,
targetCoordinates.x,
targetCoordinates.y
currentGeoCoordinates.latitude,
currentGeoCoordinates.longitude,
targetCoordinates.latitude,
targetCoordinates.longitude
),
currentCosLat,
currentLatRad,
......@@ -228,10 +228,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
}
newYawRad = this._toRad(newYaw);
currentLatRad = this._toRad(currentGeoCoordinates.x);
currentLatRad = this._toRad(currentGeoCoordinates.latitude);
currentCosLat = Math.cos(currentLatRad);
currentSinLat = Math.sin(currentLatRad);
currentLonRad = this._toRad(currentGeoCoordinates.y);
currentLonRad = this._toRad(currentGeoCoordinates.longitude);
verticalSpeed = this._getVerticalSpeed(drone);
groundSpeed = Math.sqrt(
......@@ -502,11 +502,11 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI.prototype.triggerParachute = function (drone) {
var drone_pos = drone.getCurrentPosition();
drone.setTargetCoordinates(drone_pos.x, drone_pos.y, 5);
drone.setTargetCoordinates(drone_pos.latitude, drone_pos.longitude, 5);
};
FixedWingDroneAPI.prototype.landed = function (drone) {
var drone_pos = drone.getCurrentPosition();
return Math.floor(drone_pos.z) < 10;
return Math.floor(drone_pos.altitude) < 10;
};
FixedWingDroneAPI.prototype.exit = function () {
return;
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.43751.23980.5597</string> </value>
<value> <string>1011.48679.53693.47701</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1692888030.77</float>
<float>1697030763.04</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -135,16 +135,18 @@ var DroneManager = /** @class */ (function () {
/**
* Set a target point to move
*/
DroneManager.prototype.setTargetCoordinates = function (x, y, z) {
this._internal_setTargetCoordinates(x, y, z);
DroneManager.prototype.setTargetCoordinates =
function (latitude, longitude, altitude) {
this._internal_setTargetCoordinates(latitude, longitude, altitude);
};
DroneManager.prototype._internal_setTargetCoordinates =
function (x, y, z, radius) {
function (latitude, longitude, altitude, radius) {
if (!this._canPlay) {
return;
}
//convert real geo-coordinates to virtual x-y coordinates
this._targetCoordinates = this._API.processCoordinates(x, y, z);
this._targetCoordinates =
this._API.processCoordinates(latitude, longitude, altitude);
return this._API.internal_setTargetCoordinates(
this,
this._targetCoordinates,
......@@ -296,8 +298,14 @@ var DroneManager = /** @class */ (function () {
/**
* Make the drone loiter (circle with a set radius)
*/
DroneManager.prototype.loiter = function (x, y, z, radius) {
this._internal_setTargetCoordinates(x, y, z, radius);
DroneManager.prototype.loiter =
function (latitude, longitude, altitude, radius) {
this._internal_setTargetCoordinates(
latitude,
longitude,
altitude,
radius
);
};
DroneManager.prototype.getFlightParameters = function () {
if (this._API.getFlightParameters) {
......@@ -436,7 +444,7 @@ var MapManager = /** @class */ (function () {
this.map_info.initial_position = this.convertToLocalCoordinates(
initial_position.latitude,
initial_position.longitude,
initial_position.z
initial_position.altitude
);
};
MapManager.prototype.getMapInfo = function () {
......@@ -485,9 +493,9 @@ var MapManager = /** @class */ (function () {
this.map_info.min_y;
lat = 90 - lat / (this.map_info.map_size / 180.0);
return {
x: lat,
y: lon,
z: z
latitude: lat,
longitude: lon,
altitude: z
};
};
return MapManager;
......@@ -666,7 +674,7 @@ var GameManager = /** @class */ (function () {
queue.push(function () {
drone._tick += 1;
if (drone._API.isCollidable && drone.can_play) {
if (drone.getCurrentPosition().z <= 0) {
if (drone.getCurrentPosition().altitude <= 0) {
drone._internal_crash(new Error('Drone ' + drone.id +
' touched the floor.'));
} else {
......@@ -718,8 +726,9 @@ var GameManager = /** @class */ (function () {
drone_position.z
);
game_manager._flight_log[index].push([
game_manager._game_duration, geo_coordinates.x,
geo_coordinates.y, map_info.start_AMSL + drone_position.z,
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.getClimbRate()
]);
......@@ -1013,6 +1022,7 @@ var GameManager = /** @class */ (function () {
try {
eval(code_eval);
} catch (error) {
console.error(error);
eval(base);
}
/*jslint evil: false*/
......
......@@ -240,7 +240,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1010.42341.16308.11025</string> </value>
<value> <string>1011.48744.22696.33177</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1692802878.6</float>
<float>1697032866.09</float>
<string>UTC</string>
</tuple>
</state>
......
(function (window, RSVP, rJS, domsugar, document, Blob) {
/*jslint indent: 2, maxlen: 100*/
/*global window, rJS, domsugar, document*/
(function (window, rJS, domsugar, document) {
"use strict";
var SIMULATION_SPEED = 200,
......@@ -40,7 +42,7 @@
})
.declareMethod('render', function render() {
var gadget = this, query;
var gadget = this;
return gadget.getDeclaredGadget('form_view')
.push(function (form_gadget) {
return form_gadget.render({
......@@ -90,7 +92,7 @@
group_list: [[
"left",
[["my_log_1"], ["my_simulation_speed"]]
],[
], [
"right",
[["my_log_2"]]
]]
......@@ -106,7 +108,9 @@
})
.declareJob('runGame', function runGame(options) {
var gadget = this, simulator, log_1_entry_list, log_2_entry_list;
var gadget = this, dist, fragment = gadget.element.querySelector('.simulator_div'),
game_parameters_json, log_1_entry_list, log_2_entry_list, map_info,
span = document.querySelector('#distance');
function latLonDistance(c1, c2) {
var R = 6371e3,
q1 = c1[0] * Math.PI / 180,
......@@ -123,21 +127,18 @@
var i, line_list = log.split('\n'), log_entry_list = [], log_entry,
log_header_found;
for (i = 0; i < line_list.length; i += 1) {
if (!log_header_found && !line_list[i].includes("timestamp (ms);")) {
continue;
} else {
if (log_header_found || line_list[i].includes("timestamp (ms);")) {
log_header_found = true;
}
if (line_list[i].indexOf("AMSL") >= 0 ||
!line_list[i].includes(";")) {
continue;
}
if (line_list[i].indexOf("AMSL") < 0 &&
line_list[i].includes(";")) {
log_entry = line_list[i].trim();
if (log_entry) {
log_entry = log_entry.split(';');
log_entry_list.push(log_entry);
}
}
}
}
return log_entry_list;
}
function averageLogDistance(a, b, z) {
......@@ -146,15 +147,15 @@
Math.pow(p1[1] - p2[1], 2) +
Math.pow(p1[2] - p2[2], 2));
}
var i, sum = 0, point_a, point_b, penalization = 0, length;
for (i = 0; i < a.length; i++) {
var d, i, sum = 0, point_a, point_b, penalization = 0, length;
for (i = 0; i < a.length; i += 1) {
if (b[i]) {
point_a = [a[i][1], a[i][1]];
point_b = [b[i][1], b[i][1]];
if (z) {
sum += distance3D(point_a, point_b);
} else {
var d = latLonDistance(point_a, point_b);
d = latLonDistance(point_a, point_b);
sum += d;
}
}
......@@ -168,14 +169,12 @@
}
log_1_entry_list = getLogEntries(options.log_1);
log_2_entry_list = getLogEntries(options.log_2);
var span = document.querySelector('#distance'),
dist = averageLogDistance(log_1_entry_list, log_2_entry_list, false);
if (isNaN(dist)) {
return gadget.notifySubmitted({message: 'Invalid log content', status: 'error'});
}
span.textContent = 'Average flights distance: ' +
Math.round(dist * 100) / 100;
var fragment = gadget.element.querySelector('.simulator_div');
fragment = domsugar(gadget.element.querySelector('.simulator_div'),
[domsugar('div')]).firstElementChild;
DRONE_LIST[0].log_content = options.log_1;
......@@ -184,11 +183,19 @@
var all = list_1.concat(list_2), i,
min_lat = 999, min_lon = 999,
max_lat = 0, max_lon = 0;
for (i = 0; i < all.length; i+=1) {
if (all[i][1] < min_lat) min_lat = all[i][1];
if (all[i][1] > max_lat) max_lat = all[i][1];
if (all[i][2] < min_lon) min_lon = all[i][2];
if (all[i][2] > max_lon) max_lon = all[i][2];
for (i = 0; i < all.length; i += 1) {
if (all[i][1] < min_lat) {
min_lat = all[i][1];
}
if (all[i][1] > max_lat) {
max_lat = all[i][1];
}
if (all[i][2] < min_lon) {
min_lon = all[i][2];
}
if (all[i][2] > max_lon) {
max_lon = all[i][2];
}
}
return {
"min_lat": min_lat,
......@@ -198,10 +205,10 @@
"start_AMSL": all[0][3] - all[0][4],
"init_pos_lat": all[0][1],
"init_pos_lon": all[0][2],
"init_pos_z": all[0][4]
"init_pos_alt": all[0][4]
};
}
var map_info = generateMapInfo(log_1_entry_list, log_2_entry_list);
map_info = generateMapInfo(log_1_entry_list, log_2_entry_list);
options.min_lat = map_info.min_lat;
options.max_lat = map_info.max_lat;
options.min_lon = map_info.min_lon;
......@@ -210,8 +217,8 @@
options.start_AMSL = map_info.start_AMSL;
options.init_pos_lon = map_info.init_pos_lon;
options.init_pos_lat = map_info.init_pos_lat;
options.init_pos_z = map_info.init_pos_z;
var game_parameters_json = {
options.init_pos_alt = map_info.init_pos_alt;
game_parameters_json = {
"drone": {
"maxAcceleration": 1,
"maxSpeed": 1
......@@ -233,7 +240,7 @@
"initialPosition": {
"longitude": parseFloat(options.init_pos_lon),
"latitude": parseFloat(options.init_pos_lat),
"z": parseFloat(options.init_pos_z)
"altitude": parseFloat(options.init_pos_alt)
},
"draw_flight_path": DRAW,
"log_drone_flight": LOG,
......@@ -288,4 +295,4 @@
});
});
}(window, RSVP, rJS, domsugar, document, Blob));
\ No newline at end of file
}(window, rJS, domsugar, document));
\ No newline at end of file
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
<value> <unicode>zope</unicode> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1006.43898.62059.64102</string> </value>
<value> <string>1011.48769.44767.36898</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1677600140.0</float>
<float>1697034365.81</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -25,7 +25,7 @@
INITIAL_POSITION = {
"latitude": 45.6412,
"longitude": 14.2658,
"z": 15
"altitude": 15
},
NUMBER_OF_DRONES = 2,
// Non-inputs parameters
......@@ -108,8 +108,8 @@
' if (me.next_checkpoint < CHECKPOINT_LIST.length) {\n' +
' me.current_position = me.getCurrentPosition();\n' +
' me.distance = distance(\n' +
' me.current_position.x,\n' +
' me.current_position.y,\n' +
' me.current_position.latitude,\n' +
' me.current_position.longitude,\n' +
' CHECKPOINT_LIST[me.next_checkpoint].latitude,\n' +
' CHECKPOINT_LIST[me.next_checkpoint].longitude\n' +
' );\n' +
......@@ -387,14 +387,14 @@
"hidden": 0,
"type": "FloatField"
},
"my_init_pos_z": {
"my_init_pos_alt": {
"description": "",
"title": "Initial drone position Z",
"default": INITIAL_POSITION.z,
"title": "Initial drone altitude",
"default": INITIAL_POSITION.altitude,
"css_class": "",
"required": 1,
"editable": 1,
"key": "init_pos_z",
"key": "init_pos_alt",
"hidden": 0,
"type": "FloatField"
},
......@@ -434,7 +434,7 @@
[["my_simulation_speed"], ["my_simulation_time"], ["my_number_of_drones"],
["my_minimum_latitud"], ["my_maximum_latitud"],
["my_minimum_longitud"], ["my_maximum_longitud"],
["my_init_pos_lat"], ["my_init_pos_lon"], ["my_init_pos_z"],
["my_init_pos_lat"], ["my_init_pos_lon"], ["my_init_pos_alt"],
["my_map_height"]]
], [
"right",
......@@ -498,7 +498,7 @@
"initialPosition": {
"longitude": parseFloat(options.init_pos_lon),
"latitude": parseFloat(options.init_pos_lat),
"z": parseFloat(options.init_pos_z)
"altitude": parseFloat(options.init_pos_alt)
},
"draw_flight_path": DRAW,
"temp_flight_path": true,
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1009.59163.16294.47701</string> </value>
<value> <string>1011.48716.48246.13943</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1690477710.21</float>
<float>1697031250.03</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