Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
c-astral-wrapper
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
nexedi
c-astral-wrapper
Commits
210738dd
Commit
210738dd
authored
Apr 24, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Plain Diff
Multicopters update
See merge request
!2
parents
96ed9f80
d289eec9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
117 deletions
+64
-117
mavsdk_wrapper.cpp
mavsdk_wrapper.cpp
+64
-117
No files found.
mavsdk_wrapper.cpp
View file @
210738dd
...
@@ -44,7 +44,6 @@ static const float ADDED_DISTANCE = (2 * DEFAULT_RADIUS) / EARTH_RADIUS;
...
@@ -44,7 +44,6 @@ static const float ADDED_DISTANCE = (2 * DEFAULT_RADIUS) / EARTH_RADIUS;
static
const
double
COS_ADDED_DISTANCE
=
cos
(
ADDED_DISTANCE
);
static
const
double
COS_ADDED_DISTANCE
=
cos
(
ADDED_DISTANCE
);
static
const
double
SIN_ADDED_DISTANCE
=
sin
(
ADDED_DISTANCE
);
static
const
double
SIN_ADDED_DISTANCE
=
sin
(
ADDED_DISTANCE
);
static
int
mavsdk_started
=
0
;
static
Telemetry
::
Position
origin
;
static
Telemetry
::
Position
origin
;
static
int64_t
current_position
[
POSITION_ARRAY_SIZE
]
=
{
0
};
static
int64_t
current_position
[
POSITION_ARRAY_SIZE
]
=
{
0
};
static
int64_t
timestamp_difference
=
0
;
static
int64_t
timestamp_difference
=
0
;
...
@@ -53,13 +52,10 @@ static Coordinates targeted_destination;
...
@@ -53,13 +52,10 @@ static Coordinates targeted_destination;
static
float
targeted_radius
=
DEFAULT_RADIUS
;
static
float
targeted_radius
=
DEFAULT_RADIUS
;
static
Coordinates
projected_destination
;
static
Coordinates
projected_destination
;
static
const
float
DEFAULT_SPEED
=
17
;
static
float
last_override_altitude
;
static
float
last_override_speed
;
static
bool
do_projection
=
false
;
static
bool
do_projection
=
false
;
static
bool
first_coordinate_entered
=
false
;
static
bool
is_in_air
=
false
;
static
bool
is_in_air
=
false
;
static
bool
do_reposition_sent
=
false
;
static
bool
override_sent
=
false
;
// Logs functions
// Logs functions
...
@@ -81,11 +77,6 @@ static void log_error_from_result(std::string message, Enumeration result) {
...
@@ -81,11 +77,6 @@ static void log_error_from_result(std::string message, Enumeration result) {
// Action functions
// Action functions
static
int
doAction
(
Action
::
Result
(
Action
::*
toDo
)(
void
)
const
,
std
::
string
failure_message
)
{
static
int
doAction
(
Action
::
Result
(
Action
::*
toDo
)(
void
)
const
,
std
::
string
failure_message
)
{
if
(
!
mavsdk_started
)
{
log_error
(
"Mavsdk not started"
);
return
-
1
;
}
const
Action
::
Result
result
=
(
action
->*
toDo
)();
const
Action
::
Result
result
=
(
action
->*
toDo
)();
if
(
result
!=
Action
::
Result
::
Success
)
{
if
(
result
!=
Action
::
Result
::
Success
)
{
log_error_from_result
(
failure_message
,
result
);
log_error_from_result
(
failure_message
,
result
);
...
@@ -149,9 +140,6 @@ static Coordinates getProjectionCoordinates(Coordinates destination, Coordinates
...
@@ -149,9 +140,6 @@ static Coordinates getProjectionCoordinates(Coordinates destination, Coordinates
}
}
static
int
doReposition
(
float
la
,
float
lo
,
float
radius
,
float
y
)
{
static
int
doReposition
(
float
la
,
float
lo
,
float
radius
,
float
y
)
{
if
(
!
mavsdk_started
)
return
-
1
;
MavlinkPassthrough
::
CommandLong
command
;
MavlinkPassthrough
::
CommandLong
command
;
command
.
command
=
MAV_CMD_DO_REPOSITION
;
command
.
command
=
MAV_CMD_DO_REPOSITION
;
command
.
param1
=
-
1
;
// Ground speed, -1 for default
command
.
param1
=
-
1
;
// Ground speed, -1 for default
...
@@ -163,22 +151,27 @@ static int doReposition(float la, float lo, float radius, float y) {
...
@@ -163,22 +151,27 @@ static int doReposition(float la, float lo, float radius, float y) {
command
.
target_sysid
=
mavlink_passthrough
->
get_target_sysid
();
command
.
target_sysid
=
mavlink_passthrough
->
get_target_sysid
();
command
.
target_compid
=
mavlink_passthrough
->
get_target_compid
();
command
.
target_compid
=
mavlink_passthrough
->
get_target_compid
();
return
doMavlinkCommand
(
command
,
"Entering loiter mode failed"
);
int
res
=
doMavlinkCommand
(
command
,
"Entering loiter mode failed"
);
do_reposition_sent
=
false
;
return
res
;
}
}
static
void
doReposition_async
(
float
la
,
float
lo
,
float
radius
,
float
y
)
{
static
int
doReposition_async
(
float
la
,
float
lo
,
float
radius
,
float
y
)
{
if
(
!
first_coordinate_entered
)
{
if
(
do_reposition_sent
)
{
first_coordinate_entered
=
true
;
log_error
(
"Command DO_REPOSITION already in working queue."
);
return
-
1
;
}
}
do_reposition_sent
=
true
;
std
::
thread
(
doReposition
,
la
,
lo
,
radius
,
y
).
detach
();
std
::
thread
(
doReposition
,
la
,
lo
,
radius
,
y
).
detach
();
return
0
;
}
}
static
void
updateProjection
(
int64_t
current_lat
,
int64_t
current_lon
)
{
static
int
updateProjection
(
int64_t
current_lat
,
int64_t
current_lon
)
{
Coordinates
position
{
(
double
)
current_lat
/
1e7
,
(
double
)
current_lon
/
1e7
};
Coordinates
position
{
(
double
)
current_lat
/
1e7
,
(
double
)
current_lon
/
1e7
};
projected_destination
=
getProjectionCoordinates
(
targeted_destination
,
projected_destination
=
getProjectionCoordinates
(
targeted_destination
,
position
);
position
);
doReposition_async
(
return
doReposition_async
(
(
float
)
projected_destination
.
latitude
,
(
float
)
projected_destination
.
latitude
,
(
float
)
projected_destination
.
longitude
,
(
float
)
projected_destination
.
longitude
,
DEFAULT_RADIUS
,
DEFAULT_RADIUS
,
...
@@ -191,41 +184,37 @@ static long long int getTimestamp() {
...
@@ -191,41 +184,37 @@ static long long int getTimestamp() {
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
now
.
time_since_epoch
()).
count
();
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
milliseconds
>
(
now
.
time_since_epoch
()).
count
();
}
}
static
int
doOverride
(
float
altitude
,
float
speed
,
const
char
*
failure_msg
)
{
static
int
doOverride
(
float
altitude
,
float
airspeed
,
const
char
*
failure_msg
)
{
if
(
!
mavsdk_started
)
return
-
1
;
if
(
!
first_coordinate_entered
)
{
log_error
(
"Not overriding altitude before user sets coordinates"
);
return
-
1
;
}
MavlinkPassthrough
::
CommandLong
command
;
MavlinkPassthrough
::
CommandLong
command
;
command
.
command
=
MAV_CMD_DO_OVERRIDE
;
command
.
command
=
MAV_CMD_DO_OVERRIDE
;
command
.
param1
=
1
|
2
|
4
|
8
;
command
.
param1
=
1
|
2
|
4
|
8
;
command
.
param2
=
1
|
2
|
4
|
8
;
command
.
param2
=
1
|
2
|
4
|
8
;
command
.
param3
=
altitude
;
command
.
param3
=
altitude
;
command
.
param4
=
speed
;
command
.
param4
=
air
speed
;
command
.
target_sysid
=
mavlink_passthrough
->
get_target_sysid
();
command
.
target_sysid
=
mavlink_passthrough
->
get_target_sysid
();
command
.
target_compid
=
mavlink_passthrough
->
get_target_compid
();
command
.
target_compid
=
mavlink_passthrough
->
get_target_compid
();
return
doMavlinkCommand
(
command
,
failure_msg
);
int
res
=
doMavlinkCommand
(
command
,
failure_msg
);
}
override_sent
=
false
;
return
res
;
static
int
setAltitude
(
float
altitude
)
{
last_override_altitude
=
altitude
;
return
doOverride
(
altitude
,
last_override_speed
,
"Setting altitude failed"
);
}
}
static
void
setAltitude_async
(
float
altitude
)
{
static
int
doOverride_async
(
float
altitude
,
float
airspeed
)
{
std
::
thread
(
setAltitude
,
altitude
).
detach
();
if
(
override_sent
)
{
log_error
(
"Command DO_REPOSITION already in working queue."
);
return
-
1
;
}
override_sent
=
true
;
std
::
thread
(
doOverride
,
altitude
,
airspeed
,
"Overriding altitude and speed failed"
).
detach
();
return
0
;
}
}
void
updateLogAndProjection
(
void
)
{
void
updateLogAndProjection
(
void
)
{
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
Telemetry
::
FixedwingMetrics
metrics
;
Telemetry
::
FixedwingMetrics
metrics
;
if
(
mavsdk_started
)
{
metrics
=
telemetry
->
fixedwing_metrics
();
metrics
=
telemetry
->
fixedwing_metrics
();
oss
<<
current_position
[
TIMESTAMP
]
<<
";"
oss
<<
current_position
[
TIMESTAMP
]
<<
";"
<<
current_position
[
LATITUDE
]
<<
";"
<<
current_position
[
LATITUDE
]
<<
";"
...
@@ -236,7 +225,6 @@ void updateLogAndProjection(void) {
...
@@ -236,7 +225,6 @@ void updateLogAndProjection(void) {
<<
metrics
.
airspeed_m_s
<<
";"
<<
metrics
.
climb_rate_m_s
;
<<
metrics
.
airspeed_m_s
<<
";"
<<
metrics
.
climb_rate_m_s
;
log
(
oss
.
str
());
log
(
oss
.
str
());
if
(
first_coordinate_entered
)
{
if
(
do_projection
)
{
if
(
do_projection
)
{
updateProjection
(
current_position
[
LATITUDE
],
updateProjection
(
current_position
[
LATITUDE
],
current_position
[
LONGITUDE
]);
current_position
[
LONGITUDE
]);
...
@@ -248,8 +236,6 @@ void updateLogAndProjection(void) {
...
@@ -248,8 +236,6 @@ void updateLogAndProjection(void) {
0
0
);
);
}
}
}
}
}
}
// Connexion management functions
// Connexion management functions
...
@@ -308,6 +294,7 @@ int start(const char * ip, int port, const char * log_file, int timeout) {
...
@@ -308,6 +294,7 @@ int start(const char * ip, int port, const char * log_file, int timeout) {
telemetry
->
subscribe_landed_state
([](
const
Telemetry
::
LandedState
landed_state
)
{
telemetry
->
subscribe_landed_state
([](
const
Telemetry
::
LandedState
landed_state
)
{
if
(
landed_state
==
Telemetry
::
LandedState
::
InAir
)
{
if
(
landed_state
==
Telemetry
::
LandedState
::
InAir
)
{
is_in_air
=
true
;
is_in_air
=
true
;
doAction
(
&
Action
::
transition_to_fixedwing
,
"Transition to fixedwing failed"
);
}
}
});
});
...
@@ -318,11 +305,7 @@ int start(const char * ip, int port, const char * log_file, int timeout) {
...
@@ -318,11 +305,7 @@ int start(const char * ip, int port, const char * log_file, int timeout) {
}
while
(
isnan
(
abs_altitude
)
||
abs_altitude
==
0
);
}
while
(
isnan
(
abs_altitude
)
||
abs_altitude
==
0
);
origin
=
telemetry
->
position
();
origin
=
telemetry
->
position
();
last_override_altitude
=
origin
.
absolute_altitude_m
+
DEFAULT_OVERRIDE_ALTITUDE
;
last_override_speed
=
DEFAULT_SPEED
;
log
(
"MAVSDK started..."
);
mavsdk_started
=
1
;
log
(
"timestamp (ms);latitude (°E7);longitude (°E7);AMSL (mm);rel altitude (mm);yaw (°);air speed (m/s);climb rate (m/s)"
);
log
(
"timestamp (ms);latitude (°E7);longitude (°E7);AMSL (mm);rel altitude (mm);yaw (°);air speed (m/s);climb rate (m/s)"
);
return
0
;
return
0
;
...
@@ -347,10 +330,8 @@ int reboot() {
...
@@ -347,10 +330,8 @@ int reboot() {
// Flight state management functions
// Flight state management functions
int
arm
(
void
)
{
int
arm
(
void
)
{
if
(
!
mavsdk_started
)
return
-
1
;
if
(
telemetry
->
armed
())
{
if
(
telemetry
->
armed
())
{
log
(
"Drone already armed"
);
return
0
;
return
0
;
}
}
...
@@ -365,29 +346,10 @@ int arm(void) {
...
@@ -365,29 +346,10 @@ int arm(void) {
int
takeOff
(
void
)
{
int
takeOff
(
void
)
{
action
->
set_takeoff_altitude
(
DEFAULT_OVERRIDE_ALTITUDE
);
action
->
set_takeoff_altitude
(
DEFAULT_OVERRIDE_ALTITUDE
);
if
(
doAction
(
&
Action
::
takeoff
,
"Takeoff failed"
))
return
doAction
(
&
Action
::
takeoff
,
"Takeoff failed"
);
return
-
1
;
return
0
;
}
int
takeOffAndWait
(
void
)
{
if
(
takeOff
()
<
0
)
return
-
1
;
while
(
telemetry
->
flight_mode
()
!=
Telemetry
::
FlightMode
::
Takeoff
)
sleep_for
(
seconds
(
1
));
while
(
telemetry
->
flight_mode
()
==
Telemetry
::
FlightMode
::
Takeoff
)
sleep_for
(
seconds
(
1
));
return
doAction
(
&
Action
::
transition_to_fixedwing
,
"Transition to fixedwing failed"
);
}
}
int
triggerParachute
(
void
)
{
int
land
(
void
)
{
if
(
!
mavsdk_started
)
return
-
1
;
log
(
"Landing..."
);
log
(
"Landing..."
);
MavlinkPassthrough
::
CommandLong
command
;
MavlinkPassthrough
::
CommandLong
command
;
command
.
command
=
MAV_CMD_DO_PARACHUTE
;
command
.
command
=
MAV_CMD_DO_PARACHUTE
;
...
@@ -400,38 +362,23 @@ int triggerParachute(void) {
...
@@ -400,38 +362,23 @@ int triggerParachute(void) {
// Flight management functions
// Flight management functions
void
loiter
(
double
la
,
double
lo
,
float
a
,
float
radius
)
{
int
loiter
(
double
latitude
,
double
longitude
,
float
altitude
,
targeted_destination
.
latitude
=
la
;
float
radius
,
float
speed
)
{
targeted_destination
.
longitude
=
lo
;
targeted_destination
.
latitude
=
latitude
;
targeted_destination
.
longitude
=
longitude
;
targeted_radius
=
radius
;
targeted_radius
=
radius
;
do_projection
=
false
;
do_projection
=
false
;
doReposition_async
((
float
)
la
,
(
float
)
lo
,
radius
,
0
);
return
doReposition_async
((
float
)
latitude
,
(
float
)
longitude
,
radius
,
0
)
&&
doOverride_async
(
altitude
,
speed
);
setAltitude_async
(
a
);
}
static
int
setAirSpeed
(
float
airspeed
)
{
last_override_speed
=
airspeed
;
return
doOverride
(
last_override_altitude
,
airspeed
,
"Setting airspeed failed"
);
}
void
setAirSpeed_async
(
float
airspeed
)
{
std
::
thread
(
setAirSpeed
,
airspeed
).
detach
();
}
}
void
setTargetCoordinates
(
double
la
,
double
lo
,
float
a
)
{
int
setTargetCoordinates
(
double
latitude
,
double
longitude
,
float
altitude
,
if
(
!
mavsdk_started
)
{
float
speed
)
{
log_error
(
"Mavsdk not started"
);
targeted_destination
.
latitude
=
latitude
;
return
;
targeted_destination
.
longitude
=
longitude
;
}
targeted_destination
.
latitude
=
la
;
targeted_destination
.
longitude
=
lo
;
do_projection
=
true
;
do_projection
=
true
;
updateProjection
(
current_position
[
0
],
current_position
[
1
]);
return
updateProjection
(
current_position
[
0
],
current_position
[
1
])
&&
doOverride_async
(
altitude
,
speed
);
setAltitude_async
(
a
);
}
}
// Information functions
// Information functions
...
@@ -495,8 +442,8 @@ int gpsIsOk(void) {
...
@@ -495,8 +442,8 @@ int gpsIsOk(void) {
return
(
fixType
!=
Telemetry
::
FixType
::
NoGps
)
&&
(
fixType
!=
Telemetry
::
FixType
::
NoFix
);
return
(
fixType
!=
Telemetry
::
FixType
::
NoGps
)
&&
(
fixType
!=
Telemetry
::
FixType
::
NoFix
);
}
}
int
healthAllOk
(
void
)
{
int
isReadyToFly
(
void
)
{
return
telemetry
->
health_all_ok
()
;
return
is_in_air
;
}
}
int
isLanding
(
void
)
{
int
isLanding
(
void
)
{
...
...
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