Paparazzi UAS  v5.17_devel-24-g2ae834f
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 
37 #if GUIDANCE_INDI_HYBRID
39 #else
41 #endif
42 
46 
47 /* for guidance_v_thrust_coeff */
49 
50 #include "state.h"
51 
52 #ifndef GUIDANCE_H_AGAIN
53 #define GUIDANCE_H_AGAIN 0
54 #endif
55 
56 #ifndef GUIDANCE_H_VGAIN
57 #define GUIDANCE_H_VGAIN 0
58 #endif
59 
60 /* error if some gains are negative */
61 #if (GUIDANCE_H_PGAIN < 0) || \
62  (GUIDANCE_H_DGAIN < 0) || \
63  (GUIDANCE_H_IGAIN < 0) || \
64  (GUIDANCE_H_AGAIN < 0) || \
65  (GUIDANCE_H_VGAIN < 0)
66 #error "ALL control gains have to be positive!!!"
67 #endif
68 
69 #ifndef GUIDANCE_H_MAX_BANK
70 #define GUIDANCE_H_MAX_BANK RadOfDeg(20)
71 #endif
72 
73 PRINT_CONFIG_VAR(GUIDANCE_H_USE_REF)
74 PRINT_CONFIG_VAR(GUIDANCE_H_USE_SPEED_REF)
75 
76 #ifndef GUIDANCE_H_APPROX_FORCE_BY_THRUST
77 #define GUIDANCE_H_APPROX_FORCE_BY_THRUST FALSE
78 #endif
79 
80 #ifndef GUIDANCE_INDI
81 #define GUIDANCE_INDI FALSE
82 #endif
83 
84 // Navigation can set heading freely
85 // This is false if sideslip is a problem
86 #ifndef GUIDANCE_HEADING_IS_FREE
87 #define GUIDANCE_HEADING_IS_FREE TRUE
88 #endif
89 
91 
93 
94 /*
95  * internal variables
96  */
100 
106 
107 static void guidance_h_update_reference(void);
108 #if !GUIDANCE_INDI
109 static void guidance_h_traj_run(bool in_flight);
110 #endif
111 static inline void transition_run(bool to_forward);
112 static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight);
113 
114 #if PERIODIC_TELEMETRY
116 
117 static void send_gh(struct transport_tx *trans, struct link_device *dev)
118 {
119  struct NedCoor_i *pos = stateGetPositionNed_i();
120  pprz_msg_send_GUIDANCE_H_INT(trans, dev, AC_ID,
123  &(pos->x), &(pos->y));
124 }
125 
126 static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
127 {
128  struct NedCoor_i *pos = stateGetPositionNed_i();
129  struct NedCoor_i *speed = stateGetSpeedNed_i();
130  struct NedCoor_i *accel = stateGetAccelNed_i();
131  pprz_msg_send_HOVER_LOOP(trans, dev, AC_ID,
132  &guidance_h.sp.pos.x,
133  &guidance_h.sp.pos.y,
134  &(pos->x), &(pos->y),
135  &(speed->x), &(speed->y),
136  &(accel->x), &(accel->y),
146 }
147 
148 static void send_href(struct transport_tx *trans, struct link_device *dev)
149 {
150  pprz_msg_send_GUIDANCE_H_REF_INT(trans, dev, AC_ID,
156  &guidance_h.ref.accel.y);
157 }
158 
159 static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
160 {
161  pprz_msg_send_ROTORCRAFT_TUNE_HOVER(trans, dev, AC_ID,
165  &stabilization_cmd[COMMAND_ROLL],
166  &stabilization_cmd[COMMAND_PITCH],
167  &stabilization_cmd[COMMAND_YAW],
168  &stabilization_cmd[COMMAND_THRUST],
169  &(stateGetNedToBodyEulers_i()->phi),
170  &(stateGetNedToBodyEulers_i()->theta),
171  &(stateGetNedToBodyEulers_i()->psi));
172 }
173 
174 #endif
175 
176 void guidance_h_init(void)
177 {
178 
182 
186  guidance_h.sp.heading = 0.0;
187  guidance_h.sp.heading_rate = 0.0;
188  guidance_h.gains.p = GUIDANCE_H_PGAIN;
189  guidance_h.gains.i = GUIDANCE_H_IGAIN;
190  guidance_h.gains.d = GUIDANCE_H_DGAIN;
193  transition_percentage = 0;
195 
196  gh_ref_init();
197 
198 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
200 #endif
201 
202 #if PERIODIC_TELEMETRY
203  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_GUIDANCE_H_INT, send_gh);
205  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_GUIDANCE_H_REF_INT, send_href);
206  register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_ROTORCRAFT_TUNE_HOVER, send_tune_hover);
207 #endif
208 
209 }
210 
211 
213 {
218 
220 }
221 
223 {
224  if (new_mode == guidance_h.mode) {
225  return;
226  }
227 
228 #if HYBRID_NAVIGATION
230 #endif
231 
232  switch (new_mode) {
235  break;
236 
237 #if USE_STABILIZATION_RATE
240  break;
241 #endif
242 
245  /* Falls through. */
248 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
249  /* reset attitude stabilization if previous mode was not using it */
253 #endif
255  break;
256 
259 #if GUIDANCE_INDI
261 #endif
263 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
264  /* reset attitude stabilization if previous mode was not using it */
268 #endif
270  break;
271 
272 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
275  break;
276 #endif
277 
278  case GUIDANCE_H_MODE_NAV:
280 #if NO_ATTITUDE_RESET_ON_MODE_CHANGE
281  /* reset attitude stabilization if previous mode was not using it */
285 #endif
287  break;
288 
291  break;
292 
293  default:
294  break;
295  }
296 
297  guidance_h.mode = new_mode;
298 
299 }
300 
301 
302 void guidance_h_read_rc(bool in_flight)
303 {
304 
305  switch (guidance_h.mode) {
306 
309  break;
310 
311 #if USE_STABILIZATION_RATE
313 #if SWITCH_STICKS_FOR_RATE_CONTROL
315 #else
317 #endif
318  break;
319 #endif
320 
323  break;
326  break;
329  break;
332 #if GUIDANCE_H_USE_SPEED_REF
334  /* enable x,y velocity setpoints */
335  SetBit(guidance_h.sp.mask, 5);
336 #endif
337  break;
338 
339 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
342  break;
343 #endif
344 
345  case GUIDANCE_H_MODE_NAV:
346  if (radio_control.status == RC_OK) {
348  } else {
350  }
351  break;
354  break;
355  default:
356  break;
357  }
358 
359 }
360 
361 void guidance_h_run(bool in_flight)
362 {
363  switch (guidance_h.mode) {
364 
366  stabilization_none_run(in_flight);
367  break;
368 
369 #if USE_STABILIZATION_RATE
371  stabilization_rate_run(in_flight);
372  break;
373 #endif
374 
376  if (transition_percentage < (100 << INT32_PERCENTAGE_FRAC)) {
377  transition_run(true);
378  }
379  /* Falls through. */
382  if ((!(guidance_h.mode == GUIDANCE_H_MODE_FORWARD)) && transition_percentage > 0) {
383  transition_run(false);
384  }
385  stabilization_attitude_run(in_flight);
386 #if (STABILIZATION_FILTER_CMD_ROLL_PITCH || STABILIZATION_FILTER_CMD_YAW)
387  if (in_flight) {
389  }
390 #endif
391 
392  break;
393 
395  /* set psi command from RC */
397  /* fall trough to GUIDED to update ref, run traj and set final attitude setpoint */
398 
399  /* Falls through. */
401  guidance_h_guided_run(in_flight);
402  break;
403 
404  case GUIDANCE_H_MODE_NAV:
405  guidance_h_from_nav(in_flight);
406  break;
407 
408 #if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
410  guidance_h_module_run(in_flight);
411  break;
412 #endif
413 
416  break;
417 
418  default:
419  break;
420  }
421 }
422 
423 
425 {
426  /* compute reference even if usage temporarily disabled via guidance_h_use_ref */
427 #if GUIDANCE_H_USE_REF
428  if (bit_is_set(guidance_h.sp.mask, 5)) {
430  } else {
432  }
433 #endif
434 
435  /* either use the reference or simply copy the pos setpoint */
436  if (guidance_h.use_ref) {
437  /* convert our reference to generic representation */
441  } else {
445  }
446 
447 #if GUIDANCE_H_USE_SPEED_REF
449  VECT2_COPY(guidance_h.sp.pos, guidance_h.ref.pos); // for display only
450  }
451 #endif
452 
453  /* update heading setpoint from rate */
454  if (bit_is_set(guidance_h.sp.mask, 7)) {
455  guidance_h.sp.heading += guidance_h.sp.heading_rate / PERIODIC_FREQUENCY;
457  }
458 }
459 
460 #define MAX_POS_ERR POS_BFP_OF_REAL(16.)
461 #define MAX_SPEED_ERR SPEED_BFP_OF_REAL(16.)
462 
463 #ifndef GUIDANCE_H_THRUST_CMD_FILTER
464 #define GUIDANCE_H_THRUST_CMD_FILTER 10
465 #endif
466 
467 /* with a pgain of 100 and a scale of 2,
468  * you get an angle of 5.6 degrees for 1m pos error */
469 #define GH_GAIN_SCALE 2
470 
471 #if !GUIDANCE_INDI
472 static void guidance_h_traj_run(bool in_flight)
473 {
474  /* maximum bank angle: default 20 deg, max 40 deg*/
475  static const int32_t traj_max_bank = Min(BFP_OF_REAL(GUIDANCE_H_MAX_BANK, INT32_ANGLE_FRAC),
476  BFP_OF_REAL(RadOfDeg(40), INT32_ANGLE_FRAC));
477  static const int32_t total_max_bank = BFP_OF_REAL(RadOfDeg(45), INT32_ANGLE_FRAC);
478 
479  /* compute position error */
481  /* saturate it */
483 
484  /* compute speed error */
486  /* saturate it */
488 
489  /* run PID */
490  int32_t pd_x =
493  int32_t pd_y =
496  guidance_h_cmd_earth.x = pd_x +
497  ((guidance_h.gains.v * guidance_h.ref.speed.x) >> (INT32_SPEED_FRAC - GH_GAIN_SCALE)) + /* speed feedforward gain */
499  GH_GAIN_SCALE)); /* acceleration feedforward gain */
500  guidance_h_cmd_earth.y = pd_y +
501  ((guidance_h.gains.v * guidance_h.ref.speed.y) >> (INT32_SPEED_FRAC - GH_GAIN_SCALE)) + /* speed feedforward gain */
503  GH_GAIN_SCALE)); /* acceleration feedforward gain */
504 
505  /* trim max bank angle from PD */
506  VECT2_STRIM(guidance_h_cmd_earth, -traj_max_bank, traj_max_bank);
507 
508  /* Update pos & speed error integral, zero it if not in_flight.
509  * Integrate twice as fast when not only POS but also SPEED are wrong,
510  * but do not integrate POS errors when the SPEED is already catching up.
511  */
512  if (in_flight) {
513  /* ANGLE_FRAC (12) * GAIN (8) * LOOP_FREQ (9) -> INTEGRATOR HIGH RES ANGLE_FRAX (28) */
516  /* saturate it */
518  (traj_max_bank << (INT32_ANGLE_FRAC + GH_GAIN_SCALE * 2)));
519  /* add it to the command */
522  } else {
524  }
525 
526  /* compute a better approximation of force commands by taking thrust into account */
527  if (guidance_h.approx_force_by_thrust && in_flight) {
528  static int32_t thrust_cmd_filt;
529  int32_t vertical_thrust = (stabilization_cmd[COMMAND_THRUST] * guidance_v_thrust_coeff) >> INT32_TRIG_FRAC;
530  thrust_cmd_filt = (thrust_cmd_filt * GUIDANCE_H_THRUST_CMD_FILTER + vertical_thrust) /
533  thrust_cmd_filt));
535  thrust_cmd_filt));
536  }
537 
538  VECT2_STRIM(guidance_h_cmd_earth, -total_max_bank, total_max_bank);
539 }
540 #endif
541 
543 {
544  /* reset speed setting */
545  guidance_h.sp.speed.x = 0;
546  guidance_h.sp.speed.y = 0;
547 
548  /* disable horizontal velocity setpoints,
549  * might still be activated in guidance_h_read_rc if GUIDANCE_H_USE_SPEED_REF
550  */
551  ClearBit(guidance_h.sp.mask, 5);
552  ClearBit(guidance_h.sp.mask, 7);
553 
554  /* set horizontal setpoint to current position */
556 
557  /* reset guidance reference */
559 
560  /* set guidance to current heading and position */
563 }
564 
566 {
567  ClearBit(guidance_h.sp.mask, 5);
568  ClearBit(guidance_h.sp.mask, 7);
569 
570  /* horizontal position setpoint from navigation/flightplan */
572 
574 
577 }
578 
579 void guidance_h_from_nav(bool in_flight)
580 {
581  if (!in_flight) {
583  }
584 
586  stabilization_cmd[COMMAND_ROLL] = nav_cmd_roll;
587  stabilization_cmd[COMMAND_PITCH] = nav_cmd_pitch;
588  stabilization_cmd[COMMAND_YAW] = nav_cmd_yaw;
590  struct Int32Eulers sp_cmd_i;
591  sp_cmd_i.phi = nav_roll;
592  sp_cmd_i.theta = nav_pitch;
593  sp_cmd_i.psi = nav_heading;
595  stabilization_attitude_run(in_flight);
596 
597 #if HYBRID_NAVIGATION
598  //make sure the heading is right before leaving horizontal_mode attitude
600 #endif
601  } else {
602 
603 #if HYBRID_NAVIGATION
606 #else
608 
610 
611 #if GUIDANCE_HEADING_IS_FREE
612  /* set psi command */
615 #endif
616 
617 #if GUIDANCE_INDI
619 #else
620  /* compute x,y earth commands */
621  guidance_h_traj_run(in_flight);
622  /* set final attitude setpoint */
625  heading_sp_i);
626 #endif
627 
628 #endif
629  stabilization_attitude_run(in_flight);
630  }
631 }
632 
633 static inline void transition_run(bool to_forward)
634 {
635  if (to_forward) {
636  //Add 0.00625%
637  transition_percentage += 1 << (INT32_PERCENTAGE_FRAC - 4);
638  } else {
639  //Subtract 0.00625%
640  transition_percentage -= 1 << (INT32_PERCENTAGE_FRAC - 4);
641  }
642 
643 #ifdef TRANSITION_MAX_OFFSET
644  const int32_t max_offset = ANGLE_BFP_OF_REAL(TRANSITION_MAX_OFFSET);
645  transition_theta_offset = INT_MULT_RSHIFT((transition_percentage << (INT32_ANGLE_FRAC - INT32_PERCENTAGE_FRAC)) / 100,
646  max_offset, INT32_ANGLE_FRAC);
647 #endif
648 }
649 
651 static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
652 {
653  if (in_flight) {
654  // negative pitch is forward
657  DeadBand(rc_x, MAX_PPRZ / 20);
658  DeadBand(rc_y, MAX_PPRZ / 20);
659 
660  // convert input from MAX_PPRZ range to SPEED_BFP
663  //int32_t rc_norm = sqrtf(rc_x * rc_x + rc_y * rc_y);
664  //int32_t max_pprz = rc_norm * MAX_PPRZ / Max(abs(rc_x), abs(rc_y);
665  rc_x = rc_x * max_speed / MAX_PPRZ;
666  rc_y = rc_y * max_speed / MAX_PPRZ;
667 
668  /* Rotate from body to NED frame by negative psi angle */
670  int32_t s_psi, c_psi;
671  PPRZ_ITRIG_SIN(s_psi, psi);
672  PPRZ_ITRIG_COS(c_psi, psi);
673  speed_sp->x = (int32_t)(((int64_t)c_psi * rc_x + (int64_t)s_psi * rc_y) >> INT32_TRIG_FRAC);
674  speed_sp->y = (int32_t)((-(int64_t)s_psi * rc_x + (int64_t)c_psi * rc_y) >> INT32_TRIG_FRAC);
675  } else {
676  speed_sp->x = 0;
677  speed_sp->y = 0;
678  }
679 }
680 
682 {
683  guidance_h.gains.i = igain;
685 }
686 
687 
688 void guidance_h_guided_run(bool in_flight)
689 {
690  /* guidance_h.sp.pos and guidance_h.sp.heading need to be set from external source */
691  if (!in_flight) {
693  }
694 
696 
697 #if GUIDANCE_INDI
699 #else
700  /* compute x,y earth commands */
701  guidance_h_traj_run(in_flight);
702  /* set final attitude setpoint */
705 #endif
706  stabilization_attitude_run(in_flight);
707 }
708 
709 bool guidance_h_set_guided_pos(float x, float y)
710 {
712  ClearBit(guidance_h.sp.mask, 5);
715  return true;
716  }
717  return false;
718 }
719 
721 {
723  ClearBit(guidance_h.sp.mask, 7);
726  return true;
727  }
728  return false;
729 }
730 
731 bool guidance_h_set_guided_body_vel(float vx, float vy)
732 {
733  float psi = stateGetNedToBodyEulers_f()->psi;
734  float newvx = cosf(-psi) * vx + sinf(-psi) * vy;
735  float newvy = -sinf(-psi) * vx + cosf(-psi) * vy;
736  return guidance_h_set_guided_vel(newvx, newvy);
737 }
738 
739 bool guidance_h_set_guided_vel(float vx, float vy)
740 {
742  SetBit(guidance_h.sp.mask, 5);
745  return true;
746  }
747  return false;
748 }
749 
751 {
753  SetBit(guidance_h.sp.mask, 7);
754  guidance_h.sp.heading_rate = rate;
755  return true;
756  }
757  return false;
758 }
759 
761 {
762  return &guidance_h_pos_err;
763 }
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
struct EnuCoor_i navigation_target
Definition: navigation.c:91
#define FLOAT_ANGLE_NORMALIZE(_a)
int32_t transition_percentage
Definition: guidance_h.c:92
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:176
#define RADIO_ROLL
Definition: intermcu_ap.h:41
int32_t nav_cmd_pitch
Definition: navigation.c:109
#define GUIDANCE_H_MODE_GUIDED
Definition: guidance_h.h:66
void gh_update_ref_from_speed_sp(struct Int32Vect2 speed_sp)
#define Min(x, y)
Definition: esc_dshot.c:85
void guidance_h_read_rc(bool in_flight)
Definition: guidance_h.c:302
#define GUIDANCE_H_MAX_BANK
Definition: guidance_h.c:70
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:750
#define GUIDANCE_H_MODE_CARE_FREE
Definition: guidance_h.h:62
struct Int32Vect2 pos
horizontal position setpoint in NED.
Definition: guidance_h.h:74
struct Int32Vect2 guidance_h_cmd_earth
horizontal guidance command.
Definition: guidance_h.c:105
void guidance_h_module_run(bool in_flight)
#define INT32_ACCEL_FRAC
float heading
Definition: wedgebug.c:258
#define MAX_SPEED_ERR
Definition: guidance_h.c:461
#define INT32_SPEED_FRAC
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
const struct Int32Vect2 * guidance_h_get_pos_err(void)
Gets the position error.
Definition: guidance_h.c:760
#define INT32_PERCENTAGE_FRAC
Dummy stabilization for rotorcrafts.
Periodic telemetry system header (includes downlink utility and generated code).
int32_t nav_cmd_roll
Definition: navigation.c:109
General attitude stabilization interface for rotorcrafts.
void guidance_h_run(bool in_flight)
Definition: guidance_h.c:361
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:64
#define GUIDANCE_H_VGAIN
Definition: guidance_h.c:57
#define FLOAT_EULERS_ZERO(_e)
#define INT32_ANGLE_FRAC
#define HORIZONTAL_MODE_MANUAL
Definition: navigation.h:57
#define VECT2_STRIM(_v, _min, _max)
Definition: pprz_algebra.h:110
#define POS_BFP_OF_REAL(_af)
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
Definition: guidance_h.c:77
Open Loop guidance for making a flip.
static void reset_guidance_reference_from_current_position(void)
Definition: guidance_h.c:212
Read an attitude setpoint from the RC.
#define MAX_POS_ERR
Definition: guidance_h.c:460
bool approx_force_by_thrust
Definition: guidance_h.h:99
#define GUIDANCE_H_MODE_HOVER
Definition: guidance_h.h:59
void stabilization_filter_commands(void)
Definition: stabilization.c:75
#define VECT2_COPY(_a, _b)
Definition: pprz_algebra.h:68
bool guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
Definition: guidance_h.c:709
float psi
in radians
Vertical guidance for rotorcrafts.
#define VECT2_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:92
bool guidance_h_set_guided_body_vel(float vx, float vy)
Set body relative horizontal velocity setpoint in GUIDED mode.
Definition: guidance_h.c:731
void stabilization_attitude_run(bool in_flight)
void guidance_h_module_init(void)
struct Int32Vect2 guidance_h_trim_att_integrator
Definition: guidance_h.c:99
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:58
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:104
void guidance_h_set_igain(uint32_t igain)
Definition: guidance_h.c:681
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:69
struct HorizontalGuidanceGains gains
Definition: guidance_h.h:101
#define GUIDANCE_H_REF_MAX_SPEED
Default speed saturation.
void guidance_h_module_read_rc(void)
struct Int64Vect2 pos
Reference model position.
#define ANGLE_FLOAT_OF_BFP(_ai)
void guidance_h_hover_enter(void)
Definition: guidance_h.c:542
#define FALSE
Definition: std.h:5
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:126
#define GUIDANCE_H_MODE_FLIP
Definition: guidance_h.h:65
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)
uint8_t mask
bit 5: vx & vy, bit 6: vz, bit 7: vyaw
Definition: guidance_h.h:78
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:464
#define TRUE
Definition: std.h:4
static void guidance_h_update_reference(void)
Definition: guidance_h.c:424
struct Int32Vect2 speed
with INT32_SPEED_FRAC
Definition: guidance_h.h:83
void guidance_h_module_enter(void)
struct Int32Vect2 guidance_h_pos_err
Definition: guidance_h.c:97
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:75
struct FloatVect3 speed_sp
int32_t nav_heading
with INT32_ANGLE_FRAC
Definition: navigation.c:108
#define HORIZONTAL_MODE_ATTITUDE
Definition: navigation.h:56
void guidance_indi_run(float *heading_sp)
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 transition_theta_offset
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:633
void stabilization_none_read_rc(void)
struct RadioControl radio_control
Definition: radio_control.c:30
struct HorizontalGuidance guidance_h
Definition: guidance_h.c:90
#define GH_SPEED_REF_FRAC
void guidance_h_mode_changed(uint8_t new_mode)
Definition: guidance_h.c:222
#define INT32_POS_FRAC
int32_t guidance_hybrid_norm_ref_airspeed
#define GUIDANCE_H_MODE_FORWARD
Definition: guidance_h.h:63
static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
read speed setpoint from RC
Definition: guidance_h.c:651
void guidance_h_nav_enter(void)
Definition: guidance_h.c:565
signed long int32_t
Definition: types.h:19
struct EnuCoor_i navigation_carrot
Definition: navigation.c:92
static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:159
#define GUIDANCE_H_AGAIN
Definition: guidance_h.c:53
#define RC_OK
Definition: radio_control.h:56
#define ANGLE_BFP_OF_REAL(_af)
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
#define INT32_TRIG_FRAC
#define GH_ACCEL_REF_FRAC
Rotorcraft navigation functions.
struct Int32Vect2 pos
with INT32_POS_FRAC
Definition: guidance_h.h:82
void guidance_h_from_nav(bool in_flight)
Set horizontal guidance from NAV and run control loop.
Definition: guidance_h.c:579
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:739
static void guidance_h_traj_run(bool in_flight)
Definition: guidance_h.c:472
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
#define RADIO_PITCH
Definition: intermcu_ap.h:42
struct Int32Vect2 speed
Reference model speed.
#define INT_MULT_RSHIFT(_a, _b, _r)
int32_t guidance_v_thrust_coeff
Definition: guidance_v.c:142
#define GUIDANCE_H_USE_REF
Use horizontal guidance reference trajectory.
Definition: guidance_h.h:45
#define GUIDANCE_H_MODE_NAV
Definition: guidance_h.h:60
A guidance mode based on Incremental Nonlinear Dynamic Inversion Come to ICRA2016 to learn more! ...
General stabilization interface for rotorcrafts.
void guidance_flip_run(void)
Definition: guidance_flip.c:65
#define RADIO_YAW
Definition: intermcu_ap.h:43
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:32
void stabilization_rate_run(bool in_flight)
struct Int32Vect2 guidance_h_speed_err
Definition: guidance_h.c:98
#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:84
Guidance in a module file.
int32_t nav_roll
Definition: navigation.c:107
struct Int32Vect2 accel
Reference model acceleration.
#define GH_GAIN_SCALE
Definition: guidance_h.c:469
#define SPEED_BFP_OF_REAL(_af)
bool guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
Definition: guidance_h.c:720
struct FloatEulers rc_sp
Definition: guidance_h.h:106
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
int32_t nav_cmd_yaw
Definition: navigation.c:109
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:57
void guidance_h_guided_run(bool in_flight)
Run GUIDED mode control.
Definition: guidance_h.c:688
#define GUIDANCE_H_USE_SPEED_REF
Use horizontal guidance speed reference.
Definition: guidance_h.h:53
static void send_gh(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:117
struct HorizontalGuidanceSetpoint sp
setpoints
Definition: guidance_h.h:103
A guidance mode based on Incremental Nonlinear Dynamic Inversion.
static void send_href(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:148
#define GUIDANCE_H_MODE_KILL
Definition: guidance_h.h:56
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:64
#define GUIDANCE_H_MODE_RC_DIRECT
Definition: guidance_h.h:61