Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
erp5
Commits
41796c1f
Commit
41796c1f
authored
Jul 31, 2023
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
erp5_officejs_drone_simulator: fix position update
Fix position update regarding the drone speed
parent
79f1313d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
107 additions
and
56 deletions
+107
-56
bt5/erp5_officejs_drone_simulator/PathTemplateItem/web_page_module/drone_simulator_fixedwingdrone_js.js
...Item/web_page_module/drone_simulator_fixedwingdrone_js.js
+105
-54
bt5/erp5_officejs_drone_simulator/PathTemplateItem/web_page_module/drone_simulator_fixedwingdrone_js.xml
...tem/web_page_module/drone_simulator_fixedwingdrone_js.xml
+2
-2
No files found.
bt5/erp5_officejs_drone_simulator/PathTemplateItem/web_page_module/drone_simulator_fixedwingdrone_js.js
View file @
41796c1f
...
...
@@ -92,7 +92,7 @@ var FixedWingDroneAPI = /** @class */ (function () {
** Function called on every drone update, right before onUpdate AI script
*/
FixedWingDroneAPI
.
prototype
.
internal_update
=
function
(
context
,
delta_time
)
{
var
diff
,
newrot
,
orientationValue
,
rotStep
,
updateSpeed
;
var
diff
,
newrot
,
orientationValue
,
rotStep
;
//TODO rotation
if
(
context
.
_rotationTarget
)
{
...
...
@@ -116,18 +116,8 @@ var FixedWingDroneAPI = /** @class */ (function () {
}
this
.
_updateSpeed
(
context
,
delta_time
);
this
.
_update
Direc
tion
(
context
,
delta_time
);
this
.
_update
Posi
tion
(
context
,
delta_time
);
updateSpeed
=
context
.
_speed
*
delta_time
/
1000
;
if
(
context
.
_direction
.
x
!==
0
||
context
.
_direction
.
y
!==
0
||
context
.
_direction
.
z
!==
0
)
{
context
.
_controlMesh
.
position
.
addInPlace
(
new
BABYLON
.
Vector3
(
context
.
_direction
.
x
*
updateSpeed
,
context
.
_direction
.
y
*
updateSpeed
,
context
.
_direction
.
z
*
updateSpeed
));
}
//TODO rotation
orientationValue
=
context
.
_maxOrientation
*
(
context
.
_speed
/
context
.
_maxSpeed
);
...
...
@@ -180,51 +170,108 @@ var FixedWingDroneAPI = /** @class */ (function () {
}
};
FixedWingDroneAPI
.
prototype
.
_updateDirection
=
function
(
drone
,
delta_time
)
{
var
horizontalCoeff
,
newX
,
newY
,
newZ
,
tangentYaw
;
FixedWingDroneAPI
.
prototype
.
_updatePosition
=
function
(
drone
,
delta_time
)
{
var
R
=
6371
e3
,
currentGeoCoordinates
=
this
.
_mapManager
.
convertToGeoCoordinates
(
drone
.
position
.
x
,
drone
.
position
.
y
,
drone
.
position
.
z
,
this
.
_map_dict
),
targetCoordinates
=
this
.
_mapManager
.
convertToGeoCoordinates
(
drone
.
_targetCoordinates
.
x
,
drone
.
_targetCoordinates
.
y
,
drone
.
_targetCoordinates
.
z
,
this
.
_map_dict
),
bearing
=
this
.
_computeBearing
(
currentGeoCoordinates
.
x
,
currentGeoCoordinates
.
y
,
targetCoordinates
.
x
,
targetCoordinates
.
y
),
currentCosLat
,
currentLatRad
,
distance
,
distanceCos
,
distanceSin
,
currentSinLat
,
currentLonRad
,
groundSpeed
,
newLatRad
,
newLonRad
,
newX
,
newY
,
newYaw
,
newYawRad
,
verticalSpeed
,
yawToDirection
;
if
(
this
.
_loiter_mode
&&
Math
.
sqrt
(
Math
.
pow
(
drone
.
_targetCoordinates
.
x
-
drone
.
position
.
x
,
2
)
+
Math
.
pow
(
drone
.
_targetCoordinates
.
y
-
drone
.
position
.
y
,
2
)
)
<=
this
.
_loiter_radius
)
{
tangentYaw
=
this
.
_computeBearing
(
drone
.
position
.
x
,
drone
.
position
.
y
,
drone
.
_targetCoordinates
.
x
,
drone
.
_targetCoordinates
.
y
)
-
90
;
// trigonometric circle is east oriented, yaw angle is clockwise
tangentYaw
=
this
.
_toRad
(
-
tangentYaw
+
90
);
newX
=
Math
.
cos
(
tangentYaw
);
newZ
=
Math
.
sin
(
tangentYaw
);
newYaw
=
bearing
-
90
;
}
else
{
[
newX
,
newZ
]
=
this
.
_getNewYaw
(
drone
,
delta_time
);
newYaw
=
this
.
_getNewYaw
(
drone
,
bearing
,
delta_time
);
}
newY
=
this
.
_getNewAltitude
(
drone
);
newYawRad
=
this
.
_toRad
(
newYaw
);
currentLatRad
=
this
.
_toRad
(
currentGeoCoordinates
.
x
);
currentCosLat
=
Math
.
cos
(
currentLatRad
);
currentSinLat
=
Math
.
sin
(
currentLatRad
);
currentLonRad
=
this
.
_toRad
(
currentGeoCoordinates
.
y
);
verticalSpeed
=
this
.
_getVerticalSpeed
(
drone
);
groundSpeed
=
Math
.
sqrt
(
Math
.
pow
(
drone
.
getAirSpeed
(),
2
)
-
Math
.
pow
(
verticalSpeed
,
2
)
);
distance
=
(
groundSpeed
*
delta_time
/
1000
)
/
R
;
distanceCos
=
Math
.
cos
(
distance
);
distanceSin
=
Math
.
sin
(
distance
);
newLatRad
=
Math
.
asin
(
currentSinLat
*
distanceCos
+
currentCosLat
*
distanceSin
*
Math
.
cos
(
newYawRad
)
);
newLonRad
=
currentLonRad
+
Math
.
atan2
(
Math
.
sin
(
newYawRad
)
*
distanceSin
*
currentCosLat
,
distanceCos
-
currentSinLat
*
Math
.
sin
(
newLatRad
)
);
horizontalCoeff
=
Math
.
sqrt
(
(
Math
.
pow
(
drone
.
getAirSpeed
(),
2
)
-
Math
.
pow
(
newY
,
2
)
)
/
(
Math
.
pow
(
newX
,
2
)
+
Math
.
pow
(
newZ
,
2
)
)
[
newX
,
newY
]
=
this
.
_mapManager
.
normalize
(
this
.
_mapManager
.
longitudToX
(
this
.
_toDeg
(
newLonRad
),
this
.
_map_dict
.
map_size
),
this
.
_mapManager
.
latitudeToY
(
this
.
_toDeg
(
newLatRad
),
this
.
_map_dict
.
map_size
),
this
.
_map_dict
);
newX
*=
horizontalCoeff
;
newZ
*=
horizontalCoeff
;
// swap y and z axis so z axis represents altitude
drone
.
setDirection
(
newX
,
newZ
,
newY
);
drone
.
_controlMesh
.
position
.
addInPlace
(
new
BABYLON
.
Vector3
(
Math
.
abs
(
newX
-
drone
.
position
.
x
)
*
(
newX
<
drone
.
position
.
x
?
-
1
:
1
),
verticalSpeed
*
delta_time
/
1000
,
Math
.
abs
(
newY
-
drone
.
position
.
y
)
*
(
newY
<
drone
.
position
.
y
?
-
1
:
1
)
));
yawToDirection
=
this
.
_toRad
(
-
newYaw
+
90
);
drone
.
setDirection
(
groundSpeed
*
Math
.
cos
(
yawToDirection
),
groundSpeed
*
Math
.
sin
(
yawToDirection
),
verticalSpeed
);
};
FixedWingDroneAPI
.
prototype
.
_getNewYaw
=
function
(
drone
,
delta_time
)
{
FixedWingDroneAPI
.
prototype
.
_getNewYaw
=
function
(
drone
,
bearing
,
delta_time
)
{
// swap y and z axis so z axis represents altitude
var
bearing
=
this
.
_computeBearing
(
drone
.
position
.
x
,
drone
.
position
.
y
,
drone
.
_targetCoordinates
.
x
,
drone
.
_targetCoordinates
.
y
),
yaw
=
drone
.
getYaw
(),
var
yaw
=
drone
.
getYaw
(),
yawDiff
=
this
.
_computeYawDiff
(
yaw
,
bearing
),
yawUpdate
=
this
.
getYawVelocity
(
drone
)
*
delta_time
/
1000
;
...
...
@@ -233,14 +280,10 @@ var FixedWingDroneAPI = /** @class */ (function () {
}
else
if
(
yawDiff
<
0
)
{
yawUpdate
*=
-
1
;
}
yaw
+=
yawUpdate
;
// trigonometric circle is east oriented, yaw angle is clockwise
yaw
=
this
.
_toRad
(
-
yaw
+
90
);
return
[
Math
.
cos
(
yaw
),
Math
.
sin
(
yaw
)];
return
yaw
+
yawUpdate
;
};
FixedWingDroneAPI
.
prototype
.
_get
NewAltitude
=
function
(
drone
)
{
FixedWingDroneAPI
.
prototype
.
_get
VerticalSpeed
=
function
(
drone
)
{
// swap y and z axis so z axis represents altitude
var
altitudeDiff
=
drone
.
_targetCoordinates
.
z
-
drone
.
position
.
z
,
verticalSpeed
;
...
...
@@ -419,11 +462,19 @@ var FixedWingDroneAPI = /** @class */ (function () {
};
FixedWingDroneAPI
.
prototype
.
getYaw
=
function
(
drone
)
{
var
direction
=
drone
.
worldDirection
;
return
this
.
_computeBearing
(
0
,
0
,
direction
.
x
,
direction
.
z
);
};
FixedWingDroneAPI
.
prototype
.
_computeBearing
=
function
(
x1
,
z1
,
x2
,
z2
)
{
return
this
.
_toDeg
(
Math
.
atan2
(
x2
-
x1
,
z2
-
z1
));
};
return
this
.
_toDeg
(
Math
.
atan2
(
direction
.
x
,
direction
.
z
));
};
FixedWingDroneAPI
.
prototype
.
_computeBearing
=
function
(
lat1
,
lon1
,
lat2
,
lon2
)
{
var
dLon
=
this
.
_toRad
(
lon2
-
lon1
),
lat1Rad
=
this
.
_toRad
(
lat1
),
lat2Rad
=
this
.
_toRad
(
lat2
),
x
=
Math
.
cos
(
lat2Rad
)
*
Math
.
sin
(
dLon
),
y
=
Math
.
cos
(
lat1Rad
)
*
Math
.
sin
(
lat2Rad
)
-
Math
.
sin
(
lat1Rad
)
*
Math
.
cos
(
lat2Rad
)
*
Math
.
cos
(
dLon
);
return
this
.
_toDeg
(
Math
.
atan2
(
x
,
y
));
};
FixedWingDroneAPI
.
prototype
.
_computeYawDiff
=
function
(
yaw1
,
yaw2
)
{
var
diff
=
yaw2
-
yaw1
;
diff
+=
(
diff
>
180
)
?
-
360
:
(
diff
<
-
180
)
?
360
:
0
;
...
...
bt5/erp5_officejs_drone_simulator/PathTemplateItem/web_page_module/drone_simulator_fixedwingdrone_js.xml
View file @
41796c1f
...
...
@@ -240,7 +240,7 @@
</item>
<item>
<key>
<string>
serial
</string>
</key>
<value>
<string>
10
09.59163.16294.47701
</string>
</value>
<value>
<string>
10
10.8942.4282.1348
</string>
</value>
</item>
<item>
<key>
<string>
state
</string>
</key>
...
...
@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>
1690
395852.2
</float>
<float>
1690
806298.28
</float>
<string>
UTC
</string>
</tuple>
</state>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment