CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Blimp/mode_loiter.cpp
Views: 1798
1
#include "Blimp.h"
2
/*
3
* Init and run calls for loiter flight mode
4
*/
5
6
//Number of seconds of movement that the target position can be ahead of actual position.
7
#define POS_LAG 1
8
9
bool ModeLoiter::init(bool ignore_checks)
10
{
11
target_pos = blimp.pos_ned;
12
target_yaw = blimp.ahrs.get_yaw();
13
14
return true;
15
}
16
17
//Runs the main loiter controller
18
void ModeLoiter::run()
19
{
20
const float dt = blimp.scheduler.get_last_loop_time_s();
21
22
Vector3f pilot;
23
float pilot_yaw;
24
get_pilot_input(pilot, pilot_yaw);
25
pilot.x *= g.max_pos_xy * dt;
26
pilot.y *= g.max_pos_xy * dt;
27
pilot.z *= g.max_pos_z * dt;
28
pilot_yaw *= g.max_pos_yaw * dt;
29
30
if (g.simple_mode == 0) {
31
//If simple mode is disabled, input is in body-frame, thus needs to be rotated.
32
blimp.rotate_BF_to_NE(pilot.xy());
33
}
34
35
if (fabsf(target_pos.x-blimp.pos_ned.x) < (g.max_pos_xy*POS_LAG)) {
36
target_pos.x += pilot.x;
37
}
38
if (fabsf(target_pos.y-blimp.pos_ned.y) < (g.max_pos_xy*POS_LAG)) {
39
target_pos.y += pilot.y;
40
}
41
if (fabsf(target_pos.z-blimp.pos_ned.z) < (g.max_pos_z*POS_LAG)) {
42
target_pos.z += pilot.z;
43
}
44
if (fabsf(wrap_PI(target_yaw-ahrs.get_yaw())) < (g.max_pos_yaw*POS_LAG)) {
45
target_yaw = wrap_PI(target_yaw + pilot_yaw);
46
}
47
48
blimp.loiter->run(target_pos, target_yaw, Vector4b{false,false,false,false});
49
}
50
51