Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
guidance_v.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
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 
27 #include "generated/airframe.h"
30 
35 
36 #include "state.h"
37 
38 #include "math/pprz_algebra_int.h"
39 
40 
41 /* error if some gains are negative */
42 #if (GUIDANCE_V_HOVER_KP < 0) || \
43  (GUIDANCE_V_HOVER_KD < 0) || \
44  (GUIDANCE_V_HOVER_KI < 0)
45 #error "ALL control gains must be positive!!!"
46 #endif
47 
48 
49 /* If only GUIDANCE_V_NOMINAL_HOVER_THROTTLE is defined,
50  * disable the adaptive throttle estimation by default.
51  * Otherwise enable adaptive estimation by default.
52  */
53 #ifdef GUIDANCE_V_NOMINAL_HOVER_THROTTLE
54 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
55 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED FALSE
56 # endif
57 #else
58 # define GUIDANCE_V_NOMINAL_HOVER_THROTTLE 0.4
59 # ifndef GUIDANCE_V_ADAPT_THROTTLE_ENABLED
60 # define GUIDANCE_V_ADAPT_THROTTLE_ENABLED TRUE
61 # endif
62 #endif
63 PRINT_CONFIG_VAR(GUIDANCE_V_NOMINAL_HOVER_THROTTLE)
64 PRINT_CONFIG_VAR(GUIDANCE_V_ADAPT_THROTTLE_ENABLED)
65 
66 
67 #ifndef GUIDANCE_V_CLIMB_RC_DEADBAND
68 #define GUIDANCE_V_CLIMB_RC_DEADBAND MAX_PPRZ/10
69 #endif
70 
71 #ifndef GUIDANCE_V_MAX_RC_CLIMB_SPEED
72 #define GUIDANCE_V_MAX_RC_CLIMB_SPEED GUIDANCE_V_REF_MIN_ZD
73 #endif
74 
75 #ifndef GUIDANCE_V_MAX_RC_DESCENT_SPEED
76 #define GUIDANCE_V_MAX_RC_DESCENT_SPEED GUIDANCE_V_REF_MAX_ZD
77 #endif
78 
79 #ifndef GUIDANCE_V_MIN_ERR_Z
80 #define GUIDANCE_V_MIN_ERR_Z POS_BFP_OF_REAL(-10.)
81 #endif
82 
83 #ifndef GUIDANCE_V_MAX_ERR_Z
84 #define GUIDANCE_V_MAX_ERR_Z POS_BFP_OF_REAL(10.)
85 #endif
86 
87 #ifndef GUIDANCE_V_MIN_ERR_ZD
88 #define GUIDANCE_V_MIN_ERR_ZD SPEED_BFP_OF_REAL(-10.)
89 #endif
90 
91 #ifndef GUIDANCE_V_MAX_ERR_ZD
92 #define GUIDANCE_V_MAX_ERR_ZD SPEED_BFP_OF_REAL(10.)
93 #endif
94 
95 #ifndef GUIDANCE_V_MAX_SUM_ERR
96 #define GUIDANCE_V_MAX_SUM_ERR 2000000
97 #endif
98 
99 #ifndef GUIDANCE_V_MAX_CMD
100 #define GUIDANCE_V_MAX_CMD 0.9*MAX_PPRZ
101 #endif
102 
107 
110 static bool desired_zd_updated;
111 
112 #define GUIDANCE_V_GUIDED_MODE_ZHOLD 0
113 #define GUIDANCE_V_GUIDED_MODE_CLIMB 1
114 #define GUIDANCE_V_GUIDED_MODE_THROTTLE 2
115 
117 
122 
128 
135 
139 
141 
143 
144 
146 
147 #if PERIODIC_TELEMETRY
149 
150 static void send_vert_loop(struct transport_tx *trans, struct link_device *dev)
151 {
152  pprz_msg_send_VERT_LOOP(trans, dev, AC_ID,
153  &guidance_v_z_sp, &guidance_v_zd_sp,
154  &(stateGetPositionNed_i()->z),
155  &(stateGetSpeedNed_i()->z),
156  &(stateGetAccelNed_i()->z),
157  &guidance_v_z_ref, &guidance_v_zd_ref,
158  &guidance_v_zdd_ref,
159  &gv_adapt_X,
160  &gv_adapt_P,
162  &guidance_v_z_sum_err,
163  &guidance_v_ff_cmd,
164  &guidance_v_fb_cmd,
165  &guidance_v_delta_t);
166 }
167 
168 static void send_tune_vert(struct transport_tx *trans, struct link_device *dev)
169 {
170  pprz_msg_send_TUNE_VERT(trans, dev, AC_ID,
171  &guidance_v_z_sp,
172  &(stateGetPositionNed_i()->z),
173  &guidance_v_z_ref,
174  &guidance_v_zd_ref);
175 }
176 #endif
177 
178 void guidance_v_init(void)
179 {
180 
181  guidance_v_mode = GUIDANCE_V_MODE_KILL;
182 
183  guidance_v_kp = GUIDANCE_V_HOVER_KP;
184  guidance_v_kd = GUIDANCE_V_HOVER_KD;
185  guidance_v_ki = GUIDANCE_V_HOVER_KI;
186 
187  guidance_v_z_sum_err = 0;
188 
189  guidance_v_nominal_throttle = GUIDANCE_V_NOMINAL_HOVER_THROTTLE;
190  guidance_v_adapt_throttle_enabled = GUIDANCE_V_ADAPT_THROTTLE_ENABLED;
191  desired_zd_updated = false;
192  guidance_v_guided_mode = GUIDANCE_V_GUIDED_MODE_ZHOLD;
193 
194  guidance_v_thrust_coeff = BFP_OF_REAL(1.f, INT32_TRIG_FRAC);
195 
196  gv_adapt_init();
197 
198 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
200 #endif
201 
202 #if PERIODIC_TELEMETRY
205 #endif
206 }
207 
208 
210 {
211 
212  /* used in RC_DIRECT directly and as saturation in CLIMB and HOVER */
213  guidance_v_rc_delta_t = (int32_t)radio_control.values[RADIO_THROTTLE];
214 
215  /* used in RC_CLIMB */
216  guidance_v_rc_zd_sp = (MAX_PPRZ / 2) - (int32_t)radio_control.values[RADIO_THROTTLE];
217  DeadBand(guidance_v_rc_zd_sp, GUIDANCE_V_CLIMB_RC_DEADBAND);
218 
219  static const int32_t climb_scale = ABS(SPEED_BFP_OF_REAL(GUIDANCE_V_MAX_RC_CLIMB_SPEED) /
221  static const int32_t descent_scale = ABS(SPEED_BFP_OF_REAL(GUIDANCE_V_MAX_RC_DESCENT_SPEED) /
223 
224  if (guidance_v_rc_zd_sp > 0) {
225  guidance_v_rc_zd_sp *= descent_scale;
226  } else {
227  guidance_v_rc_zd_sp *= climb_scale;
228  }
229 }
230 
232 {
233 
234  if (new_mode == guidance_v_mode) {
235  return;
236  }
237 
238  switch (new_mode) {
242  break;
243 
246  guidance_v_zd_sp = 0;
247  /* Falls through. */
248  case GUIDANCE_V_MODE_NAV:
249  guidance_v_z_sum_err = 0;
251  break;
252 
253 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
256  break;
257 #endif
258 
260  break;
261 
262  default:
263  break;
264 
265  }
266 
267  guidance_v_mode = new_mode;
268 
269 }
270 
271 void guidance_v_notify_in_flight(bool in_flight)
272 {
273  if (in_flight) {
274  gv_adapt_init();
275  }
276 }
277 
278 void guidance_v_thrust_adapt(bool in_flight)
279 {
280  guidance_v_thrust_coeff = get_vertical_thrust_coeff();
281 
282  if (in_flight) {
283  /* Only run adaptive throttle estimation if we are in flight and
284  * the desired vertical velocity (zd) was updated (i.e. we ran hover_loop before).
285  * This means that the estimation is not updated when using direct throttle commands.
286  *
287  * FIXME... SATURATIONS NOT TAKEN INTO ACCOUNT, AKA SUPERVISION and co
288  */
289  if (desired_zd_updated) {
290  int32_t vertical_thrust = (stabilization_cmd[COMMAND_THRUST] * guidance_v_thrust_coeff) >> INT32_TRIG_FRAC;
291  gv_adapt_run(stateGetAccelNed_i()->z, vertical_thrust, guidance_v_zd_ref);
292  }
293  } else {
294  /* reset estimate while not in_flight */
295  gv_adapt_init();
296  }
297 }
298 
299 void guidance_v_run(bool in_flight)
300 {
301  guidance_v_thrust_adapt(in_flight);
302 
303  /* reset flag indicating if desired zd was updated */
304  desired_zd_updated = false;
305 
306  switch (guidance_v_mode) {
307 
309  guidance_v_z_sp = stateGetPositionNed_i()->z; // for display only
310  stabilization_cmd[COMMAND_THRUST] = guidance_v_rc_delta_t;
311  break;
312 
314  guidance_v_zd_sp = guidance_v_rc_zd_sp;
315  gv_update_ref_from_zd_sp(guidance_v_zd_sp, stateGetPositionNed_i()->z);
316  run_hover_loop(in_flight);
317  stabilization_cmd[COMMAND_THRUST] = guidance_v_delta_t;
318  break;
319 
321  gv_update_ref_from_zd_sp(guidance_v_zd_sp, stateGetPositionNed_i()->z);
322  run_hover_loop(in_flight);
323 #if !NO_RC_THRUST_LIMIT
324  /* use rc limitation if available */
325  if (radio_control.status == RC_OK) {
326  stabilization_cmd[COMMAND_THRUST] = Min(guidance_v_rc_delta_t, guidance_v_delta_t);
327  } else
328 #endif
329  stabilization_cmd[COMMAND_THRUST] = guidance_v_delta_t;
330  break;
331 
333  guidance_v_guided_mode = GUIDANCE_V_GUIDED_MODE_ZHOLD;
334  /* Falls through. */
336  guidance_v_guided_run(in_flight);
337  break;
338 
339 #if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
341  guidance_v_module_run(in_flight);
342  break;
343 #endif
344 
345  case GUIDANCE_V_MODE_NAV: {
346  guidance_v_from_nav(in_flight);
347  break;
348  }
349 
351  break;
352 
353  default:
354  break;
355  }
356 }
357 
358 
360 {
361  /* set current altitude as setpoint */
362  guidance_v_z_sp = stateGetPositionNed_i()->z;
363 
364  /* reset guidance reference */
365  guidance_v_z_sum_err = 0;
367 
368  /* reset speed setting */
369  guidance_v_zd_sp = 0;
370 }
371 
372 void guidance_v_set_ref(int32_t pos, int32_t speed, int32_t accel)
373 {
374  gv_set_ref(pos, speed, accel);
375  guidance_v_z_ref = pos;
376  guidance_v_zd_ref = speed;
377  guidance_v_zdd_ref = accel;
378 }
379 
380 
383 {
384  // cos(30°) = 0.8660254
385  static const int32_t max_bank_coef = BFP_OF_REAL(0.8660254f, INT32_TRIG_FRAC);
386 
387  struct Int32RMat *att = stateGetNedToBodyRMat_i();
388  /* thrust vector:
389  * int32_rmat_vmult(&thrust_vect, &att, &zaxis)
390  * same as last colum of rmat with INT32_TRIG_FRAC
391  * struct Int32Vect thrust_vect = {att.m[2], att.m[5], att.m[8]};
392  *
393  * Angle between two vectors v1 and v2:
394  * angle = acos(dot(v1, v2) / (norm(v1) * norm(v2)))
395  * since here both are already of unit length:
396  * angle = acos(dot(v1, v2))
397  * since we we want the cosine of the angle we simply need
398  * thrust_coeff = dot(v1, v2)
399  * also can be simplified considering: v1 is zaxis with (0,0,1)
400  * dot(v1, v2) = v1.z * v2.z = v2.z
401  */
402  int32_t coef = att->m[8];
403  if (coef < max_bank_coef) {
404  coef = max_bank_coef;
405  }
406  return coef;
407 }
408 
409 
410 #define FF_CMD_FRAC 18
411 
412 void run_hover_loop(bool in_flight)
413 {
414 
415  /* convert our reference to generic representation */
417  guidance_v_z_ref = (int32_t)tmp;
418  guidance_v_zd_ref = gv_zd_ref << (INT32_SPEED_FRAC - GV_ZD_REF_FRAC);
419  guidance_v_zdd_ref = gv_zdd_ref << (INT32_ACCEL_FRAC - GV_ZDD_REF_FRAC);
420  /* set flag to indicate that desired zd was updated */
421  desired_zd_updated = true;
422  /* compute the error to our reference */
423  int32_t err_z = guidance_v_z_ref - stateGetPositionNed_i()->z;
425  int32_t err_zd = guidance_v_zd_ref - stateGetSpeedNed_i()->z;
427 
428  if (in_flight) {
429  guidance_v_z_sum_err += err_z;
430  Bound(guidance_v_z_sum_err, -GUIDANCE_V_MAX_SUM_ERR, GUIDANCE_V_MAX_SUM_ERR);
431  } else {
432  guidance_v_z_sum_err = 0;
433  }
434 
435  /* our nominal command : (g + zdd)*m */
436  int32_t inv_m;
437  if (guidance_v_adapt_throttle_enabled) {
438  inv_m = gv_adapt_X >> (GV_ADAPT_X_FRAC - FF_CMD_FRAC);
439  } else {
440  /* use the fixed nominal throttle */
441  inv_m = BFP_OF_REAL(9.81 / (guidance_v_nominal_throttle * MAX_PPRZ), FF_CMD_FRAC);
442  }
443 
444  const int32_t g_m_zdd = (int32_t)BFP_OF_REAL(9.81, FF_CMD_FRAC) -
445  (guidance_v_zdd_ref << (FF_CMD_FRAC - INT32_ACCEL_FRAC));
446 
447  guidance_v_ff_cmd = g_m_zdd / inv_m;
448  /* feed forward command */
449  guidance_v_ff_cmd = (guidance_v_ff_cmd << INT32_TRIG_FRAC) / guidance_v_thrust_coeff;
450 
451 #if HYBRID_NAVIGATION
452  //FIXME: NOT USING FEEDFORWARD COMMAND BECAUSE OF QUADSHOT NAVIGATION
453  guidance_v_ff_cmd = guidance_v_nominal_throttle * MAX_PPRZ;
454 #endif
455 
456  /* bound the nominal command to GUIDANCE_V_MAX_CMD */
457  Bound(guidance_v_ff_cmd, 0, GUIDANCE_V_MAX_CMD);
458 
459 
460  /* our error feed back command */
461  /* z-axis pointing down -> positive error means we need less thrust */
462  guidance_v_fb_cmd = ((-guidance_v_kp * err_z) >> 7) +
463  ((-guidance_v_kd * err_zd) >> 16) +
464  ((-guidance_v_ki * guidance_v_z_sum_err) >> 16);
465 
466  guidance_v_delta_t = guidance_v_ff_cmd + guidance_v_fb_cmd;
467 
468  /* bound the result */
469  Bound(guidance_v_delta_t, 0, MAX_PPRZ);
470 
471 }
472 
473 void guidance_v_from_nav(bool in_flight)
474 {
476  guidance_v_z_sp = -nav_flight_altitude;
477  guidance_v_zd_sp = 0;
478  gv_update_ref_from_z_sp(guidance_v_z_sp);
479  run_hover_loop(in_flight);
480  } else if (vertical_mode == VERTICAL_MODE_CLIMB) {
481  guidance_v_z_sp = stateGetPositionNed_i()->z;
482  guidance_v_zd_sp = -nav_climb;
483  gv_update_ref_from_zd_sp(guidance_v_zd_sp, stateGetPositionNed_i()->z);
484  run_hover_loop(in_flight);
485  } else if (vertical_mode == VERTICAL_MODE_MANUAL) {
486  guidance_v_z_sp = stateGetPositionNed_i()->z;
487  guidance_v_zd_sp = stateGetSpeedNed_i()->z;
488  GuidanceVSetRef(guidance_v_z_sp, guidance_v_zd_sp, 0);
489  guidance_v_z_sum_err = 0;
490  guidance_v_delta_t = nav_throttle;
491  }
492 #if HYBRID_NAVIGATION
494 #else
495 #if !NO_RC_THRUST_LIMIT
496  /* use rc limitation if available */
497  if (radio_control.status == RC_OK) {
498  stabilization_cmd[COMMAND_THRUST] = Min(guidance_v_rc_delta_t, guidance_v_delta_t);
499  } else
500 #endif
501  stabilization_cmd[COMMAND_THRUST] = guidance_v_delta_t;
502 #endif
503 }
504 
506 {
507  /* disable vertical velocity setpoints */
508  guidance_v_guided_mode = GUIDANCE_V_GUIDED_MODE_ZHOLD;
509 
510  /* set current altitude as setpoint and reset speed setpoint */
511  guidance_v_z_sp = stateGetPositionNed_i()->z;
512  guidance_v_zd_sp = 0;
513 
514  /* reset guidance reference */
515  guidance_v_z_sum_err = 0;
517 }
518 
519 void guidance_v_guided_run(bool in_flight)
520 {
521  switch(guidance_v_guided_mode)
522  {
524  // Altitude Hold
525  guidance_v_zd_sp = 0;
526  gv_update_ref_from_z_sp(guidance_v_z_sp);
527  run_hover_loop(in_flight);
528  break;
530  // Climb
531  gv_update_ref_from_zd_sp(guidance_v_zd_sp, stateGetPositionNed_i()->z);
532  run_hover_loop(in_flight);
533  break;
535  // Throttle
536  guidance_v_z_sp = stateGetPositionNed_i()->z; // for display only
537  guidance_v_delta_t = guidance_v_th_sp;
538  break;
539  default:
540  break;
541  }
542 #if !NO_RC_THRUST_LIMIT
543  /* use rc limitation if available */
544  if (radio_control.status == RC_OK) {
545  stabilization_cmd[COMMAND_THRUST] = Min(guidance_v_rc_delta_t, guidance_v_delta_t);
546  } else
547 #endif
548  stabilization_cmd[COMMAND_THRUST] = guidance_v_delta_t;
549 }
550 
552 {
553  if (guidance_v_mode == GUIDANCE_V_MODE_GUIDED) {
554  /* disable vertical velocity setpoints */
555  guidance_v_guided_mode = GUIDANCE_V_GUIDED_MODE_ZHOLD;
556 
557  /* set altitude setpoint */
558  guidance_v_z_sp = POS_BFP_OF_REAL(z);
559 
560  /* reset speed setting */
561  guidance_v_zd_sp = 0;
562 
563  return true;
564  }
565  return false;
566 }
567 
569 {
570  if (guidance_v_mode == GUIDANCE_V_MODE_GUIDED) {
571  /* enable vertical velocity setpoints */
572  guidance_v_guided_mode = GUIDANCE_V_GUIDED_MODE_CLIMB;
573 
574  /* set speed setting */
575  guidance_v_zd_sp = SPEED_BFP_OF_REAL(vz);
576 
577  return true;
578  }
579  return false;
580 }
581 
583 {
584  if (guidance_v_mode == GUIDANCE_V_MODE_GUIDED) {
585  /* enable vertical velocity setpoints */
586  guidance_v_guided_mode = GUIDANCE_V_GUIDED_MODE_THROTTLE;
587 
588  /* reset guidance reference */
590  guidance_v_th_sp = (int32_t)(MAX_PPRZ * th);
591  Bound(guidance_v_th_sp, 0, MAX_PPRZ);
592  return true;
593  }
594  return false;
595 }
596 
597 
bool guidance_v_set_guided_z(float z)
Set z setpoint in GUIDED mode.
Definition: guidance_v.c:551
int32_t guidance_v_z_sp
altitude setpoint in meters (input).
Definition: guidance_v.c:129
bool guidance_v_set_guided_th(float th)
Definition: guidance_v.c:582
void guidance_v_guided_run(bool in_flight)
Run GUIDED mode control.
Definition: guidance_v.c:519
void guidance_hybrid_vertical(void)
Description.
#define GV_ZD_REF_FRAC
number of bits for the fractional part of gv_zd_ref
int32_t guidance_v_kd
vertical control D-gain
Definition: guidance_v.c:137
#define GUIDANCE_V_MODE_NAV
Definition: guidance_v.h:40
#define Min(x, y)
Definition: esc_dshot.c:85
static void send_vert_loop(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_v.c:150
bool guidance_v_set_guided_vz(float vz)
Set z velocity setpoint in GUIDED mode.
Definition: guidance_v.c:568
#define GUIDANCE_V_NOMINAL_HOVER_THROTTLE
Definition: guidance_v.c:58
#define GV_Z_REF_FRAC
number of bits for the fractional part of gv_z_ref
#define INT32_ACCEL_FRAC
#define INT32_SPEED_FRAC
int32_t guidance_v_fb_cmd
feed-back command
Definition: guidance_v.c:105
Periodic telemetry system header (includes downlink utility and generated code).
static struct Int32RMat * stateGetNedToBodyRMat_i(void)
Get vehicle body attitude rotation matrix (int).
Definition: state.h:1119
void guidance_v_set_ref(int32_t pos, int32_t speed, int32_t accel)
Set guidance ref parameters.
Definition: guidance_v.c:372
int32_t guidance_v_delta_t
thrust command.
Definition: guidance_v.c:106
uint8_t status
Definition: radio_control.h:64
#define GUIDANCE_V_GUIDED_MODE_ZHOLD
Definition: guidance_v.c:112
int32_t guidance_v_kp
vertical control P-gain
Definition: guidance_v.c:136
#define GV_ADAPT_X_FRAC
void guidance_v_init(void)
Definition: guidance_v.c:178
#define POS_BFP_OF_REAL(_af)
bool guidance_v_adapt_throttle_enabled
Use adaptive throttle command estimation.
Definition: guidance_v.c:109
#define GUIDANCE_V_MIN_ERR_Z
Definition: guidance_v.c:80
int32_t m[3 *3]
int32_t nav_flight_altitude
Definition: navigation.c:111
void guidance_v_mode_changed(uint8_t new_mode)
Definition: guidance_v.c:231
float guidance_v_nominal_throttle
nominal throttle for hover.
Definition: guidance_v.c:108
Vertical guidance for rotorcrafts.
void guidance_v_z_enter(void)
Definition: guidance_v.c:359
#define GV_ZDD_REF_FRAC
number of bits for the fractional part of gv_zdd_ref
void guidance_v_run(bool in_flight)
Definition: guidance_v.c:299
signed long long int64_t
Definition: types.h:21
int32_t guidance_v_z_sum_err
accumulator for I-gain
Definition: guidance_v.c:140
void guidance_v_notify_in_flight(bool in_flight)
Definition: guidance_v.c:271
Guidance controllers (horizontal and vertical) for Hybrid UAV configurations.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69
int32_t z
Down.
#define GUIDANCE_V_MODE_KILL
Definition: guidance_v.h:35
void run_hover_loop(bool in_flight)
Definition: guidance_v.c:412
int32_t guidance_v_rc_zd_sp
Vertical speed setpoint from radio control.
Definition: guidance_v.c:127
#define BFP_OF_REAL(_vr, _frac)
#define GuidanceVSetRef
Definition: guidance_v.h:120
void gv_update_ref_from_z_sp(int32_t z_sp)
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
Definition: state.h:863
int32_t guidance_v_ki
vertical control I-gain
Definition: guidance_v.c:138
#define GUIDANCE_V_MODE_MODULE
Definition: guidance_v.h:41
void gv_adapt_init(void)
#define GUIDANCE_V_MAX_RC_DESCENT_SPEED
Definition: guidance_v.c:76
#define GUIDANCE_V_MODE_CLIMB
Definition: guidance_v.h:38
int32_t gv_zd_ref
reference model vertical speed in meters/sec (output) fixed point representation with GV_ZD_REF_FRAC ...
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
int32_t guidance_v_zdd_ref
vertical acceleration reference in meter/s^2.
Definition: guidance_v.c:134
#define GUIDANCE_V_MAX_ERR_Z
Definition: guidance_v.c:84
#define GUIDANCE_V_MAX_CMD
Definition: guidance_v.c:100
#define GUIDANCE_V_MODE_HOVER
Definition: guidance_v.h:39
struct RadioControl radio_control
Definition: radio_control.c:30
void gv_adapt_run(int32_t zdd_meas, int32_t thrust_applied, int32_t zd_ref)
Adaptation function.
#define GUIDANCE_V_MAX_RC_CLIMB_SPEED
Definition: guidance_v.c:72
int32_t guidance_v_z_ref
altitude reference in meters.
Definition: guidance_v.c:132
void guidance_v_module_run(UNUSED bool in_flight)
#define INT32_POS_FRAC
#define RADIO_THROTTLE
Definition: intermcu_ap.h:40
void gv_update_ref_from_zd_sp(int32_t zd_sp, int32_t z_pos)
update vertical reference from speed setpoint.
int32_t guidance_v_zd_ref
vertical speed reference in meter/s.
Definition: guidance_v.c:133
int32_t guidance_v_th_sp
Definition: guidance_v.c:131
int32_t gv_adapt_P
Covariance.
signed long int32_t
Definition: types.h:19
#define RC_OK
Definition: radio_control.h:56
void guidance_v_guided_enter(void)
Enter GUIDED mode control.
Definition: guidance_v.c:505
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define INT32_TRIG_FRAC
void gv_set_ref(int32_t alt, int32_t speed, int32_t accel)
#define GUIDANCE_V_CLIMB_RC_DEADBAND
Definition: guidance_v.c:68
#define GUIDANCE_V_GUIDED_MODE_CLIMB
Definition: guidance_v.c:113
Rotorcraft navigation functions.
uint8_t guidance_v_mode
Definition: guidance_v.c:103
#define GUIDANCE_V_ADAPT_THROTTLE_ENABLED
Definition: guidance_v.c:60
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
void guidance_v_module_init(void)
int32_t gv_adapt_Xmeas
Measurement.
#define FF_CMD_FRAC
Definition: guidance_v.c:410
int32_t guidance_v_thrust_coeff
Definition: guidance_v.c:142
#define GUIDANCE_V_MIN_ERR_ZD
Definition: guidance_v.c:88
int64_t gv_z_ref
reference model altitude in meters (output) fixed point representation with GV_Z_REF_FRAC Q37...
static int32_t get_vertical_thrust_coeff(void)
get the cosine of the angle between thrust vector and gravity vector
Definition: guidance_v.c:382
General stabilization interface for rotorcrafts.
void guidance_v_read_rc(void)
Definition: guidance_v.c:209
#define GUIDANCE_V_GUIDED_MODE_THROTTLE
Definition: guidance_v.c:114
void guidance_v_module_enter(void)
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:32
#define GUIDANCE_V_MAX_ERR_ZD
Definition: guidance_v.c:92
#define VERTICAL_MODE_ALT
Definition: navigation.h:75
#define GUIDANCE_V_MODE_FLIP
Definition: guidance_v.h:42
static void send_tune_vert(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_v.c:168
Guidance in a module file.
int32_t guidance_v_zd_sp
vertical speed setpoint in meter/s (input).
Definition: guidance_v.c:130
#define GUIDANCE_V_MAX_SUM_ERR
Definition: guidance_v.c:96
int32_t guidance_v_rc_delta_t
Direct throttle from radio control.
Definition: guidance_v.c:121
rotation matrix
uint32_t nav_throttle
direct throttle from 0:MAX_PPRZ, used in VERTICAL_MODE_MANUAL
Definition: navigation.c:110
static bool desired_zd_updated
Definition: guidance_v.c:110
#define SPEED_BFP_OF_REAL(_af)
int32_t guidance_v_ff_cmd
feed-forward command
Definition: guidance_v.c:104
#define GUIDANCE_V_MODE_RC_CLIMB
Definition: guidance_v.h:37
#define MAX_PPRZ
Definition: paparazzi.h:8
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
Definition: state.h:665
#define VERTICAL_MODE_CLIMB
Definition: navigation.h:74
void guidance_v_thrust_adapt(bool in_flight)
Definition: guidance_v.c:278
#define GUIDANCE_V_MODE_RC_DIRECT
Definition: guidance_v.h:36
uint8_t vertical_mode
Definition: sim_ap.c:35
int32_t gv_adapt_X
State of the estimator.
#define VERTICAL_MODE_MANUAL
Definition: navigation.h:73
#define GUIDANCE_V_MODE_GUIDED
Definition: guidance_v.h:43
int32_t gv_zdd_ref
reference model vertical accel in meters/s^2 (output) fixed point representation with GV_ZDD_REF_FRAC...
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
int guidance_v_guided_mode
Definition: guidance_v.c:116
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
Definition: state.h:1020
Paparazzi fixed point algebra.
void guidance_v_from_nav(bool in_flight)
Set guidance setpoint from NAV and run hover loop.
Definition: guidance_v.c:473