Paparazzi UAS  v7.0_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 "-Waddress-of-packed-member"
37 #pragma GCC diagnostic ignored "-Wswitch-default"
38 #include "mavlink/paparazzi/mavlink.h"
39 #pragma GCC diagnostic pop
40 
41 // for waypoints, include correct header until we have unified API
42 #if defined(FIXEDWING_FIRMWARE)
43 #include "modules/nav/common_nav.h"
44 #elif defined(ROTORCRAFT_FIRMWARE)
46 #else
47 #error "Mission manager: unsupported firmware"
48 #endif
49 #include "generated/flight_plan.h"
50 
51 #include "mcu_periph/sys_time.h"
52 
53 
55 {
56  mgr->seq = 0;
57  mgr->timer_id = -1;
58 }
59 
61 {
62  if (mission_mgr.timer_id < 0) {
64  }
65  else {
67  }
68 }
69 
71 {
72  if (mission_mgr.timer_id >= 0) {
74  }
75  mission_mgr.timer_id = -1;
76 }
77 
78 void mavlink_mission_message_handler(const mavlink_message_t *msg)
79 {
81 
83 
84  if (msg->msgid == MAVLINK_MSG_ID_MISSION_ACK) {
85  MAVLINK_DEBUG("Received MISSION_ACK message\n");
88  MAVLINK_DEBUG("State: %d\n", mission_mgr.state);
89  }
90 }
91 
94 {
95  // FIXME: really use the SCRIPT_ITEM message to indicate current block?
98  mavlink_msg_script_current_send(MAVLINK_COMM_0, get_nav_block());
100  }
101  // check if we had a timeout on a transaction
105  mission_mgr.seq = 0;
106  MAVLINK_DEBUG("Warning: Mavlink mission request timed out!\n");
107  }
108 }
109 
111 {
112  mavlink_msg_mission_ack_send(MAVLINK_COMM_0, mission_mgr.rem_sysid, mission_mgr.rem_compid,
113  MAV_MISSION_ACCEPTED, MAV_MISSION_TYPE_MISSION);
115  MAVLINK_DEBUG("Sent MISSION_ACK message\n");
116 }
void mavlink_block_message_handler(const mavlink_message_t *msg)
Definition: blocks.c:65
PPRZ specific mission block implementation.
uint8_t get_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