Skip to content

Commit

Permalink
Fixed copilot module to work both with rotorcraft and fixedwing firmw…
Browse files Browse the repository at this point in the history
…ares
  • Loading branch information
podhrmic committed May 6, 2017
1 parent de58bd5 commit af56804
Show file tree
Hide file tree
Showing 7 changed files with 253 additions and 60 deletions.
1 change: 1 addition & 0 deletions conf/firmwares/rotorcraft.makefile
Expand Up @@ -43,6 +43,7 @@ VPATH += $(PAPARAZZI_HOME)/var/share
## COMMON ROTORCRAFT ALL TARGETS (AP + NPS)
##

$(TARGET).CFLAGS += -DFIRMWARE=ROTORCRAFT
$(TARGET).CFLAGS += $(ROTORCRAFT_INC)
$(TARGET).CFLAGS += -DBOARD_CONFIG=$(BOARD_CFG)
$(TARGET).CFLAGS += -DPERIPHERALS_AUTO_INIT
Expand Down
2 changes: 1 addition & 1 deletion conf/firmwares/subsystems/fixedwing/autopilot.makefile
Expand Up @@ -25,7 +25,7 @@
##
## COMMON FIXEDWING ALL TARGETS (SIM + AP + FBW ...)
##

$(TARGET).CFLAGS += -DFIRMWARE=FIXEDWING

#
# Board config + Include paths
Expand Down
22 changes: 21 additions & 1 deletion conf/modules/copilot.xml
Expand Up @@ -35,7 +35,27 @@
<datalink message="COPILOT_STATUS_DL" fun="copilot_parse_copilot_status_dl(buf)"/>
<datalink message="MOVE_WP" fun="copilot_parse_move_wp_dl(buf)"/>
<makefile target="ap">
<file name="copilot.c"/>
<file name="copilot_common.c"/>
<raw>
# attach the correct file based on firmware
RESULT=0

ifneq (,$(findstring ROTORCRAFT,$($(TARGET).CFLAGS)))
# Rotorcraft
RESULT=1
$(TARGET).srcs += $(SRC_MODULES)/mission/copilot_rotorcraft.c
endif

ifneq (,$(findstring FIXEDWING,$($(TARGET).CFLAGS)))
# Fixedwing
$(TARGET).srcs += $(SRC_MODULES)/mission/copilot_fixedwing.c
RESULT=1
endif

ifeq ($(RESULT), 0)
$(error Error: Copilot module can be compiled only in Fixeding or Rotorcraft firmware. Please check your firmware.)
endif
</raw>
</makefile>
</module>

5 changes: 5 additions & 0 deletions sw/airborne/modules/mission/copilot.h
Expand Up @@ -46,6 +46,11 @@

#include "subsystems/datalink/datalink.h"
#include "modules/datalink/extra_pprz_dl.h"
#include "pprz_mutex.h"

PPRZ_MUTEX_DECL(copilot_cam_snapshot_mtx);
PPRZ_MUTEX_DECL(copilot_cam_payload_mtx);
PPRZ_MUTEX_DECL(copilot_status_mtx);

struct CameraPayload {
float timestamp;
Expand Down
Expand Up @@ -20,7 +20,7 @@
*
*/
/**
* @file "modules/mission/copilot.c"
* @file "modules/mission/copilot_common.c"
*
* Mission Computer module, interfacing the mission computer (also known as Copilot),
* based losely on
Expand All @@ -43,14 +43,6 @@

#include "modules/mission/copilot.h"
#include "subsystems/datalink/telemetry.h"
#include <string.h>

#include "pprz_mutex.h"

// needed for WP_MOVED confirmation
#include "firmwares/fixedwing/nav.h"
#include "subsystems/navigation/common_nav.h"
#include "math/pprz_geodetic_float.h"

bool send_cam_snapshot;
bool send_cam_payload;
Expand Down Expand Up @@ -196,52 +188,3 @@ void copilot_parse_copilot_status_dl(uint8_t *buf)

PPRZ_MUTEX_UNLOCK(copilot_status_mtx);
}

/**
* If MOVE_WP from GCS
* - processed in firmware_parse_msg(dev, trans, buf); with regular buffer
* - reponse over telemetry (regular buffer)
* - here send WP_MOVED over extra_dl
*
* If MOVE_WP from extra_dl
* - processed in firmware_parse_msg(dev, trans, buf); with extra buffer
* - response over extra_dl
* - send an update to GCS
*
* In both cases, the MOVE_WP message was already processed in firmware_parse
* here we are taking care only about propagating the change
*
*/
void copilot_parse_move_wp_dl(uint8_t *buf)
{
if (DL_MOVE_WP_ac_id(buf) == AC_ID) {
uint8_t wp_id = DL_MOVE_WP_wp_id(buf);

/* Computes from (lat, long) in the referenced UTM zone */
struct LlaCoor_f lla;
lla.lat = RadOfDeg((float)(DL_MOVE_WP_lat(buf) / 1e7));
lla.lon = RadOfDeg((float)(DL_MOVE_WP_lon(buf) / 1e7));
lla.alt = ((float)(DL_MOVE_WP_alt(buf)))/1000.;
struct UtmCoor_f utm;
utm.zone = nav_utm_zone0;
utm_of_lla_f(&utm, &lla);

// Waypoint range is limited. Computes the UTM pos back from the relative
// coordinates */
utm.east = waypoints[wp_id].x + nav_utm_east0;
utm.north = waypoints[wp_id].y + nav_utm_north0;

if (buf == extra_dl_buffer) {
// MOVE_WP came from extra_dl, respond over telemetry
DOWNLINK_SEND_WP_MOVED(DefaultChannel, DefaultDevice,
&wp_id, &utm.east, &utm.north, &utm.alt, &nav_utm_zone0);
}

if (buf == dl_buffer) {
// MOVE_WP came over telemetry, respond over extra_dl
DOWNLINK_SEND_WP_MOVED(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,
&wp_id, &utm.east, &utm.north, &utm.alt, &nav_utm_zone0);
}

}
}
103 changes: 103 additions & 0 deletions sw/airborne/modules/mission/copilot_fixedwing.c
@@ -0,0 +1,103 @@
/*
* Copyright (C) 2016 2017 Michal Podhradsky <http://github.com/podhrmic>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/**
* @file "modules/mission/copilot_fixedwing.c"
*
* Mission Computer module, interfacing the mission computer (also known as Copilot),
* based losely on
* ISaAC: The Intelligent Safety and Airworthiness Co-Pilot module
* Based on paper "A Payload Verification and Management Framework
* for Small UAV-based Personal Remote Sensing Systems" by Cal Coopmans
* and Chris Coffin. Link: http://ieeexplore.ieee.org/abstract/document/6309316/
*
* More info can be found on http://wiki.paparazziuav.org/wiki/Mission_computer
*
* Copilot is intended mainly for mapping applications.
*
* This module processes messages from Copilot, and either forwards them to the GCS
* (such as CAMERA_SNAPSHOT or CAMERA_PAYLOAD messages), or responds to them as necessary
* (such as MOVE_WP).
*
* The module assumes the source of the messages is trusted (i.e. not authentication besides
* AC_ID check is performed).
*/

#include "modules/mission/copilot.h"
#include "subsystems/datalink/telemetry.h"

// needed for WP_MOVED confirmation
#include "firmwares/fixedwing/nav.h"
#include "subsystems/navigation/common_nav.h"
#include "math/pprz_geodetic_float.h"

/**
* If MOVE_WP from GCS
* - processed in firmware_parse_msg(dev, trans, buf); with regular buffer
* - reponse over telemetry (regular buffer)
* - here send WP_MOVED over extra_dl
*
* If MOVE_WP from extra_dl
* - processed in firmware_parse_msg(dev, trans, buf); with extra buffer
* - response over extra_dl
* - send an update to GCS
*
* In both cases, the MOVE_WP message was already processed in firmware_parse
* here we are taking care only about propagating the change
*
*/
void copilot_parse_move_wp_dl(uint8_t *buf)
{
if (DL_MOVE_WP_ac_id(buf) == AC_ID) {
uint8_t wp_id = DL_MOVE_WP_wp_id(buf);

if (wp_id >= nb_waypoint) {
return;
}

/* Computes from (lat, long) in the referenced UTM zone */
struct LlaCoor_f lla;
lla.lat = RadOfDeg((float)(DL_MOVE_WP_lat(buf) / 1e7));
lla.lon = RadOfDeg((float)(DL_MOVE_WP_lon(buf) / 1e7));
lla.alt = ((float)(DL_MOVE_WP_alt(buf)))/1000.;
struct UtmCoor_f utm;
utm.zone = nav_utm_zone0;
utm_of_lla_f(&utm, &lla);

// Waypoint range is limited. Computes the UTM pos back from the relative
// coordinates */
utm.east = waypoints[wp_id].x + nav_utm_east0;
utm.north = waypoints[wp_id].y + nav_utm_north0;

if (buf == extra_dl_buffer) {
// MOVE_WP came from extra_dl, respond over telemetry
DOWNLINK_SEND_WP_MOVED(DefaultChannel, DefaultDevice,
&wp_id, &utm.east, &utm.north, &utm.alt, &nav_utm_zone0);
}

if (buf == dl_buffer) {
// MOVE_WP came over telemetry, respond over extra_dl
DOWNLINK_SEND_WP_MOVED(extra_pprz_tp, EXTRA_DOWNLINK_DEVICE,
&wp_id, &utm.east, &utm.north, &utm.alt, &nav_utm_zone0);
}

}
}
121 changes: 121 additions & 0 deletions sw/airborne/modules/mission/copilot_rotorcraft.c
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2016 2017 Michal Podhradsky <http://github.com/podhrmic>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/**
* @file "modules/mission/copilot_rotorcraft.c"
*
* Mission Computer module, interfacing the mission computer (also known as Copilot),
* based losely on
* ISaAC: The Intelligent Safety and Airworthiness Co-Pilot module
* Based on paper "A Payload Verification and Management Framework
* for Small UAV-based Personal Remote Sensing Systems" by Cal Coopmans
* and Chris Coffin. Link: http://ieeexplore.ieee.org/abstract/document/6309316/
*
* More info can be found on http://wiki.paparazziuav.org/wiki/Mission_computer
*
* Copilot is intended mainly for mapping applications.
*
* This module processes messages from Copilot, and either forwards them to the GCS
* (such as CAMERA_SNAPSHOT or CAMERA_PAYLOAD messages), or responds to them as necessary
* (such as MOVE_WP).
*
* The module assumes the source of the messages is trusted (i.e. not authentication besides
* AC_ID check is performed).
*/

#include "modules/mission/copilot.h"
#include "subsystems/datalink/telemetry.h"

// needed for WP_MOVED confirmation
#include "firmwares/rotorcraft/navigation.h"
//#include "math/pprz_geodetic_float.h"
#include "math/pprz_geodetic_int.h"
//#include "state.h"

/**
* If MOVE_WP from GCS
* - processed in firmware_parse_msg(dev, trans, buf); with regular buffer
* - reponse over telemetry (regular buffer)
* - here send WP_MOVED over extra_dl
*
* If MOVE_WP from extra_dl
* - processed in firmware_parse_msg(dev, trans, buf); with extra buffer
* - response over extra_dl
* - send an update to GCS
*
* In both cases, the MOVE_WP message was already processed in firmware_parse
* here we are taking care only about propagating the change
*
*/
void copilot_parse_move_wp_dl(uint8_t *buf)
{
if (DL_MOVE_WP_ac_id(buf) == AC_ID) {
if (stateIsLocalCoordinateValid()) {
uint8_t wp_id = DL_MOVE_WP_wp_id(buf);
if (wp_id >= nb_waypoint) {
return;
}

struct LlaCoor_i lla;
lla.lat = DL_MOVE_WP_lat(buf);
lla.lon = DL_MOVE_WP_lon(buf);
/* WP_alt from message is alt above MSL in mm
* lla.alt is above ellipsoid in mm
*/
lla.alt = DL_MOVE_WP_alt(buf) - state.ned_origin_i.hmsl +
state.ned_origin_i.lla.alt;


if (waypoint_is_global(wp_id)) {
/* lla->alt is above ellipsoid, WP_MOVED_LLA has hmsl alt */
int32_t hmsl = lla.alt - state.ned_origin_i.lla.alt + state.ned_origin_i.hmsl;

if (buf == extra_dl_buffer) {
// MOVE_WP came from extra_dl, respond over telemetry
DOWNLINK_SEND_WP_MOVED_LLA(DefaultChannel, DefaultDevice, &wp_id,
&lla.lat, &lla.lon, &hmsl);
}

if (buf == dl_buffer) {
// MOVE_WP came over telemetry, respond over extra_dl
DOWNLINK_SEND_WP_MOVED_LLA(extra_pprz_tp, DefaultDevice, &wp_id,
&lla.lat, &lla.lon, &hmsl);
}
} else {
if (buf == extra_dl_buffer) {
// MOVE_WP came from extra_dl, respond over telemetry
DOWNLINK_SEND_WP_MOVED_ENU(DefaultChannel, DefaultDevice, &wp_id,
&waypoints[wp_id].enu_i.x,
&waypoints[wp_id].enu_i.y,
&waypoints[wp_id].enu_i.z);
}

if (buf == dl_buffer) {
// MOVE_WP came over telemetry, respond over extra_dl
DOWNLINK_SEND_WP_MOVED_ENU(extra_pprz_tp, DefaultDevice, &wp_id,
&waypoints[wp_id].enu_i.x,
&waypoints[wp_id].enu_i.y,
&waypoints[wp_id].enu_i.z);
}
}
}
}
}

0 comments on commit af56804

Please sign in to comment.