Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
guidance_h.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"
28 
38 
42 
43 /* for guidance_v_thrust_coeff */
45 
46 #include "state.h"
47 
48 #ifndef GUIDANCE_H_AGAIN
49 #define GUIDANCE_H_AGAIN 0
50 #endif
51 
52 #ifndef GUIDANCE_H_VGAIN
53 #define GUIDANCE_H_VGAIN 0
54 #endif
55 
56 /* error if some gains are negative */
57 #if (GUIDANCE_H_PGAIN < 0) || \
58  (GUIDANCE_H_DGAIN < 0) || \
59  (GUIDANCE_H_IGAIN < 0) || \
60  (GUIDANCE_H_AGAIN < 0) || \
61  (GUIDANCE_H_VGAIN < 0)
62 #error "ALL control gains have to be positive!!!"
63 #endif
64 
65 #ifndef GUIDANCE_H_MAX_BANK
66 #define GUIDANCE_H_MAX_BANK RadOfDeg(20)
67 #endif
68 
69 PRINT_CONFIG_VAR(GUIDANCE_H_USE_REF)
70 PRINT_CONFIG_VAR(GUIDANCE_H_USE_SPEED_REF)
71 
72 #ifndef GUIDANCE_H_APPROX_FORCE_BY_THRUST
73 #define GUIDANCE_H_APPROX_FORCE_BY_THRUST FALSE
74 #endif
75 
76 #ifndef GUIDANCE_INDI
77 #define GUIDANCE_INDI FALSE
78 #endif
79 
81 
84 
85 /*
86  * internal variables
87  */
91 
97 
98 static void guidance_h_update_reference(void);
99 #if !GUIDANCE_INDI
100 static void guidance_h_traj_run(bool in_flight);
101 #endif
102 static inline void transition_run(bool to_forward);
103 static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight);
104 
105 #if PERIODIC_TELEMETRY
107 
108 static void send_gh(struct transport_tx *trans, struct link_device *dev)
109 {
110  struct NedCoor_i *pos = stateGetPositionNed_i();
111  pprz_msg_send_GUIDANCE_H_INT(trans, dev, AC_ID,
114  &(pos->x), &(pos->y));
115 }
116 
117 static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
118 {
119  struct NedCoor_i *pos = stateGetPositionNed_i();
120  struct NedCoor_i *speed = stateGetSpeedNed_i();
121  struct NedCoor_i *accel = stateGetAccelNed_i();
122  pprz_msg_send_HOVER_LOOP(trans, dev, AC_ID,
123  &guidance_h.sp.pos.x,
124  &guidance_h.sp.pos.y,
125  &(pos->x), &(pos->y),
126  &(speed->x), &(speed->y),
127  &(accel->x), &(accel->y),
137 }
138 
139 static void send_href(struct transport_tx *trans, struct link_device *dev)
140 {
141  pprz_msg_send_GUIDANCE_H_REF_INT(trans, dev, AC_ID,
147  &guidance_h.ref.accel.y);
148 }
149 
150 static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
151 {
152  pprz_msg_send_ROTORCRAFT_TUNE_HOVER(trans, dev, AC_ID,
156  &stabilization_cmd[COMMAND_ROLL],
157  &stabilization_cmd[COMMAND_PITCH],
158  &stabilization_cmd[COMMAND_YAW],
159  &stabilization_cmd[COMMAND_THRUST],
160  &(stateGetNedToBodyEulers_i()->phi),
161  &(stateGetNedToBodyEulers_i()->theta),
162  &(stateGetNedToBodyEulers_i()->psi));
163 }
164 
165 #endif
166 
167 void guidance_h_init(void)
168 {
169 
173 
177  guidance_h.sp.heading = 0.0;
178  guidance_h.sp.heading_rate = 0.0;
179  guidance_h.gains.p = GUIDANCE_H_PGAIN;
180  guidance_h.gains.i = GUIDANCE_H_IGAIN;
181  guidance_h.gains.d = GUIDANCE_H_DGAIN;
184  transition_percentage = 0;
185  transition_theta_offset = 0;
186 
187  gh_ref_init();
188 
189 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
191 #endif
192 
193 #if PERIODIC_TELEMETRY
194  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_GUIDANCE_H_INT, send_gh);
196  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_GUIDANCE_H_REF_INT, send_href);
197  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_TUNE_HOVER, send_tune_hover);
198 #endif
199 
200 }
201 
202 
204 {
209 
211 }
212 
214 {
215  if (new_mode == guidance_h.mode) {
216  return;
217  }
218 
219 #if HYBRID_NAVIGATION
221 #endif
222 
223  switch (new_mode) {
226  break;
227 
228 #if USE_STABILIZATION_RATE
231  break;
232 #endif
233 
238 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
239  /* reset attitude stabilization if previous mode was not using it */
243 #endif
245  break;
246 
249 #if GUIDANCE_INDI
251 #endif
253 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
254  /* reset attitude stabilization if previous mode was not using it */
258 #endif
260  break;
261 
262 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
265  break;
266 #endif
267 
268  case GUIDANCE_H_MODE_NAV:
270 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
271  /* reset attitude stabilization if previous mode was not using it */
275 #endif
277  break;
278 
281  break;
282 
283  default:
284  break;
285  }
286 
287  guidance_h.mode = new_mode;
288 
289 }
290 
291 
292 void guidance_h_read_rc(bool in_flight)
293 {
294 
295  switch (guidance_h.mode) {
296 
299  break;
300 
301 #if USE_STABILIZATION_RATE
303 #if SWITCH_STICKS_FOR_RATE_CONTROL
305 #else
307 #endif
308  break;
309 #endif
310 
313  break;
316  break;
319  break;
322 #if GUIDANCE_H_USE_SPEED_REF
324  /* enable x,y velocity setpoints */
325  SetBit(guidance_h.sp.mask, 5);
326 #endif
327  break;
328 
329 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
332  break;
333 #endif
334 
335  case GUIDANCE_H_MODE_NAV:
336  if (radio_control.status == RC_OK) {
338  } else {
340  }
341  break;
344  break;
345  default:
346  break;
347  }
348 
349 }
350 
351 void guidance_h_run(bool in_flight)
352 {
353  switch (guidance_h.mode) {
354 
356  stabilization_none_run(in_flight);
357  break;
358 
359 #if USE_STABILIZATION_RATE
361  stabilization_rate_run(in_flight);
362  break;
363 #endif
364 
366  if (transition_percentage < (100 << INT32_PERCENTAGE_FRAC)) {
367  transition_run(true);
368  }
371  if ((!(guidance_h.mode == GUIDANCE_H_MODE_FORWARD)) && transition_percentage > 0) {
372  transition_run(false);
373  }
374  stabilization_attitude_run(in_flight);
375  break;
376 
378  /* set psi command from RC */
380  /* fall trough to GUIDED to update ref, run traj and set final attitude setpoint */
381 
383  guidance_h_guided_run(in_flight);
384  break;
385 
386  case GUIDANCE_H_MODE_NAV:
387  guidance_h_from_nav(in_flight);
388  break;
389 
390 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
392  guidance_h_module_run(in_flight);
393  break;
394 #endif
395 
398  break;
399 
400  default:
401  break;
402  }
403 }
404 
405 
407 {
408  /* compute reference even if usage temporarily disabled via guidance_h_use_ref */
409 #if GUIDANCE_H_USE_REF
410  if (bit_is_set(guidance_h.sp.mask, 5)) {
412  } else {
414  }
415 #endif
416 
417  /* either use the reference or simply copy the pos setpoint */
418  if (guidance_h.use_ref) {
419  /* convert our reference to generic representation */
423  } else {
427  }
428 
429 #if GUIDANCE_H_USE_SPEED_REF
431  VECT2_COPY(guidance_h.sp.pos, guidance_h.ref.pos); // for display only
432  }
433 #endif
434 
435  /* update heading setpoint from rate */
436  if (bit_is_set(guidance_h.sp.mask, 7)) {
437  guidance_h.sp.heading += guidance_h.sp.heading_rate / PERIODIC_FREQUENCY;
439  }
440 }
441 
442 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
443 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
444 
445 #ifndef GUIDANCE_H_THRUST_CMD_FILTER
446 #define GUIDANCE_H_THRUST_CMD_FILTER 10
447 #endif
448 
449 /* with a pgain of 100 and a scale of 2,
450  * you get an angle of 5.6 degrees for 1m pos error */
451 #define GH_GAIN_SCALE 2
452 
453 #if !GUIDANCE_INDI
454 static void guidance_h_traj_run(bool in_flight)
455 {
456  /* maximum bank angle: default 20 deg, max 40 deg*/
457  static const int32_t traj_max_bank = Min(BFP_OF_REAL(GUIDANCE_H_MAX_BANK, INT32_ANGLE_FRAC),
458  BFP_OF_REAL(RadOfDeg(40), INT32_ANGLE_FRAC));
459  static const int32_t total_max_bank = BFP_OF_REAL(RadOfDeg(45), INT32_ANGLE_FRAC);
460 
461  /* compute position error */
463  /* saturate it */
465 
466  /* compute speed error */
468  /* saturate it */
470 
471  /* run PID */
472  int32_t pd_x =
475  int32_t pd_y =
478  guidance_h_cmd_earth.x = pd_x +
479  ((guidance_h.gains.v * guidance_h.ref.speed.x) >> (INT32_SPEED_FRAC - GH_GAIN_SCALE)) + /* speed feedforward gain */
481  GH_GAIN_SCALE)); /* acceleration feedforward gain */
482  guidance_h_cmd_earth.y = pd_y +
483  ((guidance_h.gains.v * guidance_h.ref.speed.y) >> (INT32_SPEED_FRAC - GH_GAIN_SCALE)) + /* speed feedforward gain */
485  GH_GAIN_SCALE)); /* acceleration feedforward gain */
486 
487  /* trim max bank angle from PD */
488  VECT2_STRIM(guidance_h_cmd_earth, -traj_max_bank, traj_max_bank);
489 
490  /* Update pos & speed error integral, zero it if not in_flight.
491  * Integrate twice as fast when not only POS but also SPEED are wrong,
492  * but do not integrate POS errors when the SPEED is already catching up.
493  */
494  if (in_flight) {
495  /* ANGLE_FRAC (12) * GAIN (8) * LOOP_FREQ (9) -> INTEGRATOR HIGH RES ANGLE_FRAX (28) */
498  /* saturate it */
500  (traj_max_bank << (INT32_ANGLE_FRAC + GH_GAIN_SCALE * 2)));
501  /* add it to the command */
504  } else {
506  }
507 
508  /* compute a better approximation of force commands by taking thrust into account */
509  if (guidance_h.approx_force_by_thrust && in_flight) {
510  static int32_t thrust_cmd_filt;
511  int32_t vertical_thrust = (stabilization_cmd[COMMAND_THRUST] * guidance_v_thrust_coeff) >> INT32_TRIG_FRAC;
512  thrust_cmd_filt = (thrust_cmd_filt * GUIDANCE_H_THRUST_CMD_FILTER + vertical_thrust) /
515  thrust_cmd_filt));
517  thrust_cmd_filt));
518  }
519 
520  VECT2_STRIM(guidance_h_cmd_earth, -total_max_bank, total_max_bank);
521 }
522 #endif
523 
525 {
526  /* reset speed setting */
527  guidance_h.sp.speed.x = 0;
528  guidance_h.sp.speed.y = 0;
529 
530  /* disable horizontal velocity setpoints,
531  * might still be activated in guidance_h_read_rc if GUIDANCE_H_USE_SPEED_REF
532  */
533  ClearBit(guidance_h.sp.mask, 5);
534  ClearBit(guidance_h.sp.mask, 7);
535 
536  /* set horizontal setpoint to current position */
538 
539  /* reset guidance reference */
541 
542  /* set guidance to current heading and position */
545 }
546 
548 {
549  ClearBit(guidance_h.sp.mask, 5);
550  ClearBit(guidance_h.sp.mask, 7);
551 
552  /* horizontal position setpoint from navigation/flightplan */
554 
556 
559 }
560 
561 void guidance_h_from_nav(bool in_flight)
562 {
563  if (!in_flight) {
565  }
566 
568  stabilization_cmd[COMMAND_ROLL] = nav_cmd_roll;
569  stabilization_cmd[COMMAND_PITCH] = nav_cmd_pitch;
570  stabilization_cmd[COMMAND_YAW] = nav_cmd_yaw;
572  struct Int32Eulers sp_cmd_i;
573  sp_cmd_i.phi = nav_roll;
574  sp_cmd_i.theta = nav_pitch;
575  sp_cmd_i.psi = nav_heading;
577  stabilization_attitude_run(in_flight);
578 
579 #if HYBRID_NAVIGATION
580  //make sure the heading is right before leaving horizontal_mode attitude
582 #endif
583  } else {
584 
585 #if HYBRID_NAVIGATION
588 #else
590 
592 
593  /* set psi command */
596 
597 #if GUIDANCE_INDI
599 #else
600  /* compute x,y earth commands */
601  guidance_h_traj_run(in_flight);
602  /* set final attitude setpoint */
605  heading_sp_i);
606 #endif
607 
608 #endif
609  stabilization_attitude_run(in_flight);
610  }
611 }
612 
613 static inline void transition_run(bool to_forward)
614 {
615  if (to_forward) {
616  //Add 0.00625%
617  transition_percentage += 1 << (INT32_PERCENTAGE_FRAC - 4);
618  } else {
619  //Subtract 0.00625%
620  transition_percentage -= 1 << (INT32_PERCENTAGE_FRAC - 4);
621  }
622 
623 #ifdef TRANSITION_MAX_OFFSET
624  const int32_t max_offset = ANGLE_BFP_OF_REAL(TRANSITION_MAX_OFFSET);
625  transition_theta_offset = INT_MULT_RSHIFT((transition_percentage << (INT32_ANGLE_FRAC - INT32_PERCENTAGE_FRAC)) / 100,
626  max_offset, INT32_ANGLE_FRAC);
627 #endif
628 }
629 
631 static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
632 {
633  if (in_flight) {
634  // negative pitch is forward
637  DeadBand(rc_x, MAX_PPRZ / 20);
638  DeadBand(rc_y, MAX_PPRZ / 20);
639 
640  // convert input from MAX_PPRZ range to SPEED_BFP
643  //int32_t rc_norm = sqrtf(rc_x * rc_x + rc_y * rc_y);
644  //int32_t max_pprz = rc_norm * MAX_PPRZ / Max(abs(rc_x), abs(rc_y);
645  rc_x = rc_x * max_speed / MAX_PPRZ;
646  rc_y = rc_y * max_speed / MAX_PPRZ;
647 
648  /* Rotate from body to NED frame by negative psi angle */
650  int32_t s_psi, c_psi;
651  PPRZ_ITRIG_SIN(s_psi, psi);
652  PPRZ_ITRIG_COS(c_psi, psi);
653  speed_sp->x = (int32_t)(((int64_t)c_psi * rc_x + (int64_t)s_psi * rc_y) >> INT32_TRIG_FRAC);
654  speed_sp->y = (int32_t)((-(int64_t)s_psi * rc_x + (int64_t)c_psi * rc_y) >> INT32_TRIG_FRAC);
655  } else {
656  speed_sp->x = 0;
657  speed_sp->y = 0;
658  }
659 }
660 
662 {
663  guidance_h.gains.i = igain;
665 }
666 
667 
668 void guidance_h_guided_run(bool in_flight)
669 {
670  /* guidance_h.sp.pos and guidance_h.sp.heading need to be set from external source */
671  if (!in_flight) {
673  }
674 
676 
677 #if GUIDANCE_INDI
679 #else
680  /* compute x,y earth commands */
681  guidance_h_traj_run(in_flight);
682  /* set final attitude setpoint */
685 #endif
686  stabilization_attitude_run(in_flight);
687 }
688 
689 bool guidance_h_set_guided_pos(float x, float y)
690 {
692  ClearBit(guidance_h.sp.mask, 5);
695  return true;
696  }
697  return false;
698 }
699 
701 {
703  ClearBit(guidance_h.sp.mask, 7);
706  return true;
707  }
708  return false;
709 }
710 
711 bool guidance_h_set_guided_body_vel(float vx, float vy)
712 {
713  float psi = stateGetNedToBodyEulers_f()->psi;
714  float newvx = cosf(-psi) * vx + sinf(-psi) * vy;
715  float newvy = -sinf(-psi) * vx + cosf(-psi) * vy;
716  return guidance_h_set_guided_vel(newvx, newvy);
717 }
718 
719 bool guidance_h_set_guided_vel(float vx, float vy)
720 {
722  SetBit(guidance_h.sp.mask, 5);
725  return true;
726  }
727  return false;
728 }
729 
731 {
733  SetBit(guidance_h.sp.mask, 7);
734  guidance_h.sp.heading_rate = rate;
735  return true;
736  }
737  return false;
738 }
739 
741 {
742  return &guidance_h_pos_err;
743 }
void guidance_flip_enter(void)
Definition: guidance_flip.c:56
void gh_update_ref_from_pos_sp(struct Int32Vect2 pos_sp)
int32_t psi
in rad with INT32_ANGLE_FRAC
#define FLOAT_ANGLE_NORMALIZE(_a)
int32_t transition_percentage
Definition: guidance_h.c:82
void guidance_indi_enter(void)
Call upon entering indi guidance.
void gh_set_ref(struct Int32Vect2 pos, struct Int32Vect2 speed, struct Int32Vect2 accel)
void guidance_h_init(void)
Definition: guidance_h.c:167
#define GUIDANCE_H_MODE_GUIDED
Definition: guidance_h.h:63
void gh_update_ref_from_speed_sp(struct Int32Vect2 speed_sp)
void guidance_h_read_rc(bool in_flight)
Definition: guidance_h.c:292
#define GUIDANCE_H_MAX_BANK
Definition: guidance_h.c:66
void stabilization_none_run(bool in_flight)
bool guidance_h_set_guided_heading_rate(float rate)
Set heading rate setpoint in GUIDED mode.
Definition: guidance_h.c:730
#define GUIDANCE_H_MODE_CARE_FREE
Definition: guidance_h.h:59
struct Int32Vect2 pos
horizontal position setpoint in NED.
Definition: guidance_h.h:71
struct Int32Vect2 guidance_h_cmd_earth
horizontal guidance command.
Definition: guidance_h.c:96
#define INT32_ACCEL_FRAC
#define MAX_SPEED_ERR
Definition: guidance_h.c:443
#define INT32_SPEED_FRAC
#define RADIO_ROLL
Definition: spektrum_arch.h:43
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
#define RADIO_YAW
Definition: spektrum_arch.h:45
const struct Int32Vect2 * guidance_h_get_pos_err(void)
Gets the position error.
Definition: guidance_h.c:740
#define INT32_PERCENTAGE_FRAC
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
General attitude stabilization interface for rotorcrafts.
void guidance_h_run(bool in_flight)
Definition: guidance_h.c:351
struct GuidanceHRef gh_ref
void stabilization_rate_enter(void)
int32_t theta
in rad with INT32_ANGLE_FRAC
uint8_t status
Definition: radio_control.h:53
#define GUIDANCE_H_VGAIN
Definition: guidance_h.c:53
#define FLOAT_EULERS_ZERO(_e)
#define INT32_ANGLE_FRAC
#define VECT2_STRIM(_v, _min, _max)
Definition: pprz_algebra.h:109
#define POS_BFP_OF_REAL(_af)
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
Definition: guidance_h.c:73
Open Loop guidance for making a flip.
static void reset_guidance_reference_from_current_position(void)
Definition: guidance_h.c:203
Read an attitude setpoint from the RC.
#define MAX_POS_ERR
Definition: guidance_h.c:442
bool approx_force_by_thrust
Definition: guidance_h.h:96
#define GUIDANCE_H_MODE_HOVER
Definition: guidance_h.h:56
#define VECT2_COPY(_a, _b)
Definition: pprz_algebra.h:67
bool guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
Definition: guidance_h.c:689
float psi
in radians
Vertical guidance for rotorcrafts.
#define VECT2_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:91
bool guidance_h_set_guided_body_vel(float vx, float vy)
Set body relative horizontal velocity setpoint in GUIDED mode.
Definition: guidance_h.c:711
void stabilization_attitude_run(bool in_flight)
struct Int32Vect2 guidance_h_trim_att_integrator
Definition: guidance_h.c:90
void stabilization_attitude_enter(void)
signed long long int64_t
Definition: types.h:21
#define INT32_ANGLE_PI_2
#define GUIDANCE_H_MODE_ATTITUDE
Definition: guidance_h.h:55
void stabilization_attitude_reset_care_free_heading(void)
reset the heading for care-free mode to current heading
struct HorizontalGuidanceReference ref
reference calculated from setpoints
Definition: guidance_h.h:101
void guidance_h_set_igain(uint32_t igain)
Definition: guidance_h.c:661
Guidance controllers (horizontal and vertical) for Hybrid UAV configurations.
void guidance_hybrid_run(void)
Runs the Hybrid Guidance main functions.
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:58
struct HorizontalGuidanceGains gains
Definition: guidance_h.h:98
#define GUIDANCE_H_REF_MAX_SPEED
Default speed saturation.
struct Int64Vect2 pos
Reference model position.
#define ANGLE_FLOAT_OF_BFP(_ai)
void guidance_h_hover_enter(void)
Definition: guidance_h.c:524
#define FALSE
Definition: std.h:5
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:117
#define GUIDANCE_H_MODE_FLIP
Definition: guidance_h.h:62
Rate stabilization for rotorcrafts.
int32_t y
East.
#define BFP_OF_REAL(_vr, _frac)
void stabilization_none_enter(void)
#define PPRZ_ITRIG_SIN(_s, _a)
void guidance_h_module_enter(void)
uint8_t mask
bit 5: vx & vy, bit 6: vz, bit 7: vyaw
Definition: guidance_h.h:75
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
Definition: state.h:863
#define GUIDANCE_H_THRUST_CMD_FILTER
Definition: guidance_h.c:446
#define TRUE
Definition: std.h:4
static void guidance_h_update_reference(void)
Definition: guidance_h.c:406
static float heading
Definition: ahrs_infrared.c:45
struct Int32Vect2 speed
with INT32_SPEED_FRAC
Definition: guidance_h.h:80
int32_t transition_theta_offset
Definition: guidance_h.c:83
struct Int32Vect2 guidance_h_pos_err
Definition: guidance_h.c:88
void guidance_indi_run(bool in_flight, float heading_sp)
void stabilization_rate_read_rc(void)
struct Int32Vect2 speed
only used in HOVER mode if GUIDANCE_H_USE_SPEED_REF or in GUIDED mode
Definition: guidance_h.h:72
void guidance_h_module_read_rc(void)
#define RADIO_PITCH
Definition: spektrum_arch.h:44
void stabilization_rate_read_rc_switched_sticks(void)
euler angles
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
#define INT32_VECT2_NED_OF_ENU(_o, _i)
int32_t x
North.
unsigned long uint32_t
Definition: types.h:18
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
void guidance_hybrid_reset_heading(struct Int32Eulers *sp_cmd)
Description.
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
static void transition_run(bool to_forward)
Definition: guidance_h.c:613
void stabilization_none_read_rc(void)
struct RadioControl radio_control
Definition: radio_control.c:30
struct HorizontalGuidance guidance_h
Definition: guidance_h.c:80
#define GH_SPEED_REF_FRAC
void guidance_h_mode_changed(uint8_t new_mode)
Definition: guidance_h.c:213
#define INT32_POS_FRAC
int32_t guidance_hybrid_norm_ref_airspeed
#define GUIDANCE_H_MODE_FORWARD
Definition: guidance_h.h:60
static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
read speed setpoint from RC
Definition: guidance_h.c:631
#define Min(x, y)
Definition: main_fbw.c:52
void guidance_h_nav_enter(void)
Definition: guidance_h.c:547
signed long int32_t
Definition: types.h:19
void guidance_h_module_init(void)
static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:150
#define GUIDANCE_H_AGAIN
Definition: guidance_h.c:49
#define RC_OK
Definition: radio_control.h:48
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define INT32_TRIG_FRAC
#define GH_ACCEL_REF_FRAC
struct Int32Vect2 pos
with INT32_POS_FRAC
Definition: guidance_h.h:79
void guidance_h_from_nav(bool in_flight)
Set horizontal guidance from NAV and run control loop.
Definition: guidance_h.c:561
void gh_ref_init(void)
bool guidance_h_set_guided_vel(float vx, float vy)
Set horizontal velocity setpoint in GUIDED mode.
Definition: guidance_h.c:719
static void guidance_h_traj_run(bool in_flight)
Definition: guidance_h.c:454
int32_t phi
in rad with INT32_ANGLE_FRAC
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
vector in North East Down coordinates
struct Int32Vect2 speed
Reference model speed.
#define INT_MULT_RSHIFT(_a, _b, _r)
int32_t guidance_v_thrust_coeff
Definition: guidance_v.c:138
#define GUIDANCE_H_USE_REF
Use horizontal guidance reference trajectory.
Definition: guidance_h.h:42
#define GUIDANCE_H_MODE_NAV
Definition: guidance_h.h:57
General stabilization interface for rotorcrafts.
void guidance_flip_run(void)
Definition: guidance_flip.c:65
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:28
void stabilization_rate_run(bool in_flight)
struct Int32Vect2 guidance_h_speed_err
Definition: guidance_h.c:89
#define INT_VECT2_ZERO(_v)
void stabilization_attitude_read_rc_setpoint_eulers_f(struct FloatEulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
struct Int32Vect2 accel
with INT32_ACCEL_FRAC
Definition: guidance_h.h:81
Guidance in a module file.
struct Int32Vect2 accel
Reference model acceleration.
void guidance_h_module_run(bool in_flight)
#define GH_GAIN_SCALE
Definition: guidance_h.c:451
#define SPEED_BFP_OF_REAL(_af)
bool guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
Definition: guidance_h.c:700
struct FloatEulers rc_sp
Definition: guidance_h.h:103
void stabilization_attitude_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
#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
Horizontal guidance for rotorcrafts.
#define INT32_VECT2_RSHIFT(_o, _i, _r)
#define INT32_VECT2_LSHIFT(_o, _i, _l)
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
#define GH_POS_REF_FRAC
#define GUIDANCE_H_MODE_RATE
Definition: guidance_h.h:54
void guidance_h_guided_run(bool in_flight)
Run GUIDED mode control.
Definition: guidance_h.c:668
#define GUIDANCE_H_USE_SPEED_REF
Use horizontal guidance speed reference.
Definition: guidance_h.h:50
static void send_gh(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:108
struct HorizontalGuidanceSetpoint sp
setpoints
Definition: guidance_h.h:100
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more! ...
static void send_href(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:139
#define GUIDANCE_H_MODE_KILL
Definition: guidance_h.h:53
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
Definition: state.h:1020
#define PPRZ_ITRIG_COS(_c, _a)
#define GUIDANCE_H_MODE_MODULE
Definition: guidance_h.h:61
#define GUIDANCE_H_MODE_RC_DIRECT
Definition: guidance_h.h:58