Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
stabilization_attitude_passthrough.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2013 Freek van Tienen
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 
31 #include "state.h"
35 #include "paparazzi.h"
36 
37 #include "generated/airframe.h"
38 
39 #define TRAJ_MAX_BANK (int32_t)ANGLE_BFP_OF_REAL(GUIDANCE_H_MAX_BANK)
40 
42 
43 
45 {
47 }
48 
49 void stabilization_attitude_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
50 {
51  //Read from RC
52  stabilization_attitude_read_rc_setpoint_eulers(&stab_att_sp_euler, in_flight, in_carefree, coordinated_turn);
53 }
54 
56 {
57 
58 }
59 
60 void stabilization_attitude_run(bool in_flight __attribute__((unused)))
61 {
62 
63  /* For roll and pitch we pass trough the desired angles as stabilization command */
64  const int32_t angle2cmd = (MAX_PPRZ / TRAJ_MAX_BANK);
65  stabilization_cmd[COMMAND_ROLL] = stab_att_sp_euler.phi * angle2cmd;
66  stabilization_cmd[COMMAND_PITCH] = stab_att_sp_euler.theta * angle2cmd;
67 
68  //TODO: Fix yaw with PID controller
70  INT32_ANGLE_NORMALIZE(yaw_error);
71  // stabilization_cmd[COMMAND_YAW] = yaw_error * MAX_PPRZ / INT32_ANGLE_PI;
72 
73  /* bound the result */
74  BoundAbs(stabilization_cmd[COMMAND_ROLL], MAX_PPRZ);
75  BoundAbs(stabilization_cmd[COMMAND_PITCH], MAX_PPRZ);
76  BoundAbs(stabilization_cmd[COMMAND_YAW], MAX_PPRZ);
77 }
78 
80 {
84 }
85 
87 {
88  stab_att_sp_euler = *rpy;
89 }
90 
92 {
93  /* Rotate horizontal commands to body frame by psi */
95  int32_t s_psi, c_psi;
96  PPRZ_ITRIG_SIN(s_psi, psi);
97  PPRZ_ITRIG_COS(c_psi, psi);
98  stab_att_sp_euler.phi = (-s_psi * cmd->x + c_psi * cmd->y) >> INT32_TRIG_FRAC;
99  stab_att_sp_euler.theta = -(c_psi * cmd->x + s_psi * cmd->y) >> INT32_TRIG_FRAC;
101 }
Int32Eulers::theta
int32_t theta
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:148
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
stabilization_attitude_set_earth_cmd_i
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
Definition: stabilization_attitude_passthrough.c:91
stabilization_attitude.h
stabilization_attitude_set_rpy_setpoint_i
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
Definition: stabilization_attitude_passthrough.c:86
stabilization_attitude_read_rc
void stabilization_attitude_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
Definition: stabilization_attitude_passthrough.c:49
Int32Vect2::y
int32_t y
Definition: pprz_algebra_int.h:85
PPRZ_ITRIG_COS
#define PPRZ_ITRIG_COS(_c, _a)
Definition: pprz_trig_int.h:110
INT_EULERS_ZERO
#define INT_EULERS_ZERO(_e)
Definition: pprz_algebra_int.h:549
paparazzi.h
Int32Vect2::x
int32_t x
Definition: pprz_algebra_int.h:84
Int32Eulers::psi
int32_t psi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:149
Int32Eulers::phi
int32_t phi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:147
stab_att_sp_euler
struct Int32Eulers stab_att_sp_euler
with INT32_ANGLE_FRAC
Definition: stabilization_attitude_passthrough.c:41
Int32Vect2
Definition: pprz_algebra_int.h:83
stabilization_attitude_rc_setpoint.h
Int32Eulers
euler angles
Definition: pprz_algebra_int.h:146
TRAJ_MAX_BANK
#define TRAJ_MAX_BANK
Definition: stabilization_attitude_passthrough.c:39
stabilization_attitude_enter
void stabilization_attitude_enter(void)
Definition: stabilization_attitude_passthrough.c:55
int32_t
signed long int32_t
Definition: types.h:19
stabilization_attitude_read_rc_setpoint_eulers
void stabilization_attitude_read_rc_setpoint_eulers(struct Int32Eulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
Read attitude setpoint from RC as euler angles.
Definition: stabilization_attitude_rc_setpoint.c:173
stabilization_attitude_set_failsafe_setpoint
void stabilization_attitude_set_failsafe_setpoint(void)
Definition: stabilization_attitude_passthrough.c:79
stabilization_attitude_init
void stabilization_attitude_init(void)
stabilization_attitude_init
Definition: stabilization_attitude_passthrough.c:44
stabilization_cmd
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:32
stabilization_attitude_run
void stabilization_attitude_run(bool in_flight)
Definition: stabilization_attitude_passthrough.c:60
stateGetNedToBodyEulers_i
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
stabilization.h
state.h
INT32_TRIG_FRAC
#define INT32_TRIG_FRAC
Definition: pprz_algebra_int.h:154
INT32_ANGLE_NORMALIZE
#define INT32_ANGLE_NORMALIZE(_a)
Definition: pprz_algebra_int.h:126
heading
float heading
Definition: wedgebug.c:258
PPRZ_ITRIG_SIN
#define PPRZ_ITRIG_SIN(_s, _a)
Definition: pprz_trig_int.h:109