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
76fbaa6e
Commit
76fbaa6e
authored
Jan 22, 2024
by
Léo-Paul Géneau
👾
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require speed to set coordinates
parent
96ed9f80
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
55 deletions
+27
-55
mavsdk_wrapper.cpp
mavsdk_wrapper.cpp
+27
-55
No files found.
mavsdk_wrapper.cpp
View file @
76fbaa6e
...
...
@@ -53,12 +53,7 @@ static Coordinates targeted_destination;
static
float
targeted_radius
=
DEFAULT_RADIUS
;
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
first_coordinate_entered
=
false
;
static
bool
is_in_air
=
false
;
// Logs functions
...
...
@@ -167,9 +162,6 @@ static int doReposition(float la, float lo, float radius, float y) {
}
static
void
doReposition_async
(
float
la
,
float
lo
,
float
radius
,
float
y
)
{
if
(
!
first_coordinate_entered
)
{
first_coordinate_entered
=
true
;
}
std
::
thread
(
doReposition
,
la
,
lo
,
radius
,
y
).
detach
();
}
...
...
@@ -191,34 +183,26 @@ static long long int getTimestamp() {
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
air
speed
,
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
;
command
.
command
=
MAV_CMD_DO_OVERRIDE
;
command
.
param1
=
1
|
2
|
4
|
8
;
command
.
param2
=
1
|
2
|
4
|
8
;
command
.
param3
=
altitude
;
command
.
param4
=
speed
;
command
.
param4
=
air
speed
;
command
.
target_sysid
=
mavlink_passthrough
->
get_target_sysid
();
command
.
target_compid
=
mavlink_passthrough
->
get_target_compid
();
return
doMavlinkCommand
(
command
,
failure_msg
);
}
static
int
setAltitude
(
float
altitude
)
{
last_override_altitude
=
altitude
;
return
doOverride
(
altitude
,
last_override_speed
,
"Setting altitude failed"
);
}
static
void
setAltitude_async
(
float
altitude
)
{
std
::
thread
(
setAltitude
,
altitude
).
detach
();
static
void
doOverride_async
(
float
altitude
,
float
airspeed
)
{
std
::
thread
(
doOverride
,
altitude
,
airspeed
,
"Overriding altitude and speed failed"
).
detach
();
}
void
updateLogAndProjection
(
void
)
{
...
...
@@ -236,18 +220,16 @@ void updateLogAndProjection(void) {
<<
metrics
.
airspeed_m_s
<<
";"
<<
metrics
.
climb_rate_m_s
;
log
(
oss
.
str
());
if
(
first_coordinate_entered
)
{
if
(
do_projection
)
{
updateProjection
(
current_position
[
LATITUDE
],
current_position
[
LONGITUDE
]);
}
else
{
doReposition_async
(
(
float
)
targeted_destination
.
latitude
,
(
float
)
targeted_destination
.
longitude
,
targeted_radius
,
0
);
}
if
(
do_projection
)
{
updateProjection
(
current_position
[
LATITUDE
],
current_position
[
LONGITUDE
]);
}
else
{
doReposition_async
(
(
float
)
targeted_destination
.
latitude
,
(
float
)
targeted_destination
.
longitude
,
targeted_radius
,
0
);
}
}
}
...
...
@@ -318,8 +300,6 @@ int start(const char * ip, int port, const char * log_file, int timeout) {
}
while
(
isnan
(
abs_altitude
)
||
abs_altitude
==
0
);
origin
=
telemetry
->
position
();
last_override_altitude
=
origin
.
absolute_altitude_m
+
DEFAULT_OVERRIDE_ALTITUDE
;
last_override_speed
=
DEFAULT_SPEED
;
log
(
"MAVSDK started..."
);
mavsdk_started
=
1
;
...
...
@@ -400,38 +380,30 @@ int triggerParachute(void) {
// Flight management functions
void
loiter
(
double
la
,
double
lo
,
float
a
,
float
radius
)
{
targeted_destination
.
latitude
=
la
;
targeted_destination
.
longitude
=
lo
;
void
loiter
(
double
latitude
,
double
longitude
,
float
altitude
,
float
radius
,
float
speed
)
{
targeted_destination
.
latitude
=
latitude
;
targeted_destination
.
longitude
=
longitude
;
targeted_radius
=
radius
;
do_projection
=
false
;
doReposition_async
((
float
)
la
,
(
float
)
lo
,
radius
,
0
);
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
();
doReposition_async
((
float
)
latitude
,
(
float
)
longitude
,
radius
,
0
);
doOverride_async
(
altitude
,
speed
);
}
void
setTargetCoordinates
(
double
la
,
double
lo
,
float
a
)
{
void
setTargetCoordinates
(
double
latitude
,
double
longitude
,
float
altitude
,
float
speed
)
{
if
(
!
mavsdk_started
)
{
log_error
(
"Mavsdk not started"
);
return
;
}
targeted_destination
.
latitude
=
la
;
targeted_destination
.
longitude
=
lo
;
targeted_destination
.
latitude
=
la
titude
;
targeted_destination
.
longitude
=
lo
ngitude
;
do_projection
=
true
;
updateProjection
(
current_position
[
0
],
current_position
[
1
]);
setAltitude_async
(
a
);
doOverride_async
(
altitude
,
speed
);
}
// Information functions
...
...
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