29 #include "physical_constants.h"
32 #include "flightstatus.h"
33 #include "pathdesired.h"
34 #include "pathplannersettings.h"
35 #include "pathstatus.h"
36 #include "positionactual.h"
38 #include "waypointactive.h"
39 #include "modulesettings.h"
44 #define STACK_SIZE_BYTES 1024
45 #define TASK_PRIORITY PIOS_THREAD_PRIO_LOW
46 #define MAX_QUEUE_SIZE 2
47 #define UPDATE_RATE_MS 20
67 void *ctx,
void *obj,
int len);
69 void *ctx,
void *obj,
int len);
105 #ifdef MODULE_PathPlanner_BUILTIN
108 uint8_t module_state[MODULESETTINGS_ADMINSTATE_NUMELEM];
109 ModuleSettingsAdminStateGet(module_state);
110 if (module_state[MODULESETTINGS_ADMINSTATE_PATHPLANNER] == MODULESETTINGS_ADMINSTATE_ENABLED) {
117 if (PathPlannerSettingsInitialize() == -1) {
123 if (WaypointInitialize() == -1 || WaypointActiveInitialize() == -1) {
130 FlightStatusConnectQueue(queue);
147 AlarmsSet(SYSTEMALARMS_ALARM_PATHPLANNER, SYSTEMALARMS_ALARM_CRITICAL);
160 FlightStatusData flightStatus;
163 bool pathplanner_active =
false;
183 FlightStatusGet(&flightStatus);
184 if (flightStatus.FlightMode != FLIGHTSTATUS_FLIGHTMODE_PATHPLANNER) {
185 pathplanner_active =
false;
189 if(pathplanner_active ==
false) {
201 pathplanner_active =
true;
223 void *ctx,
void *obj,
int len)
225 (void) ev; (void) ctx; (void) obj; (void) len;
227 FlightStatusData flightStatus;
228 FlightStatusGet(&flightStatus);
229 if (flightStatus.FlightMode != FLIGHTSTATUS_FLIGHTMODE_PATHPLANNER)
244 void *ctx,
void *obj,
int len)
246 (void) ev; (void) ctx; (void) obj; (void) len;
250 PathStatusGet(&pathStatus);
252 if ((pathStatus.Status == PATHSTATUS_STATUS_COMPLETED) &&
265 PositionActualData position;
266 PositionActualGet(&position);
269 pathDesired.Start[PATHDESIRED_START_NORTH] = position.North;
270 pathDesired.Start[PATHDESIRED_START_EAST] = position.East;
271 pathDesired.Start[PATHDESIRED_START_DOWN] = position.Down;
272 pathDesired.End[PATHDESIRED_END_NORTH] = position.North;
273 pathDesired.End[PATHDESIRED_END_EAST] = position.East;
274 pathDesired.End[PATHDESIRED_END_DOWN] = position.Down;
275 pathDesired.Mode = PATHDESIRED_MODE_HOLDPOSITION;
276 pathDesired.StartingVelocity = 5;
277 pathDesired.EndingVelocity = 5;
278 pathDesired.ModeParameters = 0;
279 pathDesired.Waypoint = -1;
280 PathDesiredSet(&pathDesired);
291 WaypointInstGet(idx, &waypoint);
293 PositionActualData position;
294 PositionActualGet(&position);
297 pathDesired.Start[PATHDESIRED_START_NORTH] = position.North;
298 pathDesired.Start[PATHDESIRED_START_EAST] = position.East;
299 pathDesired.Start[PATHDESIRED_START_DOWN] = position.Down;
300 pathDesired.End[PATHDESIRED_END_NORTH] = waypoint.Position[WAYPOINT_POSITION_NORTH];
301 pathDesired.End[PATHDESIRED_END_EAST] = waypoint.Position[WAYPOINT_POSITION_EAST];
302 pathDesired.End[PATHDESIRED_END_DOWN] = waypoint.Position[WAYPOINT_POSITION_DOWN];
303 pathDesired.Mode = PATHDESIRED_MODE_HOLDPOSITION;
304 pathDesired.StartingVelocity = 5;
305 pathDesired.EndingVelocity = 5;
306 pathDesired.ModeParameters = 0;
307 pathDesired.Waypoint = -1;
308 PathDesiredSet(&pathDesired);
312 if (idx < 0)
return false;
320 WaypointInstGet(idx, &waypoint);
323 if (waypoint.Mode == WAYPOINT_MODE_INVALID) {
369 AlarmsSet(SYSTEMALARMS_ALARM_PATHPLANNER, SYSTEMALARMS_ALARM_ERROR);
379 pathDesired.Waypoint = idx;
381 pathDesired.End[PATHDESIRED_END_NORTH] =
waypoint.Position[WAYPOINT_POSITION_NORTH];
382 pathDesired.End[PATHDESIRED_END_EAST] =
waypoint.Position[WAYPOINT_POSITION_EAST];
383 pathDesired.End[PATHDESIRED_END_DOWN] =
waypoint.Position[WAYPOINT_POSITION_DOWN];
384 pathDesired.ModeParameters =
waypoint.ModeParameters;
389 case WAYPOINT_MODE_VECTOR:
390 pathDesired.Mode = PATHDESIRED_MODE_VECTOR;
392 case WAYPOINT_MODE_ENDPOINT:
393 pathDesired.Mode = PATHDESIRED_MODE_ENDPOINT;
395 case WAYPOINT_MODE_CIRCLELEFT:
396 pathDesired.Mode = PATHDESIRED_MODE_CIRCLELEFT;
398 case WAYPOINT_MODE_CIRCLERIGHT:
399 pathDesired.Mode = PATHDESIRED_MODE_CIRCLERIGHT;
401 case WAYPOINT_MODE_LAND:
402 pathDesired.Mode = PATHDESIRED_MODE_LAND;
406 AlarmsSet(SYSTEMALARMS_ALARM_PATHPLANNER, SYSTEMALARMS_ALARM_ERROR);
410 pathDesired.EndingVelocity =
waypoint.Velocity;
414 PositionActualData positionActual;
415 PositionActualGet(&positionActual);
417 pathDesired.Start[PATHDESIRED_START_NORTH] = positionActual.North;
418 pathDesired.Start[PATHDESIRED_START_EAST] = positionActual.East;
419 pathDesired.Start[PATHDESIRED_START_DOWN] = positionActual.Down - 1;
420 pathDesired.StartingVelocity =
waypoint.Velocity;
423 WaypointData waypointPrev;
426 pathDesired.Start[PATHDESIRED_END_NORTH] = waypointPrev.Position[WAYPOINT_POSITION_NORTH];
427 pathDesired.Start[PATHDESIRED_END_EAST] = waypointPrev.Position[WAYPOINT_POSITION_EAST];
428 pathDesired.Start[PATHDESIRED_END_DOWN] = waypointPrev.Position[WAYPOINT_POSITION_DOWN];
429 pathDesired.StartingVelocity = waypointPrev.Velocity;
432 PathDesiredSet(&pathDesired);
447 case PATHPLANNERSETTINGS_PREPROGRAMMEDPATH_NONE:
449 case PATHPLANNERSETTINGS_PREPROGRAMMEDPATH_10M_BOX:
452 case PATHPLANNERSETTINGS_PREPROGRAMMEDPATH_LOGO:
462 WaypointCreateInstance();
463 WaypointCreateInstance();
464 WaypointCreateInstance();
465 WaypointCreateInstance();
466 WaypointCreateInstance();
470 waypoint.Velocity = 2.5;
471 waypoint.Mode = WAYPOINT_MODE_VECTOR;
473 waypoint.Position[0] = 0;
474 waypoint.Position[1] = 0;
475 waypoint.Position[2] = -10;
476 WaypointInstSet(0, &waypoint);
478 waypoint.Position[0] = 5;
479 waypoint.Position[1] = 5;
480 waypoint.Position[2] = -10;
481 WaypointInstSet(1, &waypoint);
483 waypoint.Position[0] = -5;
484 waypoint.Position[1] = 5;
485 waypoint.Mode = WAYPOINT_MODE_VECTOR;
486 waypoint.ModeParameters = 35;
487 WaypointInstSet(2, &waypoint);
489 waypoint.Position[0] = -5;
490 waypoint.Position[1] = -5;
491 WaypointInstSet(3, &waypoint);
493 waypoint.Position[0] = 5;
494 waypoint.Position[1] = -5;
495 WaypointInstSet(4, &waypoint);
497 waypoint.Position[0] = 5;
498 waypoint.Position[1] = 5;
499 WaypointInstSet(5, &waypoint);
501 waypoint.Position[0] = 0;
502 waypoint.Position[1] = 0;
503 waypoint.Mode = WAYPOINT_MODE_VECTOR;
504 WaypointInstSet(6, &waypoint);
511 waypoint.Velocity = 5;
512 waypoint.Mode = WAYPOINT_MODE_VECTOR;
513 waypoint.ModeParameters = 0;
514 waypoint.Position[2] = -20;
516 waypoint.Position[0] = 6.49;
517 waypoint.Position[1] = -9.52;
518 WaypointInstSet(0, &waypoint);
520 waypoint.Position[0] = 6.32;
521 waypoint.Position[1] = -94.82;
522 WaypointCreateInstance();
523 WaypointInstSet(1, &waypoint);
525 waypoint.Position[0] = 6.32;
526 waypoint.Position[1] = -77.13;
527 WaypointCreateInstance();
528 WaypointInstSet(2, &waypoint);
530 waypoint.Position[0] = -17.04;
531 waypoint.Position[1] = -77.071;
532 WaypointCreateInstance();
533 WaypointInstSet(3, &waypoint);
535 waypoint.Position[0] = -26.42;
536 waypoint.Position[1] = -69.30;
537 waypoint.Mode = WAYPOINT_MODE_CIRCLELEFT;
538 waypoint.ModeParameters = 10;
539 WaypointCreateInstance();
540 WaypointInstSet(4, &waypoint);
542 waypoint.Position[0] = -27.06;
543 waypoint.Position[1] = -59.58;
544 waypoint.Mode = WAYPOINT_MODE_VECTOR;
545 waypoint.ModeParameters = 0;
546 WaypointCreateInstance();
547 WaypointInstSet(5, &waypoint);
549 waypoint.Position[0] = -22.37;
550 waypoint.Position[1] = -51.81;
551 waypoint.Mode = WAYPOINT_MODE_CIRCLELEFT;
552 waypoint.ModeParameters = 8;
553 WaypointCreateInstance();
554 WaypointInstSet(6, &waypoint);
556 waypoint.Position[0] = -4.25;
557 waypoint.Position[1] = -38.64;
558 waypoint.Mode = WAYPOINT_MODE_VECTOR;
559 waypoint.ModeParameters = 0;
560 WaypointCreateInstance();
561 WaypointInstSet(7, &waypoint);
563 waypoint.Position[0] = 6.33;
564 waypoint.Position[1] = -45.74;
565 waypoint.Mode = WAYPOINT_MODE_CIRCLELEFT;
566 waypoint.ModeParameters = 10;
567 WaypointCreateInstance();
568 WaypointInstSet(8, &waypoint);
570 waypoint.Position[0] = -5.11;
571 waypoint.Position[1] = -52.46;
572 waypoint.Mode = WAYPOINT_MODE_CIRCLELEFT;
573 waypoint.ModeParameters = 10;
574 WaypointCreateInstance();
575 WaypointInstSet(9, &waypoint);
577 waypoint.Position[0] = -26.84;
578 waypoint.Position[1] = -41.45;
579 waypoint.Mode = WAYPOINT_MODE_VECTOR;
580 waypoint.ModeParameters = 0;
581 WaypointCreateInstance();
582 WaypointInstSet(10, &waypoint);
584 waypoint.Position[0] = -18.11;
585 waypoint.Position[1] = -34.11;
586 waypoint.Mode = WAYPOINT_MODE_CIRCLERIGHT;
587 waypoint.ModeParameters = 10;
588 WaypointCreateInstance();
589 WaypointInstSet(11, &waypoint);
591 waypoint.Position[0] = -10.65;
592 waypoint.Position[1] = -3.45;
593 waypoint.Mode = WAYPOINT_MODE_VECTOR;
594 waypoint.ModeParameters = 0;
595 WaypointCreateInstance();
596 WaypointInstSet(12, &waypoint);
static WaypointData waypoint
struct pios_queue * PIOS_Queue_Create(size_t queue_length, size_t item_size)
static PathDesiredData pathDesired
bool TaskMonitorQueryRunning(TaskInfoRunningElem task)
static void process_pp_settings()
static void pathPlannerTask(void *parameters)
static void pathStatusUpdated(const UAVObjEvent *ev, void *ctx, void *obj, int len)
static struct pios_queue * queue
void UAVObjCbSetFlag(const UAVObjEvent *objEv, void *ctx, void *obj, int len)
int32_t AlarmsSet(SystemAlarmsAlarmElem alarm, SystemAlarmsAlarmOptions severity)
static bool path_completed
static PathStatusData pathStatus
bool PIOS_Queue_Receive(struct pios_queue *queuep, void *itemp, uint32_t timeout_ms)
static void createPathBox()
int32_t PathPlannerStart()
Path calculation library with common API.
static PathPlannerSettingsData pathPlannerSettings
static struct pios_thread * taskHandle
#define MODULE_INITCALL(ifn, sfn)
struct pios_thread * PIOS_Thread_Create(void(*fp)(void *), const char *namep, size_t stack_bytes, void *argp, enum pios_thread_prio_e prio)
int32_t TaskMonitorAdd(TaskInfoRunningElem task, struct pios_thread *threadp)
static void activateWaypoint(int idx)
static void advanceWaypoint()
int32_t PathPlannerInitialize()
static int32_t active_waypoint
Store which waypoint has actually been pushed into PathDesired.
void PIOS_Thread_Sleep(uint32_t time_ms)
static void waypointsUpdated(const UAVObjEvent *ev, void *ctx, void *obj, int len)
static WaypointActiveData waypointActive
Includes PiOS and core architecture components.
int32_t AlarmsClear(SystemAlarmsAlarmElem alarm)
uint16_t UAVObjGetNumInstances(UAVObjHandle obj)
static volatile bool pathplanner_config_dirty
static bool module_enabled
static void holdCurrentPosition()
static void holdPosition(uint32_t idx)
static bool waypointValid(int32_t idx)
static int32_t previous_waypoint
Store the previous waypoint which is used to determine the path trajectory.
static void createPathLogo()