Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
guidance_oneloop.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Tomaso De Ponti <t.m.l.deponti@tudelft.nl>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
33 
35 {
36  oneloop_andi_enter(false);
37 }
38 
40 {
41  // nothing to do
42 }
43 
44 static struct VerticalGuidance *_gv = &guidance_v;
46 
47 struct StabilizationSetpoint guidance_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
48 {
50 }
51 
52 struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
53 {
55 }
56 
57 struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
58 {
60 }
61 
63 {
64  _gv = gv;
66  return 0; // nothing to do
67 }
68 
70 {
71  _gv = gv;
73  return 0; // nothing to do
74 }
75 
77 {
78  _gv = gv;
80  return 0; // nothing to do
81 }
82 
83 struct StabilizationSetpoint guidance_oneloop_run_mode(bool in_flight, struct HorizontalGuidance *gh, struct VerticalGuidance *gv, enum GuidanceOneloop_HMode h_mode, enum GuidanceOneloop_VMode v_mode)
84 {
85  struct FloatVect3 PSA_des = { 0 };
86  int rm_order_h = 3;
87  int rm_order_v = 3;
88  // Oneloop controller wants desired targets and handles reference generation internally
89  if (h_mode == GUIDANCE_ONELOOP_H_POS) {
90  PSA_des.x = POS_FLOAT_OF_BFP(gh->sp.pos.x);
91  PSA_des.y = POS_FLOAT_OF_BFP(gh->sp.pos.y);
92  rm_order_h = 3;
93  }
94  else if (h_mode == GUIDANCE_ONELOOP_H_SPEED) {
95  PSA_des.x = SPEED_FLOAT_OF_BFP(gh->sp.speed.x);
96  PSA_des.y = SPEED_FLOAT_OF_BFP(gh->sp.speed.y);
97  PSA_des.z = SPEED_FLOAT_OF_BFP(gv->zd_sp);
98  rm_order_h = 2;
99  }
100  else { // H_ACCEL
101  PSA_des.x = ACCEL_FLOAT_OF_BFP(gh->ref.accel.x);
102  PSA_des.y = ACCEL_FLOAT_OF_BFP(gh->ref.accel.y);
103  PSA_des.z = ACCEL_FLOAT_OF_BFP(gv->zdd_ref);
104  rm_order_h = 1;
105  }
106 
107  if (v_mode == GUIDANCE_ONELOOP_V_POS){
108  PSA_des.z = POS_FLOAT_OF_BFP(gv->z_sp);
109  rm_order_v = 3;
110  }
111  else if (v_mode == GUIDANCE_ONELOOP_V_SPEED) {
112  PSA_des.z = SPEED_FLOAT_OF_BFP(gv->zd_sp);
113  rm_order_v = 2;
114  }
115  else { // H_ACCEL
116  PSA_des.z = ACCEL_FLOAT_OF_BFP(gv->zdd_ref); //why is there not acceleration SP and only REF?
117  rm_order_v = 1;
118  }
119  oneloop_andi.half_loop = false;
120  oneloop_andi_run(in_flight, oneloop_andi.half_loop, PSA_des, rm_order_h, rm_order_v);
121  struct StabilizationSetpoint sp = { 0 };
122  return sp;
123 }
uint8_t last_wp UNUSED
#define POS_FLOAT_OF_BFP(_ai)
#define SPEED_FLOAT_OF_BFP(_ai)
#define ACCEL_FLOAT_OF_BFP(_ai)
void guidance_h_run_enter(void)
static enum GuidanceOneloop_VMode _v_mode
struct StabilizationSetpoint guidance_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
struct StabilizationSetpoint guidance_oneloop_run_mode(bool in_flight, struct HorizontalGuidance *gh, struct VerticalGuidance *gv, enum GuidanceOneloop_HMode h_mode, enum GuidanceOneloop_VMode v_mode)
void guidance_v_run_enter(void)
static struct VerticalGuidance * _gv
struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
int32_t guidance_v_run_speed(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
int32_t guidance_v_run_pos(bool in_flight UNUSED, struct VerticalGuidance *gv)
int32_t guidance_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv)
A dummy guidance mode to run the oneloop_andi controller.
GuidanceOneloop_HMode
@ GUIDANCE_ONELOOP_H_ACCEL
@ GUIDANCE_ONELOOP_H_POS
@ GUIDANCE_ONELOOP_H_SPEED
GuidanceOneloop_VMode
@ GUIDANCE_ONELOOP_V_POS
@ GUIDANCE_ONELOOP_V_SPEED
@ GUIDANCE_ONELOOP_V_ACCEL
void oneloop_andi_run(bool in_flight, bool half_loop, struct FloatVect3 PSA_des, int rm_order_h, int rm_order_v)
Main function that runs the controller and performs control allocation.
struct OneloopGeneral oneloop_andi
Definition: oneloop_andi.c:384
void oneloop_andi_enter(bool half_loop_sp)
Function that resets important values upon engaging Oneloop ANDI.
Horizontal guidance for rotorcrafts.
struct VerticalGuidance guidance_v
Definition: guidance_v.c:59
Vertical guidance for rotorcrafts.
int32_t z_sp
altitude setpoint in meters (input).
Definition: guidance_v.h:51
int32_t zd_sp
vertical speed setpoint in meter/s (input).
Definition: guidance_v.h:57
int32_t zdd_ref
vertical acceleration reference in meter/s^2.
Definition: guidance_v.h:75
Stabilization setpoint.
Definition: stabilization.h:42
union StabilizationSetpoint::@278 sp
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83