Paparazzi UAS  v7.0_unstable
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 
32 #include "state.h"
33 #include "paparazzi.h"
35 #include "generated/airframe.h"
36 
37 #define TRAJ_MAX_BANK (int32_t)ANGLE_BFP_OF_REAL(GUIDANCE_H_MAX_BANK)
38 
40 {
41 }
42 
43 void stabilization_attitude_run(bool in_flight __attribute__((unused)), struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
44 {
45  struct Int32Eulers sp_euler = stab_sp_to_eulers_i(sp);
46 
47  /* For roll and pitch we pass trough the desired angles as stabilization command */
48  const int32_t angle2cmd = (MAX_PPRZ / TRAJ_MAX_BANK);
49  cmd[COMMAND_ROLL] = sp_euler.phi * angle2cmd;
50  cmd[COMMAND_PITCH] = sp_euler.theta * angle2cmd;
51  cmd[COMMAND_THRUST] = th_sp_to_thrust_i(thrust, 0, THRUST_AXIS_Z);
52 
53  //TODO: Fix yaw with PID controller
54  int32_t yaw_error = stateGetNedToBodyEulers_i()->psi - sp_euler.psi;
55  INT32_ANGLE_NORMALIZE(yaw_error);
56  // cmd[COMMAND_YAW] = yaw_error * MAX_PPRZ / INT32_ANGLE_PI;
57 
58  /* bound the result */
59  BoundAbs(cmd[COMMAND_ROLL], MAX_PPRZ);
60  BoundAbs(cmd[COMMAND_PITCH], MAX_PPRZ);
61  BoundAbs(cmd[COMMAND_YAW], MAX_PPRZ);
62  BoundAbs(cmd[COMMAND_THRUST], MAX_PPRZ);
63 }
64 
int32_t phi
in rad with INT32_ANGLE_FRAC
int32_t psi
in rad with INT32_ANGLE_FRAC
int32_t theta
in rad with INT32_ANGLE_FRAC
#define INT32_ANGLE_NORMALIZE(_a)
euler angles
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
#define MAX_PPRZ
Definition: paparazzi.h:8
struct Int32Eulers stab_sp_to_eulers_i(struct StabilizationSetpoint *sp)
int32_t th_sp_to_thrust_i(struct ThrustSetpoint *th, int32_t thrust, uint8_t axis)
General stabilization interface for rotorcrafts.
#define THRUST_AXIS_Z
void stabilization_attitude_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Attitude control run function.
void stabilization_attitude_enter(void)
Attitude control enter function.
API to get/set the generic vehicle states.
Stabilization setpoint.
Definition: stabilization.h:53
Thrust setpoint // TODO to a setpoint header Structure to store the desired thrust vector with differ...
Definition: stabilization.h:82
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83