Flying in a volume

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download

Flying in a volume

Postby waderic » Wed Sep 25, 2013 10:17 pm

Hello,

I am implementing flight in a volume for the multiwii. When the multicopter is getting out a cylinder, the failsafe alarm is running. My code is based on firmware 2.2. It had worked on one copter. I have a problem for making the buzzer working on another copter.
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby felixrising » Wed Sep 25, 2013 10:43 pm

Bradwii has geofence, might be worth checking his implementation as it's been well tested.
felixrising
 
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Flying in a volume

Postby waderic » Thu Sep 26, 2013 10:12 am

Thanks. I did not find Bradwii as user name in the forum list members.
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby timecop » Thu Sep 26, 2013 10:33 am

timecop
 
Posts: 1880
Joined: Fri Sep 02, 2011 4:48 pm

Re: Flying in a volume

Postby waderic » Thu Sep 26, 2013 2:43 pm

Thanks. Does anyone use buzzer with CRIUS AIOP V2 with multiwii 2.2 ? According to config.h, BUZZER PIN is on pin 8. But, it did not work.
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby felixrising » Thu Sep 26, 2013 3:11 pm

I moved mine to pin 33
felixrising
 
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Flying in a volume

Postby waderic » Thu Sep 26, 2013 3:37 pm

Is it a pad or pin 33 ? There is no pin labeled 33 on the CRIUS AIOP V2. There are 4 pad (32 to 37). In that case, you need to solder something on the board ?
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby waderic » Sat Sep 28, 2013 9:28 am

For using a buzzer with CRIUS All In One Pro V2 with multiwii 2.2, connector to the buzzer must be soudered with pin 32 as in this picture :

buzzer.jpg
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby felixrising » Sat Sep 28, 2013 10:43 am

You could just move it to pin 44, 45 or 46.. the crius define in def.h has cam trig, pitch and roll mapped to it, but if you're not using a camera or even all three of them, just remap it
felixrising
 
Posts: 244
Joined: Sat Mar 23, 2013 12:34 am
Location: Australia

Re: Flying in a volume

Postby waderic » Thu Dec 05, 2013 4:35 pm

Hi,

Here is my code for enabling an alarm when the copter is getting out a volume. I am using a CRIUS all-in-one pro v2.
It is enable by uncommenting the following lines
#define VOLUME_FLIGHT
#define VOLUME_HEIGTH_MAX 2
#define VOLUME_DISTANCE_MAX 10
It uses GPS for the distance and barometer for the altitude.

The code is based on Multiwii 2.3

-------------------------------------- CUT HERE ------------------------------------------------
Index: Alarms.cpp
===================================================================
--- Alarms.cpp (revision 18)
+++ Alarms.cpp (working copy)
@@ -85,6 +85,13 @@
else alarmArray[2] = 0;
#endif

+ #if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ if(f.VOLUME_MODE==1 && alarmArray[1] == 0)
+ alarmArray[1] = 1;
+ else if(f.VOLUME_MODE==0 && alarmArray[1] == 1)
+ alarmArray[1] = 0;
+ #endif
+
#if defined(BUZZER)
if ( rcOptions[BOXBEEPERON] )alarmArray[3] = 1;
else alarmArray[3] = 0;
Index: config.h
===================================================================
--- config.h (revision 18)
+++ config.h (working copy)
@@ -36,7 +36,7 @@
//#define BI
//#define TRI
//#define QUADP
- //#define QUADX
+ #define QUADX
//#define Y4
//#define Y6
//#define HEX6
@@ -109,7 +109,7 @@
//#define SIRIUS600 // Sirius Navigator IMU using the WMP for the gyro
//#define SIRIUS_AIR // Sirius Navigator IMU 6050 32U4 from MultiWiiCopter.com <- confirmed by Alex
//#define SIRIUS_AIR_GPS // Sirius Navigator IMU 6050 32U4 from MultiWiiCopter.com with GPS/MAG remote located
- //#define SIRIUS_MEGAv5_OSD // Paris_Sirius™ ITG3050,BMA280,MS5611,HMC5883,uBlox http://www.Multiwiicopter.com <- confirmed by Alex
+ //#define SIRIUS_MEGAv5_OSD // Paris_Sirius� ITG3050,BMA280,MS5611,HMC5883,uBlox http://www.Multiwiicopter.com <- confirmed by Alex
//#define MINIWII // Jussi's MiniWii Flight Controller <- confirmed by Alex
//#define MICROWII // MicroWii 10DOF with ATmega32u4, MPU6050, HMC5883L, MS561101BA from http://flyduino.net/
//#define CITRUSv2_1 // CITRUS from qcrc.ca
@@ -139,7 +139,7 @@
//#define Bobs_9DOF_V1 // BobsQuads 9DOF V1 with ITG3200, BMA180 & HMC5883L
//#define Bobs_10DOF_BMP_V1 // BobsQuads 10DOF V1 with ITG3200, BMA180, HMC5883L & BMP180 - BMP180 is software compatible with BMP085
//#define FLYDUINO_MPU // MPU6050 Break Out onboard 3.3V reg
- //#define CRIUS_AIO_PRO_V1
+ #define CRIUS_AIO_PRO_V1
//#define DESQUARED6DOFV2GO // DEsquared V2 with ITG3200 only
//#define DESQUARED6DOFV4 // DEsquared V4 with MPU6050
//#define LADYBIRD
@@ -502,7 +502,7 @@
//#define MPU6050_LPF_188HZ
//#define MPU6050_LPF_98HZ
//#define MPU6050_LPF_42HZ
- //#define MPU6050_LPF_20HZ
+ #define MPU6050_LPF_20HZ
//#define MPU6050_LPF_10HZ
//#define MPU6050_LPF_5HZ // Use this only in extreme cases, rather change motors and/or props

@@ -576,6 +576,20 @@
#define FAILSAFE_DETECT_TRESHOLD 985


+ /******** Volume flight settings ********************/
+ /* Volume flight can be used for limiting a flight in defined cylinder volume around the taking of landing.
+ Initially, this code was required for French multiwii user that must be compliant to French air rules.
+ The volume is limited with a defined heigth from the ground and a distance from the taking off point */
+ #define VOLUME_FLIGHT
+ #define VOLUME_HEIGTH_MAX 2
+ #define VOLUME_DISTANCE_MAX 10
+
+ /* The following defines are related to several types of bureaucratic authorizations from French air administration. */
+ //#define VOLUME_S1
+ //#define VOLUME_S2
+ //#define VOLUME_S3
+ //#define VOLUME_2KG
+
/***************** DFRobot LED RING *********************************/
/* I2C DFRobot LED RING communication */
//#define LED_RING
@@ -634,8 +648,8 @@
in NMEA mode the GPS must be configured to output GGA and RMC NMEA sentences (which is generally the default conf for most GPS devices)
at least 5Hz update rate. uncomment the first line to select the GPS serial port of the arduino */

- //#define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA
- //#define GPS_PROMINI_SERIAL // Will Autosense if GPS is connected when ardu boots.
+ #define GPS_SERIAL 2 // should be 2 for flyduino v2. It's the serial port number on arduino MEGA
+ //#define GPS_PROMINI_SERIAL // Will Autosense if GPS is connected when ardu boots.

// avoid using 115200 baud because with 16MHz arduino the 115200 baudrate have more than 2% speed error (57600 have 0.8% error)
#define GPS_BAUD 57600
@@ -648,7 +662,7 @@


//#define NMEA
- //#define UBLOX
+ #define UBLOX
//#define MTK_BINARY16
//#define MTK_BINARY19
//#define INIT_MTK_GPS // initialize MTK GPS for using selected speed, 5Hz update rate and GGA & RMC sentence or binary settings
@@ -794,7 +808,7 @@
/********************************************************************/
/**** Buzzer ****/
/********************************************************************/
- //#define BUZZER
+ #define BUZZER
//#define RCOPTIONSBEEP // uncomment this if you want the buzzer to beep at any rcOptions change on channel Aux1 to Aux4
//#define ARMEDTIMEWARNING 330 // (*) Trigger an alarm after a certain time of being armed [s] to save you lipo (if your TX does not have a countdown)
//#define PILOTLAMP //Uncomment if you are using a X-Arcraft Pilot Lamp
Index: def.h
===================================================================
--- def.h (revision 18)
+++ def.h (working copy)
@@ -2014,8 +2014,15 @@


/**************************************************************************************/
-/*************** override defaults ********************/
+/*************** volume flight pre-defined scenarios ********************/
/**************************************************************************************/
+#if defined(VOLUME_S1) || defined(VOLUME_S2) || defined(VOLUME_S3)
+ #define VOLUME_S1_DSTMAX 100
+ #define VOLUME_S2_DSTMAX 1000
+ #define VOLUME_S3_DSTMAX 100
+ #define VOLUME_HMAX_2KG 150
+ #define VOLUME_HMAX 50
+#endif

/*************** pin assignments ? ********************/
#ifdef OVERRIDE_V_BATPIN
Index: MultiWii.cpp
===================================================================
--- MultiWii.cpp (revision 18)
+++ MultiWii.cpp (working copy)
@@ -159,6 +159,10 @@
int16_t sonarAlt;
int16_t BaroPID = 0;
int16_t errorAltitudeI = 0;
+#if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+uint16_t VolumeAltitudeMax;
+uint16_t VolumeHeightMax;
+#endif

// **************
// gyro+acc IMU
@@ -303,6 +307,10 @@
int32_t GPS_home[2];
int32_t GPS_hold[2];
uint8_t GPS_numSat;
+#if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ uint16_t GPS_distanceToHomeMax;
+ int32_t BAROaltHome;
+#endif
uint16_t GPS_distanceToHome; // distance to home - unit: meter
int16_t GPS_directionToHome; // direction to home - unit: degree
uint16_t GPS_altitude; // GPS altitude - unit: meter
@@ -687,7 +695,40 @@
plog.armed_time = 0; // lifetime in seconds
//plog.running = 0; // toggle on arm & disarm to monitor for clean shutdown vs. powercut
#endif
-
+
+ #if defined(VOLUME_FLIGHT)
+ VolumeHeightMax = VOLUME_HEIGTH_MAX*100;
+ GPS_distanceToHomeMax = VOLUME_DISTANCE_MAX;
+ f.VOLUME_MODE = 0;
+ #endif
+ #ifdef VOLUME_S1
+ GPS_distanceToHomeMax = VOLUME_S1_DSTMAX;
+ #if defined(VOLUME_2KG)
+ VolumeHeightMax = VOLUME_HMAX_2KG*100;
+ #else
+ VolumeHeightMax = VOLUME_HMAX*100;
+ #endif
+ f.VOLUME_MODE = 0;
+ #endif
+ #ifdef VOLUME_S2
+ GPS_distanceToHomeMax = VOLUME_S2_DSTMAX;
+ #if defined(VOLUME_2KG)
+ VolumeHeightMax = VOLUME_HMAX_2KG*100;
+ #else
+ VolumeHeightMax = VOLUME_HMAX*100;
+ #endif
+ f.VOLUME_MODE = 0;
+ #endif
+ #ifdef VOLUME_S3
+ GPS_distanceToHomeMax = VOLUME_S3_DSTMAX;
+ #if defined(VOLUME_2KG)
+ VolumeHeightMax = VOLUME_HMAX_2KG*100;
+ #else
+ VolumeHeightMax = VOLUME_HMAX*100;
+ #endif
+ f.VOLUME_MODE = 0;
+ #endif
+
debugmsg_append_str("initialization completed\n");
}

@@ -724,6 +765,11 @@
// write now.
writePLog();
#endif
+ BAROaltHome = alt.EstAlt;
+ #if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ VolumeAltitudeMax = BAROaltHome + VolumeHeightMax;
+ f.VOLUME_MODE = 0;
+ #endif
}
} else if(!f.ARMED) {
blinkLED(2,255,1);
@@ -730,6 +776,7 @@
alarmArray[8] = 1;
}
}
+
void go_disarm() {
if (f.ARMED) {
f.ARMED = 0;
@@ -741,6 +788,12 @@
plog.running = 0; // toggle @ arm & disarm to monitor for clean shutdown vs. powercut
// write now.
writePLog();
+ #endif
+
+ #if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ BAROaltHome = alt.EstAlt;
+ VolumeAltitudeMax = BAROaltHome + VolumeHeightMax;
+ f.VOLUME_MODE = 0;
#endif
}
}
@@ -1072,6 +1125,24 @@
}
}
}
+
+ #if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ debug[0] = alt.EstAlt;
+ debug[1] = VolumeAltitudeMax;
+ debug[2] = GPS_distanceToHome;
+ debug[3] = GPS_distanceToHomeMax;
+
+ if(f.ARMED && ((alt.EstAlt > VolumeAltitudeMax) || (GPS_distanceToHome > GPS_distanceToHomeMax)))
+ {
+ f.VOLUME_MODE = 1;
+ }
+ else if(f.VOLUME_MODE==1)
+ {
+ if((VolumeAltitudeMax-50 > alt.EstAlt) && (GPS_distanceToHomeMax-2 > GPS_distanceToHome))
+ f.VOLUME_MODE = 0;
+ }
+ #endif
+
} else {
f.GPS_HOME_MODE = 0;
f.GPS_HOLD_MODE = 0;
@@ -1114,7 +1185,8 @@
case 4:
taskOrder++;
#if SONAR
- Sonar_update(); //debug[2] = sonarAlt;
+ Sonar_update();
+ //debug[2] = sonarAlt;
#endif
#ifdef LANDING_LIGHTS_DDR
auto_switch_landing_lights();
Index: MultiWii.h
===================================================================
--- MultiWii.h (revision 18)
+++ MultiWii.h (working copy)
@@ -43,6 +43,10 @@
extern int16_t sonarAlt;
extern int16_t BaroPID;
extern int16_t errorAltitudeI;
+#if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+extern uint16_t VolumeAltitudeMax;
+extern uint16_t VolumeHeightMax;
+#endif

extern int16_t i2c_errors_count;
extern uint8_t alarmArray[16];
@@ -125,6 +129,10 @@
extern int32_t GPS_home[2];
extern int32_t GPS_hold[2];
extern uint8_t GPS_numSat;
+#if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ extern uint16_t GPS_distanceToHomeMax;
+ extern int32_t BAROaltHome;
+#endif
extern uint16_t GPS_distanceToHome; // distance to home - unit: meter
extern int16_t GPS_directionToHome; // direction to home - unit: degree
extern uint16_t GPS_altitude; // GPS altitude - unit: meter
Index: types.h
===================================================================
--- types.h (revision 18)
+++ types.h (working copy)
@@ -126,6 +126,9 @@
uint8_t SMALL_ANGLES_25 :1 ;
uint8_t CALIBRATE_MAG :1 ;
uint8_t VARIO_MODE :1;
+#if defined(VOLUME_FLIGHT)||defined(VOLUME_S1)||defined(VOLUME_S2)||defined(VOLUME_S3)
+ uint8_t VOLUME_MODE :1;
+#endif
} flags_struct_t;

typedef struct {
-------------------------------------- CUT HERE ------------------------------------------------
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby hinkel » Thu Dec 05, 2013 7:02 pm

waderic wrote:Hi,

Here is my code for enabling an alarm when the copter is getting out a volume. I am using a CRIUS all-in-one pro v2.


Hi !
What is exactly the volumes you refer ? ( 100m or 1000m distance and 50m or 100m height ? )
Can you clearly hear the buzzer at 1000m distance ?
In future what is the goal if the copter is getting out a volume :
*Alarm via OSD
* GPS PH at the border of volume or RTH + Autolanding
* or other possibility ....

Salutations
hinkel
hinkel
 
Posts: 109
Joined: Sun Sep 09, 2012 7:24 am

Re: Flying in a volume

Postby waderic » Fri Dec 06, 2013 11:45 am

Hi Hinkel,

As you pointed out there are several possibility. The first goal is to provide an alarm for short distances (30 m) in order to inform the pilot he is out of the cylinder. The volume is a 30 m distance and a 50m height for example. The best alarm would be by OSD. For long distance, a RTH would be preferred.I am working also on improving failsafe.

Regards.

Waderic
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby EOSBandi » Tue Dec 10, 2013 9:50 pm

waderic wrote:Hi Hinkel,

As you pointed out there are several possibility. The first goal is to provide an alarm for short distances (30 m) in order to inform the pilot he is out of the cylinder. The volume is a 30 m distance and a 50m height for example. The best alarm would be by OSD. For long distance, a RTH would be preferred.I am working also on improving failsafe.

Regards.

Waderic


It is no more than 5 lines of code (assuming that you have active gps code)
User avatar
EOSBandi
 
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary

Re: Flying in a volume

Postby waderic » Sat Dec 21, 2013 3:37 pm

EOSBandi wrote:It is no more than 5 lines of code (assuming that you have active gps code)


I think code must be something like :

Code: Select all
if(f.ARMED && ((alt.EstAlt > VolumeAltitudeMax) || (GPS_distanceToHome > GPS_distanceToHomeMax)))
{
    f.VOLUME_MODE = 1;
    GPS_set_next_wp(&GPS_home[LAT],&GPS_home[LON]);
    nav_mode    = NAV_MODE_WP;
}
else if(f.VOLUME_MODE==1)
{
    if((VolumeAltitudeMax-50 > alt.EstAlt) && (GPS_distanceToHomeMax-2 > GPS_distanceToHome))
    {
       f.VOLUME_MODE = 0;         
       if (GPSNavReset == 0 ) {
           GPSNavReset = 1;
           GPS_reset_nav();
       }
    }
}
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby waderic » Mon Jan 06, 2014 10:54 am

EOSBandi wrote:It is no more than 5 lines of code (assuming that you have active gps code)


Two lines are enough ;)

Code: Select all
        if(f.VOLUME_MODE)
          rcOptions[BOXGPSHOME] = 1;


I will post all my code soon because it worked : RTH when going outside the volume.
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby waderic » Tue Jan 07, 2014 5:17 pm

Hi,

My code is available on github at https://github.com/Wadudu/MultiWii_Wad/tree/master/src

Regards
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby EOSBandi » Wed Jan 08, 2014 10:40 am

waderic wrote:Hi,

My code is available on github at https://github.com/Wadudu/MultiWii_Wad/tree/master/src

Regards

Your code is ok with vanilia MultiWii 2.3.
In the nav version I would rather change NAV_mode instead of box....
User avatar
EOSBandi
 
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary

Re: Flying in a volume

Postby EOSBandi » Wed Jan 08, 2014 10:45 am

I would define two limits for distance.
First limit is defined as the distance from home, where copter will switch to RTH. A second limit is defined as first limit+50 meters. If copter reaches this limit, it will initiate autoland.
User avatar
EOSBandi
 
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary

Re: Flying in a volume

Postby waderic » Mon Jan 13, 2014 6:39 pm

The first limit is working. I don't see why there should be second one. If the copter reaches the second one, it means the first limit did not work.
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby waderic » Mon Jan 13, 2014 6:45 pm

EOSBandi wrote:In the nav version I would rather change NAV_mode instead of box....

I don't see what you mean about. You are talking about these lines of code ?
Code: Select all
        if(f.VOLUME_MODE)
          rcOptions[BOXGPSHOME] = 1;
waderic
 
Posts: 14
Joined: Thu Aug 08, 2013 9:07 am
Location: France

Re: Flying in a volume

Postby Gartenflieger » Tue Jan 14, 2014 8:34 pm

waderic wrote:If the copter reaches the second one, it means the first limit did not work.


Wrong, it means RTH has failed and you have a rogue copter. That is probably what the limit is supposed to avoid. So I'd say a second limit makes perfect sense.
User avatar
Gartenflieger
 
Posts: 65
Joined: Sat Oct 01, 2011 10:07 pm
Location: Dortmund, Germany


Return to Software development

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron