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