Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
guidance_flip.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
3  * 2015 Ewoud Smeur
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
32 #include "guidance_flip.h"
33 
34 #include "autopilot.h"
35 #include "guidance_h.h"
37 #include "stabilization/stabilization_attitude.h"
38 
39 #ifndef STOP_ROLL_CMD_ANGLE
40 #define STOP_ROLL_CMD_ANGLE 25.0
41 #endif
42 #ifndef FIRST_THRUST_DURATION
43 #define FIRST_THRUST_DURATION 0.3
44 #endif
45 #ifndef FINAL_THRUST_LEVEL
46 #define FINAL_THRUST_LEVEL 6000
47 #endif
48 
55 
57 {
58  flip_counter = 0;
59  flip_state = 0;
60  flip_rollout = false;
63 }
64 
66 {
67 #if defined(COMMAND_ROLL) && defined(COMMAND_PITCH) && defined(COMMAND_YAW)
68 
69  uint32_t timer;
70  int32_t phi;
71  static uint32_t timer_save = 0;
72 
73  timer = (flip_counter++ << 12) / PERIODIC_FREQUENCY;
75 
76  switch (flip_state) {
77  case 0:
78  flip_cmd_earth.x = 0;
79  flip_cmd_earth.y = 0;
80  // FIXME maybe better remove the flip guidance
81  //stabilization_attitude_set_earth_cmd_i(&flip_cmd_earth,
82  // heading_save);
83  //stabilization_attitude_run(autopilot_in_flight());
84  stabilization.cmd[COMMAND_THRUST] = 8000; //Thrust to go up first
85  timer_save = 0;
86 
87  if (timer > BFP_OF_REAL(FIRST_THRUST_DURATION, 12)) {
88  flip_state++;
89  }
90  break;
91 
92  case 1:
93  stabilization.cmd[COMMAND_ROLL] = 9000; // Rolling command
94  stabilization.cmd[COMMAND_PITCH] = 0;
95  stabilization.cmd[COMMAND_YAW] = 0;
96  stabilization.cmd[COMMAND_THRUST] = 1000; //Min thrust?
97 
98  if (phi > ANGLE_BFP_OF_REAL(RadOfDeg(STOP_ROLL_CMD_ANGLE))) {
99  flip_state++;
100  }
101  break;
102 
103  case 2:
104  stabilization.cmd[COMMAND_ROLL] = 0;
105  stabilization.cmd[COMMAND_PITCH] = 0;
106  stabilization.cmd[COMMAND_YAW] = 0;
107  stabilization.cmd[COMMAND_THRUST] = 1000; //Min thrust?
108 
109  if (phi > ANGLE_BFP_OF_REAL(RadOfDeg(-110.0)) && phi < ANGLE_BFP_OF_REAL(RadOfDeg(STOP_ROLL_CMD_ANGLE))) {
110  timer_save = timer;
111  flip_state++;
112  }
113  break;
114 
115  case 3:
116  flip_cmd_earth.x = 0;
117  flip_cmd_earth.y = 0;
118  stabilization_attitude_set_earth_cmd_i(&flip_cmd_earth,
119  heading_save);
121 
122  stabilization.cmd[COMMAND_THRUST] = FINAL_THRUST_LEVEL; //Thrust to stop falling
123 
124  if ((timer - timer_save) > BFP_OF_REAL(0.5, 12)) {
125  flip_state++;
126  }
127  break;
128 
129  default:
133  flip_rollout = false;
134  flip_counter = 0;
135  timer_save = 0;
136  flip_state = 0;
137 
138  stabilization.cmd[COMMAND_ROLL] = 0;
139  stabilization.cmd[COMMAND_PITCH] = 0;
140  stabilization.cmd[COMMAND_YAW] = 0;
141  stabilization.cmd[COMMAND_THRUST] = 8000; //Some thrust to come out of the roll?
142  break;
143  }
144 #else
147 #endif
148 }
bool autopilot_set_mode(uint8_t new_autopilot_mode)
set autopilot mode
Definition: autopilot.c:193
uint8_t autopilot_get_mode(void)
get autopilot mode
Definition: autopilot.c:222
bool autopilot_in_flight(void)
get in_flight flag
Definition: autopilot.c:340
Core autopilot interface common to all firmwares.
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
#define ANGLE_BFP_OF_REAL(_af)
#define BFP_OF_REAL(_vr, _frac)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
#define FINAL_THRUST_LEVEL
Definition: guidance_flip.c:46
uint8_t flip_state
Definition: guidance_flip.c:50
void guidance_flip_run(void)
Definition: guidance_flip.c:65
uint32_t flip_counter
Definition: guidance_flip.c:49
int32_t heading_save
Definition: guidance_flip.c:52
uint8_t autopilot_mode_old
Definition: guidance_flip.c:53
#define STOP_ROLL_CMD_ANGLE
Definition: guidance_flip.c:40
bool flip_rollout
Definition: guidance_flip.c:51
void guidance_flip_enter(void)
Definition: guidance_flip.c:56
#define FIRST_THRUST_DURATION
Definition: guidance_flip.c:43
struct Int32Vect2 flip_cmd_earth
Definition: guidance_flip.c:54
Open Loop guidance for making a flip.
uint8_t autopilot_mode_auto2
Horizontal guidance for rotorcrafts.
void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Attitude control run function.
struct Stabilization stabilization
Definition: stabilization.c:41
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
int32_t stabilization_attitude_get_heading_i(void)
Get attitude heading as int (avoiding jumps)
Read an attitude setpoint from the RC.
struct Int32Eulers stab_att_sp_euler
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98