Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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
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
96 stabilization.cmd[COMMAND_THRUST] = 1000; //Min thrust?
97
99 flip_state++;
100 }
101 break;
102
103 case 2:
107 stabilization.cmd[COMMAND_THRUST] = 1000; //Min thrust?
108
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;
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
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.
float psi
in radians
int32_t phi
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:1288
#define FINAL_THRUST_LEVEL
uint8_t flip_state
void guidance_flip_run(void)
uint32_t flip_counter
int32_t heading_save
uint8_t autopilot_mode_old
#define STOP_ROLL_CMD_ANGLE
bool flip_rollout
void guidance_flip_enter(void)
#define FIRST_THRUST_DURATION
struct Int32Vect2 flip_cmd_earth
Open Loop guidance for making a flip.
uint16_t foo
Definition main_demo5.c:58
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
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
static struct FloatEulers stab_att_sp_euler
int32_t stabilization_attitude_get_heading_i(void)
Get attitude heading as int (avoiding jumps)
Read an attitude setpoint from the RC.
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.