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 
34 
36 {
38 }
39 
41 {
42  // nothing to do
43 }
44 
45 static struct VerticalGuidance *_gv = &guidance_v;
47 
48 struct StabilizationSetpoint guidance_h_run_pos(bool in_flight, struct HorizontalGuidance *gh)
49 {
51 }
52 
53 struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
54 {
56 }
57 
58 struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
59 {
61 }
62 
63 struct ThrustSetpoint guidance_v_run_pos(bool in_flight UNUSED, struct VerticalGuidance *gv)
64 {
65  _gv = gv;
67  return thrust_sp; // nothing to do
68 }
69 
70 struct ThrustSetpoint guidance_v_run_speed(bool in_flight UNUSED, struct VerticalGuidance *gv)
71 {
72  _gv = gv;
74  return thrust_sp; // nothing to do
75 }
76 
77 struct ThrustSetpoint guidance_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv)
78 {
79  _gv = gv;
81  return thrust_sp;; // nothing to do
82 }
83 
84 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)
85 {
86  struct FloatVect3 PSA_des = { 0 };
87  int rm_order_h = 3;
88  int rm_order_v = 3;
89  // Oneloop controller wants desired targets and handles reference generation internally
90  if (h_mode == GUIDANCE_ONELOOP_H_POS) {
91  PSA_des.x = POS_FLOAT_OF_BFP(gh->sp.pos.x);
92  PSA_des.y = POS_FLOAT_OF_BFP(gh->sp.pos.y);
93  rm_order_h = 3;
94  }
95  else if (h_mode == GUIDANCE_ONELOOP_H_SPEED) {
96  PSA_des.x = SPEED_FLOAT_OF_BFP(gh->sp.speed.x);
97  PSA_des.y = SPEED_FLOAT_OF_BFP(gh->sp.speed.y);
98  PSA_des.z = SPEED_FLOAT_OF_BFP(gv->zd_sp);
99  rm_order_h = 2;
100  }
101  else { // H_ACCEL
102  PSA_des.x = ACCEL_FLOAT_OF_BFP(gh->ref.accel.x);
103  PSA_des.y = ACCEL_FLOAT_OF_BFP(gh->ref.accel.y);
104  PSA_des.z = ACCEL_FLOAT_OF_BFP(gv->zdd_ref);
105  rm_order_h = 1;
106  }
107 
108  if (v_mode == GUIDANCE_ONELOOP_V_POS){
109  PSA_des.z = POS_FLOAT_OF_BFP(gv->z_sp);
110  rm_order_v = 3;
111  }
112  else if (v_mode == GUIDANCE_ONELOOP_V_SPEED) {
113  PSA_des.z = SPEED_FLOAT_OF_BFP(gv->zd_sp);
114  rm_order_v = 2;
115  }
116  else { // H_ACCEL
117  PSA_des.z = ACCEL_FLOAT_OF_BFP(gv->zdd_ref); //why is there not acceleration SP and only REF?
118  rm_order_v = 1;
119  }
120  oneloop_andi.half_loop = false;
121  oneloop_andi_run(in_flight, oneloop_andi.half_loop, PSA_des, rm_order_h, rm_order_v);
122  struct StabilizationSetpoint sp = { 0 };
123  return sp;
124 }
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 ThrustSetpoint guidance_v_run_pos(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct StabilizationSetpoint guidance_h_run_speed(bool in_flight, struct HorizontalGuidance *gh)
struct ThrustSetpoint guidance_v_run_speed(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct ThrustSetpoint thrust_sp
struct ThrustSetpoint guidance_v_run_accel(bool in_flight UNUSED, struct VerticalGuidance *gv)
struct StabilizationSetpoint guidance_h_run_accel(bool in_flight, struct HorizontalGuidance *gh)
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_enter(bool half_loop_sp, int ctrl_type)
Function that resets important values upon engaging Oneloop ANDI.
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:325
#define CTRL_ANDI
Control types.
Definition: oneloop_andi.h:57
Horizontal guidance for rotorcrafts.
struct VerticalGuidance guidance_v
Definition: guidance_v.c:60
Vertical guidance for rotorcrafts.
int32_t z_sp
altitude setpoint in meters (input).
Definition: guidance_v.h:50
int32_t zd_sp
vertical speed setpoint in meter/s (input).
Definition: guidance_v.h:56
int32_t zdd_ref
vertical acceleration reference in meter/s^2.
Definition: guidance_v.h:74
Stabilization setpoint.
Definition: stabilization.h:53
union StabilizationSetpoint::@278 sp
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
Definition: stabilization.h:82