diff --git a/conf/airframes/ardrone2_opticflow_hover.xml b/conf/airframes/ardrone2_opticflow_hover.xml
index acc324ea64..6cdc37a5dd 100644
--- a/conf/airframes/ardrone2_opticflow_hover.xml
+++ b/conf/airframes/ardrone2_opticflow_hover.xml
@@ -216,7 +216,7 @@
diff --git a/conf/modules/cv_opticflow.xml b/conf/modules/cv_opticflow.xml
index 8af8ea94d1..5d2fb518a0 100644
--- a/conf/modules/cv_opticflow.xml
+++ b/conf/modules/cv_opticflow.xml
@@ -44,7 +44,6 @@
-
diff --git a/sw/airborne/firmwares/rotorcraft/autopilot.c b/sw/airborne/firmwares/rotorcraft/autopilot.c
index cae56817ba..3ce4b1846a 100644
--- a/sw/airborne/firmwares/rotorcraft/autopilot.c
+++ b/sw/airborne/firmwares/rotorcraft/autopilot.c
@@ -423,8 +423,10 @@ void autopilot_set_mode(uint8_t new_autopilot_mode)
case AP_MODE_NAV:
guidance_h_mode_changed(GUIDANCE_H_MODE_NAV);
break;
- case AP_MODE_MODULE_OUTERLOOP:
- guidance_h_mode_changed(GUIDANCE_H_MODE_MODULE_OUTERLOOP);
+ case AP_MODE_MODULE:
+#ifdef GUIDANCE_H_MODE_MODULE_SETTING
+ guidance_h_mode_changed(GUIDANCE_H_MODE_MODULE_SETTING);
+#endif
break;
default:
break;
@@ -467,8 +469,10 @@ void autopilot_set_mode(uint8_t new_autopilot_mode)
case AP_MODE_NAV:
guidance_v_mode_changed(GUIDANCE_V_MODE_NAV);
break;
- case AP_MODE_MODULE_OUTERLOOP:
- guidance_v_mode_changed(GUIDANCE_V_MODE_MODULE_OUTERLOOP);
+ case AP_MODE_MODULE:
+#ifdef GUIDANCE_V_MODE_MODULE_SETTING
+ guidance_v_mode_changed(GUIDANCE_V_MODE_MODULE);
+#endif
break;
default:
break;
diff --git a/sw/airborne/firmwares/rotorcraft/autopilot.h b/sw/airborne/firmwares/rotorcraft/autopilot.h
index cad980c508..8ee77b2aff 100644
--- a/sw/airborne/firmwares/rotorcraft/autopilot.h
+++ b/sw/airborne/firmwares/rotorcraft/autopilot.h
@@ -50,7 +50,7 @@
#define AP_MODE_RC_DIRECT 14 // Safety Pilot Direct Commands for helicopter direct control
#define AP_MODE_CARE_FREE_DIRECT 15
#define AP_MODE_FORWARD 16
-#define AP_MODE_MODULE_OUTERLOOP 17
+#define AP_MODE_MODULE 17
extern uint8_t autopilot_mode;
extern uint8_t autopilot_mode_auto2;
diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.c b/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.c
index 4b56a2f7c2..0737340fe8 100644
--- a/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.c
+++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.c
@@ -27,6 +27,7 @@
#include "generated/airframe.h"
#include "firmwares/rotorcraft/guidance/guidance_h.h"
+#include "firmwares/rotorcraft/guidance/guidance_module.h"
#include "firmwares/rotorcraft/stabilization.h"
#include "firmwares/rotorcraft/stabilization/stabilization_attitude_rc_setpoint.h"
#include "firmwares/rotorcraft/navigation.h"
@@ -252,7 +253,12 @@ void guidance_h_mode_changed(uint8_t new_mode)
stabilization_attitude_enter();
break;
- case GUIDANCE_H_MODE_MODULE_OUTERLOOP:
+#if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
+ case GUIDANCE_H_MODE_MODULE:
+ guidance_h_module_enter();
+ break;
+#endif
+
case GUIDANCE_H_MODE_NAV:
guidance_h_nav_enter();
#if NO_ATTITUDE_RESET_ON_MODE_CHANGE
@@ -305,7 +311,12 @@ void guidance_h_read_rc(bool_t in_flight)
#endif
break;
- case GUIDANCE_H_MODE_MODULE_OUTERLOOP:
+#if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
+ case GUIDANCE_H_MODE_MODULE:
+ guidance_h_module_read_rc();
+ break;
+#endif
+
case GUIDANCE_H_MODE_NAV:
if (radio_control.status == RC_OK) {
stabilization_attitude_read_rc_setpoint_eulers(&guidance_h_rc_sp, in_flight, FALSE, FALSE);
@@ -388,15 +399,12 @@ void guidance_h_run(bool_t in_flight)
}
stabilization_attitude_run(in_flight);
break;
- case GUIDANCE_H_MODE_MODULE_OUTERLOOP:
- if (!in_flight) {
- guidance_h_nav_enter();
-#if USE_MODULE_OUTERLOOP==1
- guidance_module_run(in_flight);
-#endif
- }
+#if GUIDANCE_H_MODE_MODULE_SETTING == GUIDANCE_H_MODE_MODULE
+ case GUIDANCE_H_MODE_MODULE:
+ guidance_h_module_run(in_flight);
break;
+#endif
default:
break;
diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.h b/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.h
index c9cd7ff394..574ea4444e 100644
--- a/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.h
+++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_h.h
@@ -49,15 +49,15 @@
#define GUIDANCE_H_USE_SPEED_REF TRUE
#endif
-#define GUIDANCE_H_MODE_KILL 0
-#define GUIDANCE_H_MODE_RATE 1
-#define GUIDANCE_H_MODE_ATTITUDE 2
-#define GUIDANCE_H_MODE_HOVER 3
-#define GUIDANCE_H_MODE_NAV 4
-#define GUIDANCE_H_MODE_RC_DIRECT 5
-#define GUIDANCE_H_MODE_CARE_FREE 6
-#define GUIDANCE_H_MODE_FORWARD 7
-#define GUIDANCE_H_MODE_MODULE_OUTERLOOP 8
+#define GUIDANCE_H_MODE_KILL 0
+#define GUIDANCE_H_MODE_RATE 1
+#define GUIDANCE_H_MODE_ATTITUDE 2
+#define GUIDANCE_H_MODE_HOVER 3
+#define GUIDANCE_H_MODE_NAV 4
+#define GUIDANCE_H_MODE_RC_DIRECT 5
+#define GUIDANCE_H_MODE_CARE_FREE 6
+#define GUIDANCE_H_MODE_FORWARD 7
+#define GUIDANCE_H_MODE_MODULE 8
extern uint8_t guidance_h_mode;
diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_module.h b/sw/airborne/firmwares/rotorcraft/guidance/guidance_module.h
new file mode 100644
index 0000000000..debdbf2005
--- /dev/null
+++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_module.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2008-2009 Antoine Drouin
+ *
+ * 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 firmwares/rotorcraft/guidance/guidance_module.h
+ * Guidance in a module file.
+ *
+ * If the module implements both V and H mode, take into account that the H is called first and later V
+ */
+
+#ifndef GUIDANCE_MODULE_H_
+#define GUIDANCE_MODULE_H_
+
+#include "generated/modules.h"
+
+/**
+ *
+ * Horizontal loop default is ATTITUDE
+ * e.g.: #define GUIDANCE_H_MODE_MODULE_SETTING GUIDANCE_H_MODE_ATTITUDE
+ *
+ * Implement own Horizontal loops when GUIDANCE_H_MODE_MODULE_SETTING is set to GUIDANCE_H_MODE_MODULE
+ * extern void guidance_h_module_enter(void);
+ * extern void guidance_h_module_read_rc(void);
+ * extern void guidance_h_module_run(bool_t in_flight);
+ *
+ * Vertical loop default is ATTITUDE
+ * e.g.: #define GUIDANCE_V_MODE_MODULE_SETTING GUIDANCE_V_MODE_RC_DIRECT
+ *
+ * Implement own Vertical loops when GUIDANCE_V_MODE_MODULE_SETTING is set to GUIDANCE_V_MODE_MODULE
+ * extern void guidance_v_module_enter(void);
+ * extern void guidance_v_module_run(bool_t in_flight);
+ */
+
+#endif /* GUIDANCE_MODULE_H_ */
diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c
index decc718ba0..c6d74dae38 100644
--- a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c
+++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.c
@@ -26,6 +26,7 @@
#include "generated/airframe.h"
#include "firmwares/rotorcraft/guidance/guidance_v.h"
+#include "firmwares/rotorcraft/guidance/guidance_module.h"
#include "subsystems/radio_control.h"
#include "firmwares/rotorcraft/stabilization.h"
@@ -232,12 +233,17 @@ void guidance_v_mode_changed(uint8_t new_mode)
case GUIDANCE_V_MODE_RC_CLIMB:
case GUIDANCE_V_MODE_CLIMB:
guidance_v_zd_sp = 0;
- case GUIDANCE_V_MODE_MODULE_OUTERLOOP:
case GUIDANCE_V_MODE_NAV:
guidance_v_z_sum_err = 0;
GuidanceVSetRef(stateGetPositionNed_i()->z, stateGetSpeedNed_i()->z, 0);
break;
+#if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
+ case GUIDANCE_V_MODE_MODULE:
+ guidance_v_module_enter();
+ break;
+#endif
+
default:
break;
@@ -308,19 +314,12 @@ void guidance_v_run(bool_t in_flight)
stabilization_cmd[COMMAND_THRUST] = guidance_v_delta_t;
break;
- case GUIDANCE_V_MODE_MODULE_OUTERLOOP:
- guidance_v_z_sp = -nav_flight_altitude;
- guidance_v_zd_sp = 0;
- gv_update_ref_from_z_sp(guidance_v_z_sp);
- run_hover_loop(in_flight);
-#if !NO_RC_THRUST_LIMIT
- /* use rc limitation if available */
- if (radio_control.status == RC_OK) {
- stabilization_cmd[COMMAND_THRUST] = Min(guidance_v_rc_delta_t, guidance_v_delta_t);
- } else
-#endif
- stabilization_cmd[COMMAND_THRUST] = guidance_v_delta_t;
+#if GUIDANCE_V_MODE_MODULE_SETTING == GUIDANCE_V_MODE_MODULE
+ case GUIDANCE_V_MODE_MODULE:
+ guidance_v_module_run(in_flight);
break;
+#endif
+
case GUIDANCE_V_MODE_NAV: {
if (vertical_mode == VERTICAL_MODE_ALT) {
guidance_v_z_sp = -nav_flight_altitude;
diff --git a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h
index 241757bab9..49053be7fd 100644
--- a/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h
+++ b/sw/airborne/firmwares/rotorcraft/guidance/guidance_v.h
@@ -32,13 +32,13 @@
#include "firmwares/rotorcraft/guidance/guidance_v_ref.h"
#include "firmwares/rotorcraft/guidance/guidance_v_adapt.h"
-#define GUIDANCE_V_MODE_KILL 0
-#define GUIDANCE_V_MODE_RC_DIRECT 1
-#define GUIDANCE_V_MODE_RC_CLIMB 2
-#define GUIDANCE_V_MODE_CLIMB 3
-#define GUIDANCE_V_MODE_HOVER 4
-#define GUIDANCE_V_MODE_NAV 5
-#define GUIDANCE_V_MODE_MODULE_OUTERLOOP 6
+#define GUIDANCE_V_MODE_KILL 0
+#define GUIDANCE_V_MODE_RC_DIRECT 1
+#define GUIDANCE_V_MODE_RC_CLIMB 2
+#define GUIDANCE_V_MODE_CLIMB 3
+#define GUIDANCE_V_MODE_HOVER 4
+#define GUIDANCE_V_MODE_NAV 5
+#define GUIDANCE_V_MODE_MODULE 6
extern uint8_t guidance_v_mode;
diff --git a/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.c b/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.c
index ec643f5205..983ea022d9 100644
--- a/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.c
+++ b/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.c
@@ -98,6 +98,27 @@ unsigned int set_heading;
#define VISION_DESIRED_VY 0.
#endif
+void guidance_h_module_enter(void)
+{
+ // INIT
+ Velx_Int = 0;
+ Vely_Int = 0;
+ // GUIDANCE: Set Hover-z-hold
+ guidance_v_z_sp = -1;
+}
+
+void guidance_h_module_read_rc(void)
+{
+ // Do not read RC
+ // Setpoint being set by vision
+}
+
+void guidance_h_module_run(bool_t in_flight)
+{
+ // Run
+ // Setpoint being set by vision
+ stabilization_attitude_run(in_flight);
+}
void init_hover_stabilization_onvision()
@@ -122,11 +143,8 @@ void init_hover_stabilization_onvision()
void run_hover_stabilization_onvision(void)
{
- if (autopilot_mode == AP_MODE_MODULE_OUTERLOOP) {
+ if (autopilot_mode == AP_MODE_MODULE) {
run_opticflow_hover();
- } else {
- Velx_Int = 0;
- Vely_Int = 0;
}
}
diff --git a/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.h b/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.h
index a0a69dda9c..6e5ec518cb 100644
--- a/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.h
+++ b/sw/airborne/modules/computer_vision/opticflow/hover_stabilization.h
@@ -31,6 +31,20 @@
#include
+// Controller module
+
+// Vertical loop re-uses Alt-hold
+#define GUIDANCE_V_MODE_MODULE_SETTING GUIDANCE_V_MODE_HOVER
+
+// Horizontal mode is a specific controller
+#define GUIDANCE_H_MODE_MODULE_SETTING GUIDANCE_H_MODE_MODULE
+
+// Implement own Horizontal loops
+extern void guidance_h_module_enter(void);
+extern void guidance_h_module_read_rc(void);
+extern void guidance_h_module_run(bool_t in_flight);
+
+
void init_hover_stabilization_onvision(void);
void run_hover_stabilization_onvision(void);
void run_opticflow_hover(void);
diff --git a/sw/airborne/modules/computer_vision/opticflow_module.c b/sw/airborne/modules/computer_vision/opticflow_module.c
index 4e62418a8b..3e9872e2e5 100644
--- a/sw/airborne/modules/computer_vision/opticflow_module.c
+++ b/sw/airborne/modules/computer_vision/opticflow_module.c
@@ -30,9 +30,6 @@
// Own header
#include "opticflow_module.h"
-// Navigate Based On Vision
-#include "opticflow/hover_stabilization.h"
-
// Paparazzi
#include "state.h" // for attitude
#include "boards/ardrone/navdata.h" // for ultrasound Height
@@ -96,13 +93,6 @@ void opticflow_module_run(void)
}
}
-#include "firmwares/rotorcraft/navigation.h"
-
-void guidance_module_run(bool_t inflight)
-{
- nav_flight_altitude = -1;
-}
-
/////////////////////////////////////////////////////////////////////////
// COMPUTER VISION THREAD
diff --git a/sw/airborne/modules/computer_vision/opticflow_module.h b/sw/airborne/modules/computer_vision/opticflow_module.h
index 14256bdb5e..e75f084bab 100644
--- a/sw/airborne/modules/computer_vision/opticflow_module.h
+++ b/sw/airborne/modules/computer_vision/opticflow_module.h
@@ -31,6 +31,9 @@
#include "std.h"
+// Navigate Based On Vision
+#include "opticflow/hover_stabilization.h"
+
// Module functions
extern void opticflow_module_init(void);
extern void opticflow_module_run(void);