Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
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;
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 
377  transition_run(true);
378  }
379  /* Falls through. */
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%
638  } else {
639  //Subtract 0.00625%
641  }
642 
643 #ifdef TRANSITION_MAX_OFFSET
644  const int32_t max_offset = ANGLE_BFP_OF_REAL(TRANSITION_MAX_OFFSET);
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 }
speed_sp
struct FloatVect3 speed_sp
Definition: guidance_indi_hybrid.c:134
Int32Eulers::theta
int32_t theta
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:148
radio_control.h
guidance_hybrid_norm_ref_airspeed
int32_t guidance_hybrid_norm_ref_airspeed
Definition: guidance_hybrid.c:49
MAX_PPRZ
#define MAX_PPRZ
Definition: paparazzi.h:8
HorizontalGuidance::ref
struct HorizontalGuidanceReference ref
reference calculated from setpoints
Definition: guidance_h.h:104
INT32_VECT2_NED_OF_ENU
#define INT32_VECT2_NED_OF_ENU(_o, _i)
Definition: pprz_geodetic_int.h:209
GUIDANCE_H_USE_SPEED_REF
#define GUIDANCE_H_USE_SPEED_REF
Use horizontal guidance speed reference.
Definition: guidance_h.h:53
ANGLE_FLOAT_OF_BFP
#define ANGLE_FLOAT_OF_BFP(_ai)
Definition: pprz_algebra_int.h:211
transition_theta_offset
int32_t transition_theta_offset
Definition: stabilization_attitude_rc_setpoint.c:58
stabilization_attitude_read_rc
void stabilization_attitude_read_rc(bool in_flight, bool in_carefree, bool coordinated_turn)
Definition: stabilization_attitude_euler_float.c:131
FLOAT_ANGLE_NORMALIZE
#define FLOAT_ANGLE_NORMALIZE(_a)
Definition: pprz_algebra_float.h:99
HorizontalGuidanceSetpoint::mask
uint8_t mask
bit 5: vx & vy, bit 6: vz, bit 7: vyaw
Definition: guidance_h.h:78
RADIO_ROLL
#define RADIO_ROLL
Definition: intermcu_ap.h:41
stabilization_attitude.h
guidance_hybrid_reset_heading
void guidance_hybrid_reset_heading(struct Int32Eulers *sp_cmd)
Description.
Definition: guidance_hybrid.c:137
HorizontalGuidanceGains::i
int32_t i
Definition: guidance_h.h:90
gh_ref
struct GuidanceHRef gh_ref
Definition: guidance_h_ref.c:30
guidance_flip.h
stabilization_rate_read_rc
void stabilization_rate_read_rc(void)
Definition: stabilization_rate.c:137
GUIDANCE_H_MAX_BANK
#define GUIDANCE_H_MAX_BANK
Definition: guidance_h.c:70
INT32_SPEED_FRAC
#define INT32_SPEED_FRAC
Definition: pprz_algebra_int.h:73
guidance_h_module_run
void guidance_h_module_run(bool in_flight)
Definition: ctrl_module_innerloop_demo.c:99
guidance_h_cmd_earth
struct Int32Vect2 guidance_h_cmd_earth
horizontal guidance command.
Definition: guidance_h.c:105
NedCoor_i::y
int32_t y
East.
Definition: pprz_geodetic_int.h:70
GUIDANCE_H_MODE_ATTITUDE
#define GUIDANCE_H_MODE_ATTITUDE
Definition: guidance_h.h:58
GH_GAIN_SCALE
#define GH_GAIN_SCALE
Definition: guidance_h.c:469
guidance_h_mode_changed
void guidance_h_mode_changed(uint8_t new_mode)
Definition: guidance_h.c:222
guidance_h_module_read_rc
void guidance_h_module_read_rc(void)
Definition: ctrl_module_innerloop_demo.c:90
stabilization_filter_commands
void stabilization_filter_commands(void)
Definition: stabilization.c:75
guidance_h_update_reference
static void guidance_h_update_reference(void)
Definition: guidance_h.c:424
GUIDANCE_H_MODE_GUIDED
#define GUIDANCE_H_MODE_GUIDED
Definition: guidance_h.h:66
INT32_ANGLE_FRAC
#define INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:116
guidance_indi_hybrid.h
Int32Vect2::y
int32_t y
Definition: pprz_algebra_int.h:85
nav_cmd_yaw
int32_t nav_cmd_yaw
Definition: navigation.c:109
SPEED_BFP_OF_REAL
#define SPEED_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:218
stateGetNedToBodyEulers_f
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition: state.h:1143
GH_ACCEL_REF_FRAC
#define GH_ACCEL_REF_FRAC
Definition: guidance_h_ref.h:57
HorizontalGuidanceSetpoint::pos
struct Int32Vect2 pos
horizontal position setpoint in NED.
Definition: guidance_h.h:74
GUIDANCE_H_MODE_MODULE
#define GUIDANCE_H_MODE_MODULE
Definition: guidance_h.h:64
GUIDANCE_H_MODE_RC_DIRECT
#define GUIDANCE_H_MODE_RC_DIRECT
Definition: guidance_h.h:61
HorizontalGuidanceReference::accel
struct Int32Vect2 accel
with INT32_ACCEL_FRAC
Definition: guidance_h.h:84
PPRZ_ITRIG_COS
#define PPRZ_ITRIG_COS(_c, _a)
Definition: pprz_trig_int.h:110
FLOAT_EULERS_ZERO
#define FLOAT_EULERS_ZERO(_e)
Definition: pprz_algebra_float.h:516
navigation_target
struct EnuCoor_i navigation_target
Definition: navigation.c:91
uint32_t
unsigned long uint32_t
Definition: types.h:18
nav_roll
int32_t nav_roll
Definition: navigation.c:107
navigation_carrot
struct EnuCoor_i navigation_carrot
Definition: navigation.c:92
guidance_module.h
guidance_h_set_igain
void guidance_h_set_igain(uint32_t igain)
Definition: guidance_h.c:681
HorizontalGuidanceSetpoint::heading
float heading
Definition: guidance_h.h:76
HorizontalGuidance
Definition: guidance_h.h:95
int64_t
signed long long int64_t
Definition: types.h:21
stateGetPositionNed_i
static struct NedCoor_i * stateGetPositionNed_i(void)
Get position in local NED coordinates (int).
Definition: state.h:665
guidance_v.h
GuidanceHRef::speed
struct Int32Vect2 speed
Reference model speed.
Definition: guidance_h_ref.h:74
guidance_h_set_guided_pos
bool guidance_h_set_guided_pos(float x, float y)
Set horizontal position setpoint in GUIDED mode.
Definition: guidance_h.c:709
nav_heading
int32_t nav_heading
with INT32_ANGLE_FRAC
Definition: navigation.c:108
HorizontalGuidanceGains::d
int32_t d
Definition: guidance_h.h:89
HorizontalGuidanceReference::speed
struct Int32Vect2 speed
with INT32_SPEED_FRAC
Definition: guidance_h.h:83
HorizontalGuidance::use_ref
bool use_ref
Definition: guidance_h.h:98
nav_cmd_pitch
int32_t nav_cmd_pitch
Definition: navigation.c:109
GUIDANCE_H_MODE_FLIP
#define GUIDANCE_H_MODE_FLIP
Definition: guidance_h.h:65
INT_VECT2_ZERO
#define INT_VECT2_ZERO(_v)
Definition: pprz_algebra_int.h:237
HORIZONTAL_MODE_MANUAL
#define HORIZONTAL_MODE_MANUAL
Definition: navigation.h:57
guidance_h_pos_err
struct Int32Vect2 guidance_h_pos_err
Definition: guidance_h.c:97
stabilization_attitude_read_rc_setpoint_eulers_f
void stabilization_attitude_read_rc_setpoint_eulers_f(struct FloatEulers *sp, bool in_flight, bool in_carefree, bool coordinated_turn)
Definition: stabilization_attitude_rc_setpoint.c:252
MAX_POS_ERR
#define MAX_POS_ERR
Definition: guidance_h.c:460
VECT2_DIFF
#define VECT2_DIFF(_c, _a, _b)
Definition: pprz_algebra.h:92
gh_update_ref_from_speed_sp
void gh_update_ref_from_speed_sp(struct Int32Vect2 speed_sp)
Definition: guidance_h_ref.c:148
VECT2_COPY
#define VECT2_COPY(_a, _b)
Definition: pprz_algebra.h:68
VECT2_STRIM
#define VECT2_STRIM(_v, _min, _max)
Definition: pprz_algebra.h:110
guidance_h_traj_run
static void guidance_h_traj_run(bool in_flight)
Definition: guidance_h.c:472
INT32_ACCEL_FRAC
#define INT32_ACCEL_FRAC
Definition: pprz_algebra_int.h:78
telemetry.h
nav_pitch
float nav_pitch
Definition: nav.c:308
Int32Vect2::x
int32_t x
Definition: pprz_algebra_int.h:84
reset_guidance_reference_from_current_position
static void reset_guidance_reference_from_current_position(void)
Definition: guidance_h.c:212
GUIDANCE_H_APPROX_FORCE_BY_THRUST
#define GUIDANCE_H_APPROX_FORCE_BY_THRUST
Definition: guidance_h.c:77
Int32Eulers::psi
int32_t psi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:149
Int32Eulers::phi
int32_t phi
in rad with INT32_ANGLE_FRAC
Definition: pprz_algebra_int.h:147
HorizontalGuidanceSetpoint::speed
struct Int32Vect2 speed
only used in HOVER mode if GUIDANCE_H_USE_SPEED_REF or in GUIDED mode
Definition: guidance_h.h:75
GUIDANCE_H_MODE_HOVER
#define GUIDANCE_H_MODE_HOVER
Definition: guidance_h.h:59
GH_SPEED_REF_FRAC
#define GH_SPEED_REF_FRAC
Definition: guidance_h_ref.h:58
gh_update_ref_from_pos_sp
void gh_update_ref_from_pos_sp(struct Int32Vect2 pos_sp)
Definition: guidance_h_ref.c:116
stateGetSpeedNed_i
static struct NedCoor_i * stateGetSpeedNed_i(void)
Get ground speed in local NED coordinates (int).
Definition: state.h:863
guidance_h_run
void guidance_h_run(bool in_flight)
Definition: guidance_h.c:361
guidance_h_set_guided_body_vel
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
HorizontalGuidance::mode
uint8_t mode
Definition: guidance_h.h:96
GUIDANCE_H_MODE_FORWARD
#define GUIDANCE_H_MODE_FORWARD
Definition: guidance_h.h:63
ANGLE_BFP_OF_REAL
#define ANGLE_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:210
NedCoor_i
vector in North East Down coordinates
Definition: pprz_geodetic_int.h:68
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
send_hover_loop
static void send_hover_loop(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:126
guidance_h_trim_att_integrator
struct Int32Vect2 guidance_h_trim_att_integrator
Definition: guidance_h.c:99
guidance_indi_enter
void guidance_indi_enter(void)
Call upon entering indi guidance.
Definition: guidance_indi.c:134
guidance_flip_run
void guidance_flip_run(void)
Definition: guidance_flip.c:65
INT_MULT_RSHIFT
#define INT_MULT_RSHIFT(_a, _b, _r)
Definition: pprz_algebra_int.h:225
GUIDANCE_H_USE_REF
#define GUIDANCE_H_USE_REF
Use horizontal guidance reference trajectory.
Definition: guidance_h.h:45
Int32Vect2
Definition: pprz_algebra_int.h:83
stabilization_attitude_rc_setpoint.h
uint8_t
unsigned char uint8_t
Definition: types.h:14
HorizontalGuidance::approx_force_by_thrust
bool approx_force_by_thrust
Definition: guidance_h.h:99
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
RadioControl::status
uint8_t status
Definition: radio_control.h:64
Int32Eulers
euler angles
Definition: pprz_algebra_int.h:146
gh_ref_init
void gh_ref_init(void)
Definition: guidance_h_ref.c:62
stabilization_attitude_run
void stabilization_attitude_run(bool in_flight)
Definition: stabilization_attitude_euler_float.c:176
HorizontalGuidanceSetpoint::heading_rate
float heading_rate
Definition: guidance_h.h:77
guidance_flip_enter
void guidance_flip_enter(void)
Definition: guidance_flip.c:56
nav_cmd_roll
int32_t nav_cmd_roll
Definition: navigation.c:109
guidance_h_set_guided_heading
bool guidance_h_set_guided_heading(float heading)
Set heading setpoint in GUIDED mode.
Definition: guidance_h.c:720
BFP_OF_REAL
#define BFP_OF_REAL(_vr, _frac)
Definition: pprz_algebra_int.h:205
guidance_hybrid_run
void guidance_hybrid_run(void)
Runs the Hybrid Guidance main functions.
Definition: guidance_hybrid.c:129
HorizontalGuidance::sp
struct HorizontalGuidanceSetpoint sp
setpoints
Definition: guidance_h.h:103
stabilization_rate_enter
void stabilization_rate_enter(void)
Definition: stabilization_rate.c:182
FloatVect3::y
float y
Definition: pprz_algebra_float.h:56
HorizontalGuidance::gains
struct HorizontalGuidanceGains gains
Definition: guidance_h.h:101
GUIDANCE_H_MODE_KILL
#define GUIDANCE_H_MODE_KILL
Definition: guidance_h.h:56
stabilization_rate.h
stabilization_attitude_reset_care_free_heading
void stabilization_attitude_reset_care_free_heading(void)
reset the heading for care-free mode to current heading
Definition: stabilization_attitude_rc_setpoint.c:122
HorizontalGuidanceGains::v
int32_t v
Definition: guidance_h.h:91
GUIDANCE_H_MODE_RATE
#define GUIDANCE_H_MODE_RATE
Definition: guidance_h.h:57
GUIDANCE_H_AGAIN
#define GUIDANCE_H_AGAIN
Definition: guidance_h.c:53
INT32_VECT2_RSHIFT
#define INT32_VECT2_RSHIFT(_o, _i, _r)
Definition: pprz_algebra_int.h:268
gh_set_ref
void gh_set_ref(struct Int32Vect2 pos, struct Int32Vect2 speed, struct Int32Vect2 accel)
Definition: guidance_h_ref.c:106
INT32_VECT2_LSHIFT
#define INT32_VECT2_LSHIFT(_o, _i, _l)
Definition: pprz_algebra_int.h:273
FloatVect3::x
float x
Definition: pprz_algebra_float.h:55
GUIDANCE_H_VGAIN
#define GUIDANCE_H_VGAIN
Definition: guidance_h.c:57
stabilization_attitude_enter
void stabilization_attitude_enter(void)
Definition: stabilization_attitude_euler_float.c:136
int32_t
signed long int32_t
Definition: types.h:19
guidance_h_speed_err
struct Int32Vect2 guidance_h_speed_err
Definition: guidance_h.c:98
send_href
static void send_href(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:148
RC_OK
#define RC_OK
Definition: radio_control.h:56
read_rc_setpoint_speed_i
static void read_rc_setpoint_speed_i(struct Int32Vect2 *speed_sp, bool in_flight)
read speed setpoint from RC
Definition: guidance_h.c:651
guidance_h_read_rc
void guidance_h_read_rc(bool in_flight)
Definition: guidance_h.c:302
stabilization_none_enter
void stabilization_none_enter(void)
Definition: stabilization_none.c:50
guidance_hybrid.h
guidance_h_hover_enter
void guidance_h_hover_enter(void)
Definition: guidance_h.c:542
guidance_h_nav_enter
void guidance_h_nav_enter(void)
Definition: guidance_h.c:565
transition_run
static void transition_run(bool to_forward)
Definition: guidance_h.c:633
navigation.h
send_tune_hover
static void send_tune_hover(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:159
guidance_v_thrust_coeff
int32_t guidance_v_thrust_coeff
Definition: guidance_v.c:142
transition_percentage
int32_t transition_percentage
Definition: guidance_h.c:92
guidance_h_guided_run
void guidance_h_guided_run(bool in_flight)
Run GUIDED mode control.
Definition: guidance_h.c:688
stabilization_cmd
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:32
HorizontalGuidanceReference::pos
struct Int32Vect2 pos
with INT32_POS_FRAC
Definition: guidance_h.h:82
NedCoor_i::x
int32_t x
North.
Definition: pprz_geodetic_int.h:69
guidance_h
struct HorizontalGuidance guidance_h
Definition: guidance_h.c:90
GH_POS_REF_FRAC
#define GH_POS_REF_FRAC
Definition: guidance_h_ref.h:59
INT32_ANGLE_PI_2
#define INT32_ANGLE_PI_2
Definition: pprz_algebra_int.h:119
stateGetAccelNed_i
static struct NedCoor_i * stateGetAccelNed_i(void)
Get acceleration in NED coordinates (int).
Definition: state.h:1020
send_gh
static void send_gh(struct transport_tx *trans, struct link_device *dev)
Definition: guidance_h.c:117
guidance_h_from_nav
void guidance_h_from_nav(bool in_flight)
Set horizontal guidance from NAV and run control loop.
Definition: guidance_h.c:579
GuidanceHRef::accel
struct Int32Vect2 accel
Reference model acceleration.
Definition: guidance_h_ref.h:67
stabilization_rate_run
void stabilization_rate_run(bool in_flight)
Definition: stabilization_rate.c:187
stabilization_rate_read_rc_switched_sticks
void stabilization_rate_read_rc_switched_sticks(void)
Definition: stabilization_rate.c:160
guidance_indi.h
RADIO_YAW
#define RADIO_YAW
Definition: intermcu_ap.h:43
POS_BFP_OF_REAL
#define POS_BFP_OF_REAL(_af)
Definition: pprz_algebra_int.h:216
stabilization_attitude_set_earth_cmd_i
void stabilization_attitude_set_earth_cmd_i(struct Int32Vect2 *cmd, int32_t heading)
Definition: stabilization_attitude_euler_float.c:159
stabilization_attitude_set_rpy_setpoint_i
void stabilization_attitude_set_rpy_setpoint_i(struct Int32Eulers *rpy)
Definition: stabilization_attitude_euler_float.c:154
guidance_h_module_enter
void guidance_h_module_enter(void)
Definition: ctrl_module_innerloop_demo.c:85
stateGetNedToBodyEulers_i
static struct Int32Eulers * stateGetNedToBodyEulers_i(void)
Get vehicle body attitude euler angles (int).
Definition: state.h:1125
HorizontalGuidanceGains::p
int32_t p
Definition: guidance_h.h:88
guidance_h_module_init
void guidance_h_module_init(void)
Definition: ctrl_module_innerloop_demo.c:80
HorizontalGuidanceGains::a
int32_t a
Definition: guidance_h.h:92
stabilization.h
state.h
INT32_TRIG_FRAC
#define INT32_TRIG_FRAC
Definition: pprz_algebra_int.h:154
FALSE
#define FALSE
Definition: std.h:5
GUIDANCE_H_MODE_NAV
#define GUIDANCE_H_MODE_NAV
Definition: guidance_h.h:60
FloatEulers::psi
float psi
in radians
Definition: pprz_algebra_float.h:87
MAX_SPEED_ERR
#define MAX_SPEED_ERR
Definition: guidance_h.c:461
TRUE
#define TRUE
Definition: std.h:4
RADIO_PITCH
#define RADIO_PITCH
Definition: intermcu_ap.h:42
INT32_PERCENTAGE_FRAC
#define INT32_PERCENTAGE_FRAC
Definition: pprz_algebra_int.h:81
guidance_h_set_guided_vel
bool guidance_h_set_guided_vel(float vx, float vy)
Set horizontal velocity setpoint in GUIDED mode.
Definition: guidance_h.c:739
guidance_h.h
INT32_POS_FRAC
#define INT32_POS_FRAC
Definition: pprz_algebra_int.h:68
HORIZONTAL_MODE_ATTITUDE
#define HORIZONTAL_MODE_ATTITUDE
Definition: navigation.h:56
GuidanceHRef::pos
struct Int64Vect2 pos
Reference model position.
Definition: guidance_h_ref.h:80
horizontal_mode
uint8_t horizontal_mode
Definition: nav.c:71
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
guidance_h_set_guided_heading_rate
bool guidance_h_set_guided_heading_rate(float rate)
Set heading rate setpoint in GUIDED mode.
Definition: guidance_h.c:750
stabilization_none.h
GUIDANCE_H_MODE_CARE_FREE
#define GUIDANCE_H_MODE_CARE_FREE
Definition: guidance_h.h:62
HorizontalGuidance::rc_sp
struct FloatEulers rc_sp
Definition: guidance_h.h:106
stabilization_none_run
void stabilization_none_run(bool in_flight)
Definition: stabilization_none.c:55
guidance_indi_run
void guidance_indi_run(float *heading_sp)
Definition: guidance_indi.c:154
radio_control
struct RadioControl radio_control
Definition: radio_control.c:30
guidance_h_get_pos_err
const struct Int32Vect2 * guidance_h_get_pos_err(void)
Gets the position error.
Definition: guidance_h.c:760
stabilization_none_read_rc
void stabilization_none_read_rc(void)
Definition: stabilization_none.c:42
guidance_h_init
void guidance_h_init(void)
Definition: guidance_h.c:176
Min
#define Min(x, y)
Definition: esc_dshot.c:85
RadioControl::values
pprz_t values[RADIO_CONTROL_NB_CHANNEL]
Definition: radio_control.h:69
GUIDANCE_H_THRUST_CMD_FILTER
#define GUIDANCE_H_THRUST_CMD_FILTER
Definition: guidance_h.c:464
heading
float heading
Definition: wedgebug.c:258
GUIDANCE_H_REF_MAX_SPEED
#define GUIDANCE_H_REF_MAX_SPEED
Default speed saturation.
Definition: guidance_h_ref.h:37
PPRZ_ITRIG_SIN
#define PPRZ_ITRIG_SIN(_s, _a)
Definition: pprz_trig_int.h:109