Paparazzi UAS  v6.3_unstable
Paparazzi is a free software Unmanned Aircraft System.
mission_manager.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Lodewijk Sikkel <l.n.c.sikkel@tudelft.nl>
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  */
22 
27 // Include own header
29 
33 
34 // include mavlink headers, but ignore some warnings
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wswitch-default"
37 #include "mavlink/paparazzi/mavlink.h"
38 #pragma GCC diagnostic pop
39 
40 // for waypoints, include correct header until we have unified API
41 #if defined(FIXEDWING_FIRMWARE)
42 #include "modules/nav/common_nav.h"
43 #elif defined(ROTORCRAFT_FIRMWARE)
45 #else
46 #error "Mission manager: unsupported firmware"
47 #endif
48 #include "generated/flight_plan.h"
49 
50 #include "mcu_periph/sys_time.h"
51 
52 
54 {
55  mgr->seq = 0;
56  mgr->timer_id = -1;
57 }
58 
60 {
61  if (mission_mgr.timer_id < 0) {
63  }
64  else {
66  }
67 }
68 
70 {
71  if (mission_mgr.timer_id >= 0) {
73  }
74  mission_mgr.timer_id = -1;
75 }
76 
77 void mavlink_mission_message_handler(const mavlink_message_t *msg)
78 {
80 
82 
83  if (msg->msgid == MAVLINK_MSG_ID_MISSION_ACK) {
84  MAVLINK_DEBUG("Received MISSION_ACK message\n");
87  MAVLINK_DEBUG("State: %d\n", mission_mgr.state);
88  }
89 }
90 
93 {
94  // FIXME: really use the SCRIPT_ITEM message to indicate current block?
97  mavlink_msg_script_current_send(MAVLINK_COMM_0, nav_block);
99  }
100  // check if we had a timeout on a transaction
104  mission_mgr.seq = 0;
105  MAVLINK_DEBUG("Warning: Mavlink mission request timed out!\n");
106  }
107 }
108 
110 {
111  mavlink_msg_mission_ack_send(MAVLINK_COMM_0, mission_mgr.rem_sysid, mission_mgr.rem_compid,
112  MAV_MISSION_ACCEPTED);
114  MAVLINK_DEBUG("Sent MISSION_ACK message\n");
115 }
void mavlink_block_message_handler(const mavlink_message_t *msg)
Definition: blocks.c:64
PPRZ specific mission block implementation.
uint8_t nav_block
uint8_t msg[10]
Buffer used for general comunication over SPI (out buffer)
void mavlink_mission_init(mavlink_mission_mgr *mgr)
void mavlink_send_mission_ack(void)
void mavlink_mission_message_handler(const mavlink_message_t *msg)
void mavlink_mission_set_timer(void)
void mavlink_mission_periodic(void)
update current block and send if changed
void mavlink_mission_cancel_timer(void)
Common functions used within the mission library, blocks and waypoints cannot be send simultaneously ...
enum MAVLINK_MISSION_MGR_STATES state
#define MAVLINK_TIMEOUT
@ STATE_IDLE
Rotorcraft navigation functions.
void sys_time_update_timer(tid_t id, float duration)
Update the duration until a timer elapses.
Definition: sys_time.c:86
tid_t sys_time_register_timer(float duration, sys_time_cb cb)
Register a new system timer.
Definition: sys_time.c:43
void sys_time_cancel_timer(tid_t id)
Cancel a system timer by id.
Definition: sys_time.c:76
Architecture independent timing functions.
static bool sys_time_check_and_ack_timer(tid_t id)
Check if timer has elapsed.
Definition: sys_time.h:123