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

erp5_officejs_drone_simulator: update script to not depend on initial coordinates

parent 65fe6abf
......@@ -620,7 +620,7 @@ var OperatorAPI = /** @class */ (function () {
"editable": 1,
"key": "drone_max_acceleration",
"hidden": 0,
"type": "IntegerField"
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
......@@ -846,7 +846,7 @@ var OperatorAPI = /** @class */ (function () {
}
game_parameters_json = {
"drone": {
"maxAcceleration": parseInt(gadget.state.drone_max_acceleration, 10),
"maxAcceleration": parseFloat(gadget.state.drone_max_acceleration),
"maxDeceleration": parseInt(gadget.state.drone_max_deceleration, 10),
"minSpeed": parseInt(gadget.state.drone_min_speed, 10),
"speed": parseFloat(gadget.state.drone_speed),
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1016.21921.52144.47906</string> </value>
<value> <string>1020.20542.569.24900</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1714738877.83</float>
<float>1730211735.44</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -31,100 +31,153 @@
NUMBER_OF_DRONES = 2,
// Non-inputs parameters
DEFAULT_SCRIPT_CONTENT =
'var ALTITUDE = 100,\n' +
' EPSILON = 9,\n' +
' CHECKPOINT_LIST = [\n' +
' {\n' +
' altitude: 585.1806861589965,\n' +
' latitude: 45.64492790560583,\n' +
' longitude: 14.25334942966329\n' +
' },\n' +
' {\n' +
' altitude: 589.8802607573035,\n' +
' latitude: 45.64316335436476,\n' +
' longitude: 14.26332880184475\n' +
' },\n' +
' {\n' +
' altitude: 608.6648153348965,\n' +
' latitude: 45.64911917196595,\n' +
' longitude: 14.26214792790128\n' +
' },\n' +
' {\n' +
' altitude: 606.1448368129072,\n' +
' latitude: 45.64122685351364,\n' +
' longitude: 14.26590493128597\n' +
' },\n' +
' {\n' +
' altitude: 630.0829598206344,\n' +
' latitude: 45.64543355564817,\n' +
' longitude: 14.27242391207985\n' +
' },\n' +
' {\n' +
' altitude: 616.1839898415284,\n' +
' latitude: 45.6372792927328,\n' +
' longitude: 14.27533492411138\n' +
' },\n' +
' {\n' +
' altitude: 598.0603137354178,\n' +
' latitude: 45.64061299543953,\n' +
' longitude: 14.26161958465814\n' +
' },\n' +
' {\n' +
' altitude: 607.1243119862851,\n' +
' latitude: 45.64032340702919,\n' +
' longitude: 14.2682896662383\n' +
'/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */\n' +
'/*global console, me*/\n' +
'\n' +
'(function (console, me) {\n' +
' "use strict";\n' +
'\n' +
' var ALTITUDE = 100,\n' +
' EPSILON = 9,\n' +
' CHECKPOINT_LIST = [],\n' +
' DIRECTION_LIST = [\n' +
' {\n' +
' distance: 1053,\n' +
' bearing: 293\n' +
' },\n' +
' {\n' +
' distance: 800,\n' +
' bearing: 104\n' +
' },\n' +
' {\n' +
' distance: 669,\n' +
' bearing: 352\n' +
' },\n' +
' {\n' +
' distance: 925,\n' +
' bearing: 162\n' +
' },\n' +
' {\n' +
' distance: 690,\n' +
' bearing: 47\n' +
' },\n' +
' {\n' +
' distance: 935,\n' +
' bearing: 166\n' +
' },\n' +
' {\n' +
' distance: 1129,\n' +
' bearing: 289\n' +
' },\n' +
' {\n' +
' distance: 520,\n' +
' bearing: 94\n' +
' }\n' +
' ],\n' +
' R = 6371e3 // meters;\n' +
'\n' +
' function to_deg(rad) {\n' +
' return rad * 180 / Math.PI;\n' +
' }\n' +
'\n' +
' function to_rad(deg) {\n' +
' return deg * Math.PI / 180;\n' +
' }\n' +
'\n' +
' function set_checkpoints(lat, lon) {\n' +
' var bearing_rad,\n' +
' lat_end,\n' +
' lon_end,\n' +
' lat_start = to_rad(lat),\n' +
' lon_start = to_rad(lon),\n' +
' relative_d;\n' +
'\n' +
' DIRECTION_LIST.forEach(function (e) {\n' +
' bearing_rad = to_rad(e.bearing);\n' +
' relative_d = e.distance / R;\n' +
'\n' +
' lat_end = Math.asin(Math.sin(lat_start) * Math.cos(relative_d)\n' +
' + Math.cos(lat_start) * Math.sin(relative_d) * Math.cos(bearing_rad));\n' +
' lon_end = lon_start + Math.atan2(\n' +
' Math.sin(bearing_rad) * Math.sin(relative_d) * Math.cos(lat_start),\n' +
' Math.cos(relative_d) - Math.sin(lat_start) * Math.sin(lon_start));\n' +
'\n' +
' CHECKPOINT_LIST.push({' +
' latitude: to_deg(lat_end),\n' +
' longitude: to_deg(lon_end)\n' +
' });\n' +
'\n' +
' lat_start = lat_end;\n' +
' lon_start = lon_end;\n' +
' });\n' +
' }\n' +
'\n' +
' function distance(lat1, lon1, lat2, lon2) {\n' +
' var la1 = lat1 * Math.PI / 180, // lat, lon in radians\n' +
' la2 = lat2 * Math.PI / 180,\n' +
' lo1 = lon1 * Math.PI / 180,\n' +
' lo2 = lon2 * Math.PI / 180,\n' +
' haversine_phi = Math.pow(Math.sin((la2 - la1) / 2), 2),\n' +
' sin_lon = Math.sin((lo2 - lo1) / 2),\n' +
' h = haversine_phi + Math.cos(la1) * Math.cos(la2) * sin_lon * sin_lon;\n' +
' return 2 * R * Math.asin(Math.sqrt(h));\n' +
' }\n' +
'\n' +
' me.onStart = function (timestamp) {\n' +
' me.direction_set = false;\n' +
' me.next_checkpoint = 0;\n' +
' me.takeOff();\n' +
' };\n' +
'\n' +
' me.onUpdate = function (timestamp) {\n' +
' if (!me.isReadyToFly()) {\n' +
' return;\n' +
' }\n' +
' ];\n' +
'\n' +
'function distance(lat1, lon1, lat2, lon2) {\n' +
' var R = 6371e3, // meters\n' +
' la1 = lat1 * Math.PI / 180, // lat, lon in radians\n' +
' la2 = lat2 * Math.PI / 180,\n' +
' lo1 = lon1 * Math.PI / 180,\n' +
' lo2 = lon2 * Math.PI / 180,\n' +
' haversine_phi = Math.pow(Math.sin((la2 - la1) / 2), 2),\n' +
' sin_lon = Math.sin((lo2 - lo1) / 2),\n' +
' h = haversine_phi + Math.cos(la1) * Math.cos(la2) * sin_lon * sin_lon;\n' +
' return 2 * R * Math.asin(Math.sqrt(h));\n' +
'}\n' +
' me.current_position = me.getCurrentPosition();\n' +
' if (CHECKPOINT_LIST.length === 0) {\n' +
' set_checkpoints(me.current_position.latitude,\n' +
' me.current_position.longitude);\n' +
' }\n' +
'\n' +
'me.onStart = function (timestamp) {\n' +
' me.direction_set = false;\n' +
' me.next_checkpoint = 0;\n' +
'};\n' +
' if (!me.direction_set) {\n' +
' if (me.next_checkpoint < CHECKPOINT_LIST.length) {\n' +
' me.setTargetCoordinates(\n' +
' CHECKPOINT_LIST[me.next_checkpoint].latitude,\n' +
' CHECKPOINT_LIST[me.next_checkpoint].longitude,\n' +
' ALTITUDE + ALTITUDE * me.id,\n' +
' ' + DEFAULT_SPEED + '\n' +
' );\n' +
' console.log("[DEMO] Going to Checkpoint", me.next_checkpoint);\n' +
' }\n' +
' me.direction_set = true;\n' +
' return;\n' +
' }\n' +
'\n' +
'me.onUpdate = function (timestamp) {\n' +
' if (!me.direction_set) {\n' +
' if (me.next_checkpoint < CHECKPOINT_LIST.length) {\n' +
' me.setTargetCoordinates(\n' +
' me.current_position = me.getCurrentPosition();\n' +
' me.distance = distance(\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' +
' CHECKPOINT_LIST[me.next_checkpoint].altitude + ALTITUDE + ALTITUDE * me.id,\n' +
' ' + DEFAULT_SPEED + '\n' +
' CHECKPOINT_LIST[me.next_checkpoint].longitude\n' +
' );\n' +
' console.log("[DEMO] Going to Checkpoint %d", me.next_checkpoint);\n' +
' if (me.distance <= EPSILON) {\n' +
' console.log("[DEMO] Reached Checkpoint", me.next_checkpoint);\n' +
' me.next_checkpoint += 1;\n' +
' me.direction_set = false;\n' +
' }\n' +
' return;\n' +
' }\n' +
' me.direction_set = true;\n' +
' return;\n' +
' }\n' +
' if (me.next_checkpoint < CHECKPOINT_LIST.length) {\n' +
' me.current_position = me.getCurrentPosition();\n' +
' me.distance = distance(\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' +
' if (me.distance <= EPSILON) {\n' +
' console.log("[DEMO] Reached Checkpoint %d", me.next_checkpoint);\n' +
' me.next_checkpoint += 1;\n' +
' me.direction_set = false;\n' +
'\n' +
' if (!me.isLanding()) {\n' +
' me.land();\n' +
' }\n' +
' return;\n' +
' }\n' +
' if (!me.isLanding()) { me.land() };\n' +
' if (me.getCurrentPosition().altitude <= 0) { me.exit(0) };\n' +
'};',
' if (me.getCurrentPosition().altitude <= 0) {\n' +
' me.exit(0);\n' +
' }\n' +
' };\n' +
'}(console, me));\n',
DRAW = true,
LOG = true,
LOG_TIME = 1662.7915426540285,
......@@ -246,7 +299,7 @@
"editable": 1,
"key": "drone_max_acceleration",
"hidden": 0,
"type": "IntegerField"
"type": "FloatField"
},
"my_drone_max_deceleration": {
"description": "",
......@@ -497,7 +550,7 @@
}
game_parameters_json = {
"drone": {
"maxAcceleration": parseInt(options.drone_max_acceleration, 10),
"maxAcceleration": parseFloat(options.drone_max_acceleration),
"maxDeceleration": parseInt(options.drone_max_deceleration, 10),
"minSpeed": parseInt(options.drone_min_speed, 10),
"speed": parseFloat(options.drone_speed),
......
......@@ -246,7 +246,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1015.64120.46679.6946</string> </value>
<value> <string>1020.29234.48115.42939</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -266,7 +266,7 @@
</tuple>
<state>
<tuple>
<float>1713425712.2</float>
<float>1730734363.63</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