Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
stabilization_rate_indi.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Freek van Tienen <freek.v.tienen@gmail.com>
3  * 2020 Rohan Chotalal
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 
29 
30 #ifdef STABILIZATION_ATTITUDE_INDI_SIMPLE
32 #else
34 #endif
35 
37 
38 /* -- define variables */
40 
42 #ifndef STABILIZATION_INDI_MAX_RATE
43 #define STABILIZATION_INDI_MAX_RATE 6.0
44 #endif
45 
46 #if PERIODIC_TELEMETRY
48 
49 static void send_rate(struct transport_tx *trans, struct link_device *dev)
50 {
51  float dummy = 0;
52  float fb_p = stabilization.cmd[COMMAND_ROLL];
53  float fb_q = stabilization.cmd[COMMAND_PITCH];
54  float fb_r = stabilization.cmd[COMMAND_YAW];
55 
56  pprz_msg_send_RATE_LOOP(trans, dev, AC_ID,
60  &dummy, &dummy, &dummy,
61  &fb_p,
62  &fb_q,
63  &fb_r,
64  &stabilization.cmd[COMMAND_THRUST]);
65 }
66 #endif
67 
72 {
74  // indi init is already done through module init
75 
76 #if PERIODIC_TELEMETRY
77  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_RATE_LOOP, send_rate);
78 #endif
79 }
80 
85 {
87 }
88 
92 void stabilization_rate_run(bool in_flight, struct StabilizationSetpoint *rate_sp, struct ThrustSetpoint *thrust, int32_t *cmd)
93 {
95 
96  /* compute the INDI rate command */
97  stabilization_indi_rate_run(in_flight, rate_sp, thrust, cmd);
98 }
99 
101 {
102  struct FloatRates rate_sp;
103  FLOAT_RATES_ZERO(rate_sp);
104  if (ROLL_RATE_DEADBAND_EXCEEDED(rc)) {
105  rate_sp.p = rc->values[RC_RATE_P] * STABILIZATION_INDI_MAX_RATE / MAX_PPRZ;
106  }
108  rate_sp.q = rc->values[RC_RATE_Q] * STABILIZATION_INDI_MAX_RATE / MAX_PPRZ;
109  }
111  rate_sp.r = rc->values[RC_RATE_R] * STABILIZATION_INDI_MAX_RATE / MAX_PPRZ;
112  }
113  return stab_sp_from_rates_f(&rate_sp);
114 }
115 
float q
in rad/s
float p
in rad/s
float r
in rad/s
#define FLOAT_RATES_ZERO(_r)
angular rates
#define MAX_PPRZ
Definition: paparazzi.h:8
Some helper functions to check RC sticks.
#define THROTTLE_STICK_DOWN_FROM_RC(_rc)
struct Stabilization stabilization
Definition: stabilization.c:41
struct FloatRates stab_sp_to_rates_f(struct StabilizationSetpoint *sp)
struct StabilizationSetpoint stab_sp_from_rates_f(struct FloatRates *rates)
General stabilization interface for rotorcrafts.
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
void stabilization_indi_enter(void)
Function that resets important values upon engaging INDI.
void stabilization_indi_rate_run(bool in_flight, struct StabilizationSetpoint *sp, struct ThrustSetpoint *thrust, int32_t *cmd)
#define RC_RATE_R
#define RC_RATE_Q
#define YAW_RATE_DEADBAND_EXCEEDED(_rc)
#define RC_RATE_P
#define ROLL_RATE_DEADBAND_EXCEEDED(_rc)
#define PITCH_RATE_DEADBAND_EXCEEDED(_rc)
void stabilization_rate_enter(void)
Reset rate controller.
struct StabilizationSetpoint stabilization_rate_read_rc(struct RadioControl *rc)
void stabilization_rate_run(bool in_flight, struct StabilizationSetpoint *rate_sp, struct ThrustSetpoint *thrust, int32_t *cmd)
Run indi rate interface from the "stabilization_rate_run" function.
#define STABILIZATION_INDI_MAX_RATE
Maximum rate you can request in RC rate mode (rad/s)
static void send_rate(struct transport_tx *trans, struct link_device *dev)
struct FloatRates stabilization_rate_sp
void stabilization_rate_init(void)
Initialize rate controller.
Rate stabilization for rotorcrafts based on INDI.
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
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
struct tag_tracking_public dummy
Definition: tag_tracking.c:202
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83