44 #include "pprzlink/pprzlink_device.h"
45 #include "pprzlink/pprzlink_transport.h"
48 #ifndef NAVIGATION_FREQUENCY
49 #define NAVIGATION_FREQUENCY 20
52 #define NAV_GRAVITY 9.806
53 #define Square(_x) ((_x)*(_x))
54 #define DistanceSquare(p1_x, p1_y, p2_x, p2_y) (Square(p1_x-p2_x)+Square(p1_y-p2_y))
56 #define PowerVoltage() (electrical.vsupply)
57 #define RcRoll(travel) (radio_control_get(RADIO_ROLL) * (float)travel /(float)MAX_PPRZ)
85 #define NAV_MODE_ROLL 1
86 #define NAV_MODE_COURSE 2
90 #define HORIZONTAL_MODE_WAYPOINT 0
91 #define HORIZONTAL_MODE_ROUTE 1
92 #define HORIZONTAL_MODE_CIRCLE 2
96 #define NavGotoWaypoint(_wp) { \
97 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
98 fly_to_xy(waypoints[_wp].x, waypoints[_wp].y); \
101 #define NavGotoPoint(_point) { \
102 horizontal_mode = HORIZONTAL_MODE_WAYPOINT; \
103 fly_to_xy(_point.x, _point.y); \
109 #define Eight(a, b, c) nav_eight((a), (b), (c))
114 #define Oval(a, b, c) nav_oval((b), (a), (c))
142 #define RCLost() RadioControlIsLost()
145 #define NavFollow(_ac_id, _distance, _height) nav_follow(_ac_id, _distance, _height)
149 #define NavGlide(_start_wp, _wp) nav_glide(_start_wp, _wp)
151 #define NavCircleWaypoint(wp, radius) \
152 nav_circle_XY(waypoints[wp].x, waypoints[wp].y, radius)
154 #define NavCircleCountNoRewind() (nav_circle_radians_no_rewind / (2*M_PI))
155 #define NavCircleCount() (fabs(nav_circle_radians) / (2*M_PI))
156 #define NavCircleQdr() ({ float qdr = DegOfRad(M_PI_2 - nav_circle_trigo_qdr); NormCourse(qdr); qdr; })
158 #define CloseDegAngles(_c1, _c2) ({ float _diff = _c1 - _c2; NormCourse(_diff); 350 < _diff || _diff < 10; })
161 #define NavQdrCloseTo(x) CloseDegAngles(x, NavCircleQdr())
163 #define NavCourseCloseTo(x) CloseDegAngles(x, DegOfRad(stateGetHorizontalSpeedDir_f()))
166 extern void nav_route_xy(
float last_wp_x,
float last_wp_y,
float wp_x,
float wp_y);
167 #define NavSegment(_start, _end) \
168 nav_route_xy(waypoints[_start].x, waypoints[_start].y, waypoints[_end].x, waypoints[_end].y)
170 bool nav_approaching_xy(
float x,
float y,
float from_x,
float from_y,
float approaching_time);
171 #define NavApproaching(wp, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, last_x, last_y, time)
172 #define NavApproachingFrom(wp, from, time) nav_approaching_xy(waypoints[wp].x, waypoints[wp].y, waypoints[from].x, waypoints[from].y, time)
177 #define NavVerticalAutoThrottleMode(_pitch) { \
178 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_THROTTLE; \
179 nav_pitch = _pitch; \
184 #define NavVerticalAutoPitchMode(_throttle) { \
185 v_ctl_climb_mode = V_CTL_CLIMB_MODE_AUTO_PITCH; \
186 nav_throttle_setpoint = _throttle; \
191 #define NavVerticalAltitudeMode(_alt, _pre_climb) { \
192 v_ctl_mode = V_CTL_MODE_AUTO_ALT; \
193 nav_altitude = _alt; \
194 v_ctl_altitude_pre_climb = _pre_climb; \
198 #define NavVerticalClimbMode(_climb) { \
199 v_ctl_mode = V_CTL_MODE_AUTO_CLIMB; \
200 v_ctl_climb_setpoint = _climb; \
204 #define NavVerticalThrottleMode(_throttle) { \
205 v_ctl_mode = V_CTL_MODE_AUTO_THROTTLE; \
206 nav_throttle_setpoint = _throttle; \
209 #define NavHeading(_course) { \
210 lateral_mode = LATERAL_MODE_COURSE; \
211 h_ctl_course_setpoint = _course; \
214 #define NavAttitude(_roll) { \
215 lateral_mode = LATERAL_MODE_ROLL; \
216 if(autopilot_get_mode() != AP_MODE_AUTO1) \
217 {h_ctl_roll_setpoint = _roll;} \
220 #define NavSetMaxSpeed(_speed) {}
222 #define nav_IncreaseShift(x) { if (x==0) nav_shift = 0; else nav_shift += x; }
224 #define nav_SetNavRadius(x) { if (x==1) nav_radius = DEFAULT_CIRCLE_RADIUS; else if (x==-1) nav_radius = -DEFAULT_CIRCLE_RADIUS; else nav_radius = x; }
226 #define NavKillThrottle() { autopilot_set_kill_throttle(true); }
229 #define GetPosX() (stateGetPositionEnu_f()->x)
231 #define GetPosY() (stateGetPositionEnu_f()->y)
233 #define GetPosAlt() (stateGetPositionUtm_f()->alt)
235 #define GetPosHeight() (stateGetPositionEnu_f()->z)
242 #define GetAltRef() (ground_alt)
245 #define SEND_NAVIGATION(_trans, _dev) { \
246 uint8_t _circle_count = NavCircleCount(); \
247 struct EnuCoor_f* pos = stateGetPositionEnu_f(); \
248 float dist_wp = sqrtf(dist2_to_wp); \
249 float dist_home = sqrtf(dist2_to_home); \
250 uint8_t kill = (uint8_t)autopilot.kill_throttle; \
251 pprz_msg_send_NAVIGATION(_trans, _dev, AC_ID, &nav_block, &nav_stage, &(pos->x), &(pos->y), &dist_wp, &dist_home, &autopilot.flight_time, &block_time, &stage_time, &kill, &_circle_count, &nav_oval_count); \
Core autopilot interface common to all firmwares.
Common flight_plan functions shared between fixedwing and rotorcraft.
void nav_home(void)
Home mode navigation (circle around HOME)
void nav_eight(uint8_t, uint8_t, float)
Navigation along a figure 8.
float nav_glide_pitch_trim
float flight_altitude
Dynamically adjustable, reset to nav_altitude when it is changing.
bool nav_approaching_xy(float x, float y, float from_x, float from_y, float approaching_time)
Decide if the UAV is approaching the current waypoint.
uint8_t nav_oval_count
Navigation along a figure O.
float nav_ground_speed_pgain
void nav_compute_baseleg(uint8_t wp_af, uint8_t wp_td, uint8_t wp_baseleg, float radius)
void nav_oval(uint8_t, uint8_t, float)
pprz_t nav_throttle_setpoint
void nav_init(void)
Navigation Initialisation.
void nav_follow(uint8_t _ac_id, float _distance, float _height)
void DownlinkSendWpNr(uint8_t _wp)
float nav_circle_trigo_qdr
float nav_circle_radians_no_rewind
void nav_glide_alt(float start_alt, float final_alt)
void nav_route_xy(float last_wp_x, float last_wp_y, float wp_x, float wp_y)
Computes the carrot position along the desired segment.
void nav_parse_MOVE_WP(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
void nav_without_gps(void)
Failsafe navigation without position estimation.
void nav_circle_XY(float x, float y, float radius)
Angle from center to mobile.
void nav_periodic_task(void)
Navigation main: call to the code generated from the XML flight plan.
void nav_compute_final_from_glide(uint8_t wp_af, uint8_t wp_td, float glide)
float nav_circle_radians
Status on the current circle.
void nav_eight_init(void)
void fly_to_xy(float x, float y)
Computes desired_x, desired_y and desired_course.
float nav_ground_speed_setpoint
void nav_glide(uint8_t start_wp, uint8_t wp)
void nav_parse_BLOCK(struct link_device *dev, struct transport_tx *trans, uint8_t *buf)
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.