Browse Source

Able to arm and disarm. Fixed the fail safe counts and added a few web commands

master
Englebert 3 years ago
parent
commit
c665d8e3b1
  1. 15
      src/config.h
  2. 92
      src/main.cpp
  3. 3
      src/main.h
  4. 48
      src/web.cpp

15
src/config.h

@ -4,6 +4,19 @@
*/
#define QUADX
// Enabling multiple configuration profiles
#define MULTIPLE_CONFIGURATION_PROFILES
// Uncomment this to debug at serial
#define DEBUG_MODE
// ARM / DISARM
/* optionally disable stick combinations to arm/disarm the motors.
* In most cases one of the two options to arm/disarm via TX stick is sufficient
*/
#define ALLOW_ARM_DISARM_VIA_TX_YAW
// #define ALLOW_ARM_DISARM_VIA_TX_ROLL
/*
* Motor minthrottle
* Set the minimum throttle command sent to the ESC (Electronic Speed Controller)
@ -49,7 +62,7 @@
for best results. This value is depended from your configuration, AUW and some other params. Next, after FAILSAFE_OFF_DELAY the copter is disarmed,
and motors is stopped. If RC pulse coming back before reached FAILSAFE_OFF_DELAY time, after the small quard time the RC control is returned to normal. */
#define FAILSAFE // uncomment to activate the failsafe function
#define FAILSAFE_DELAY 2 // Guard time for failsafe activation after signal lost. 1 step = 0.1sec - 1sec in example
#define FAILSAFE_DELAY 20 // Guard time for failsafe activation after signal lost. 1 step = 0.1sec - 1sec in example
#define FAILSAFE_OFF_DELAY 200 // Time for Landing before motors stop in 0.1sec. 1 step = 0.1sec - 20sec in example
#define FAILSAFE_THROTTLE (MINTHROTTLE + 200) // (*) Throttle level used for landing - may be relative to MINTHROTTLE - as in this case

92
src/main.cpp

@ -37,6 +37,10 @@ int16_t gyroADCprevious[3] = {0,0,0};
int16_t gyroADCinter[3];
uint32_t timeInterleave = 0;
#ifdef DEBUG_MODE
char debug_str[512];
#endif
flags_struct_t flags;
// Common variables
@ -604,7 +608,7 @@ void taskMeasurements(void *pvParameters) {
// sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Cycle: %d Bat: %.2fv Temp: %.2fC Alt: %dcm T: %d Y: %d P: %d R: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, cycleTime, battery.volt, baro.temperature, baro.altitude, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL]);
sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Cycle: %d Bat: %.2fv Temp: %.2fC Alt: %dcm T: %d Y: %d P: %d R: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, cycleTime, battery.volt, baro.temperature, alt.EstAlt, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL]);
#else
sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Motor: %d Cycle: %d RC: %d Bat: %.2fv T: %d Y: %d P: %d R: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, motors.counts, cycleTime, rc_counts, battery.volt, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL]);
sprintf(buffer_gyro, "Gyro: %d %d %d %d %d %d Motor: %d Cycle: %d RC: %d Bat: %.2fv T: %d Y: %d P: %d R: %d FS: %d", AcX, AcY, AcZ, GyX, GyY, GyZ, motors.counts, cycleTime, rc_counts, battery.volt, rcData[THROTTLE], rcData[YAW], rcData[PITCH], rcData[ROLL], failsafeCnt);
#endif
// Reset counter
@ -1060,9 +1064,7 @@ bool process_rc(void) {
#endif
} else {
#if defined(FAILSAFE)
if(rc_counts == 0) {
failsafeCnt++;
}
failsafeCnt++;
#endif
}
// rx.stopListening();
@ -1906,18 +1908,33 @@ void process_data(void) {
if(rcDelayCommand == 20) {
if(flags.ARMED) { // actions during armed
#ifdef ALLOW_ARM_DISARM_VIA_TX_YAW
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_CE)
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_CE) {
#ifdef DEBUG_MODE
sprintf(debug_str, "DISARM VIA TX YAW");
Serial.println(debug_str);
#endif
go_disarm(); // Disarm via YAW
}
#endif
#ifdef ALLOW_ARM_DISARM_VIA_TX_ROLL
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_LO)
if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_LO) {
#ifdef DEBUG_MODE
sprintf(debug_str, "DISARM VIA TX ROLL");
Serial.println(debug_str);
#endif
go_disarm(); // Disarm via ROLL
}
#endif
} else { // actions during not armed
} else { // actions during not armed
i=0;
if(rcSticks == THR_LO + YAW_LO + PIT_LO + ROL_CE) { // GYRO calibration
calibratingG = 512;
#ifdef DEBUG_MODE
sprintf(debug_str, "GYRO CLIBRATING");
Serial.println(debug_str);
#endif
// TODO: Focus on basic function before proceed to GPS
#if GPS
//// GPS_reset_home_position();
@ -1929,9 +1946,20 @@ void process_data(void) {
#if defined(INFLIGHT_ACC_CALIBRATION)
else if(rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_HI) { // Inflight ACC calibration START/STOP
if(AccInflightCalibrationMeasurementDone) { // trigger saving into eeprom after landing
#ifdef DEBUG_MODE
sprintf(debug_str, "INFLIGHT ACC CALIBRATION DONE");
Serial.println(debug_str);
#endif
AccInflightCalibrationMeasurementDone = 0;
AccInflightCalibrationSavetoEEProm = 1;
} else {
#ifdef DEBUG_MODE
sprintf(debug_str, "INFLIGHT ACC CALIBRATION BEGIN");
Serial.println(debug_str);
#endif
AccInflightCalibrationArmed = !AccInflightCalibrationArmed;
#if defined(BUZZER)
if(AccInflightCalibrationArmed)
@ -1943,13 +1971,17 @@ void process_data(void) {
}
#endif
#ifdef MULTIPLE_CONFIGURATION_PROFILES
if(rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_LO)
if(rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_LO)
i = 1; // ROLL left -> Profile 1
else if(rcSticks == THR_LO + YAW_LO + PIT_HI + ROL_CE)
i = 2; // PITCH up -> Profile 2
else if(rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_HI)
i = 3; // ROLL right -> Profile 3
if(i){
if(i) {
#ifdef DEBUG_MODE
sprintf(debug_str, "Profile: %d", i);
Serial.println(debug_str);
#endif
global_conf.currentSet = i-1;
writeGlobalSet(0);
// readEEPROM();
@ -1961,16 +1993,26 @@ void process_data(void) {
if(rcSticks == THR_LO + YAW_HI + PIT_HI + ROL_CE) { // Enter LCD config
#if defined(LCD_CONF)
configurationLoop(); // beginning LCD configuration
#endif
previousTime = micros();
#endif
}
#ifdef ALLOW_ARM_DISARM_VIA_TX_YAW
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE)
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE) {
#ifdef DEBUG_MODE
sprintf(debug_str, "ARM VIA TX YAW");
Serial.println(debug_str);
#endif
go_arm(); // Arm via YAW
}
#endif
#ifdef ALLOW_ARM_DISARM_VIA_TX_ROLL
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_HI)
else if(conf.activate[BOXARM] == 0 && rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_HI) {
#ifdef DEBUG_MODE
sprintf(debug_str, "ARM VIA TX ROLL");
Serial.println(debug_str);
#endif
go_arm(); // Arm via ROLL
}
#endif
#ifdef LCD_TELEMETRY_AUTO
else if(rcSticks == THR_LO + YAW_CE + PIT_HI + ROL_LO) { // Auto telemetry ON/OFF
@ -1996,12 +2038,24 @@ void process_data(void) {
}
#endif
#if USE_ACC
else if(rcSticks == THR_HI + YAW_LO + PIT_LO + ROL_CE)
else if(rcSticks == THR_HI + YAW_LO + PIT_LO + ROL_CE) {
#ifdef DEBUG_MODE
sprintf(debug_str, "ACC CALIBRATION");
Serial.println(debug_str);
#endif
calibratingA = 512; // throttle=max, yaw=left, pitch=min
}
#endif
#if USE_MAG
else if(rcSticks == THR_HI + YAW_HI + PIT_LO + ROL_CE)
else if(rcSticks == THR_HI + YAW_HI + PIT_LO + ROL_CE) {
#ifdef DEBUG_MODE
sprintf(debug_str, "MAG CALIBRATION");
Serial.println(debug_str);
#endif
flags.CALIBRATE_MAG = 1; // throttle=max, yaw=right, pitch=min
}
#endif
i = 0;
if(rcSticks == THR_HI + YAW_CE + PIT_HI + ROL_CE) {
@ -2287,6 +2341,10 @@ void process_data(void) {
void go_disarm(void) {
if(flags.ARMED) {
flags.ARMED = 0;
#ifdef DEBUG_MODE
sprintf(debug_str, "DISARMED");
Serial.println(debug_str);
#endif
#ifdef LOG_PERMANENT
plog.disarm++; // #disarm events
plog.armed_time = armedTime ; // lifetime in seconds
@ -2309,7 +2367,7 @@ void go_arm(void) {
&& flags.ACC_CALIBRATED
#endif
#if defined(FAILSAFE)
&& failsafeCnt < 2
&& failsafeCnt < 50
#endif
#if GPS && defined(ONLY_ALLOW_ARM_WITH_GPS_3DFIX)
&& (flags.GPS_FIX && GPS_numSat >= 5)
@ -2317,6 +2375,10 @@ void go_arm(void) {
) {
if(!flags.ARMED && !flags.BARO_MODE) { // arm now!
flags.ARMED = 1;
#ifdef DEBUG_MODE
sprintf(debug_str, "ARMED");
Serial.println(debug_str);
#endif
#if defined(HEADFREE)
headFreeModeHold = att.heading;
#endif // defined(HEADFREE)

3
src/main.h

@ -513,7 +513,8 @@ void taskBaro(void *pvParameters);
extern bool load_defaults; // Default false. Only during reset this will auto set to true
extern flags_struct_t flags;
extern uint16_t rcCommand[RC_CHANS];
extern uint16_t rcData[RC_CHANS]; // Signal from nRF24L01+
extern uint16_t rcData[RC_CHANS]; // Signal from nRF24L01+
extern uint8_t rcOptions[CHECKBOXITEMS]; // Auxilariy options settings
extern int16_t motor[8];
extern int16_t axisPID[3];
extern conf_t conf;

48
src/web.cpp

@ -254,7 +254,6 @@ void WEB::begin(void) {
String(flags.LAND_COMPLETED) + "," +
String(flags.LAND_IN_PROGRESS) + "," +
#endif
"OK";
@ -262,7 +261,52 @@ void WEB::begin(void) {
server.send(200, "text/plain", feeds);
});
// getpid
// setopts
// - Setting the options for the options
// getopts
server.on("/getopts", HTTP_GET, []() {
String opts_val = "";
opts_val =
String(rcOptions[BOXARM]) + "," +
#if USE_ACC
String(rcOptions[BOXANGLE]) + "," +
String(rcOptions[BOXHORIZON]) + "," +
#endif
#if USE_BARO && (!defined(SURPRESS_BARO_ALTHOLD))
String(rcOptions[BOXBARO]) + "," +
#endif
#ifdef VARIOMETER
String(rcOptions[BOXVARIO]) + "," +
#endif
#if defined(HEADFREE)
String(rcOptions[BOXHEADFREE]) + "," +
String(rcOptions[BOXHEADADJ]) + "," +
#endif
#if GPGS
String(rcOptions[BOXGPSHOME]) + "," +
String(rcOptions[BOXGPSHOLD]) + "," +
#endif
#ifdef GOVERNOR_P
String(rcOptions[GOVERNOR_P]) + "," +
#endif
#ifdef OSD_SWITCH
String(rcOptions[OSD_SWITCH]) + "," +
#endif
#if GPS
String(rcOptions[BOXGPSNAV]) + "," +
String(rcOptions[BOXLAND]) + "," +
#endif
"OK";
server.sendHeader("Connections", "close");
server.send(200, "text/plain", opts_val);
});
// getpids
server.on("/getpids", HTTP_GET, []() {
String pids_val = "";
pids_val =

Loading…
Cancel
Save