ardupilot/Blimp/mode_loiter.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.3 KiB
C++
Raw Permalink Normal View History

2021-06-18 01:40:01 -03:00
#include "Blimp.h"
/*
* Init and run calls for loiter flight mode
*/
2023-07-27 02:03:08 -03:00
//Number of seconds of movement that the target position can be ahead of actual position.
#define POS_LAG 1
2021-06-18 01:40:01 -03:00
2023-07-27 02:03:08 -03:00
bool ModeLoiter::init(bool ignore_checks)
{
2021-06-18 01:40:01 -03:00
target_pos = blimp.pos_ned;
target_yaw = blimp.ahrs.get_yaw();
return true;
2023-07-27 02:03:08 -03:00
}
2021-06-18 01:40:01 -03:00
//Runs the main loiter controller
void ModeLoiter::run()
{
2022-11-30 01:25:42 -04:00
const float dt = blimp.scheduler.get_last_loop_time_s();
2021-06-18 01:40:01 -03:00
2023-07-27 02:03:08 -03:00
Vector3f pilot;
float pilot_yaw;
get_pilot_input(pilot, pilot_yaw);
pilot.x *= g.max_pos_xy * dt;
pilot.y *= g.max_pos_xy * dt;
pilot.z *= g.max_pos_z * dt;
pilot_yaw *= g.max_pos_yaw * dt;
if (g.simple_mode == 0) {
2021-06-18 01:40:01 -03:00
//If simple mode is disabled, input is in body-frame, thus needs to be rotated.
2021-06-22 03:36:11 -03:00
blimp.rotate_BF_to_NE(pilot.xy());
2021-06-18 01:40:01 -03:00
}
if (fabsf(target_pos.x-blimp.pos_ned.x) < (g.max_pos_xy*POS_LAG)) {
target_pos.x += pilot.x;
}
if (fabsf(target_pos.y-blimp.pos_ned.y) < (g.max_pos_xy*POS_LAG)) {
target_pos.y += pilot.y;
}
if (fabsf(target_pos.z-blimp.pos_ned.z) < (g.max_pos_z*POS_LAG)) {
target_pos.z += pilot.z;
}
if (fabsf(wrap_PI(target_yaw-ahrs.get_yaw())) < (g.max_pos_yaw*POS_LAG)) {
target_yaw = wrap_PI(target_yaw + pilot_yaw);
}
2021-06-18 01:40:01 -03:00
2023-07-27 02:03:08 -03:00
blimp.loiter->run(target_pos, target_yaw, Vector4b{false,false,false,false});
2021-06-18 01:40:01 -03:00
}