Browse Source

Fixed Jitter issue on Software method. Using Polynomial Way and Median. Also on hardware side had put the power line for the RF module direct to the battery input rather through the 3.3V DC-DC converter.

master
Englebert 6 years ago
parent
commit
f569662509
  1. 1
      OpenFlightTX.h
  2. 113
      OpenFlightTX.ino

1
OpenFlightTX.h

@ -43,6 +43,7 @@ byte getRegister(byte r);
void SignalHandler(void *pvParameters); void SignalHandler(void *pvParameters);
void setup_nrf_tx(void); void setup_nrf_tx(void);
void rx_binding(void); void rx_binding(void);
uint16_t read_voltage(byte pin);
void setup_rxsync_server(void); void setup_rxsync_server(void);
void setup_nrf_sync(void); void setup_nrf_sync(void);
void restore_radio(void); void restore_radio(void);

113
OpenFlightTX.ino

@ -42,6 +42,9 @@
#define MAX_CHANNELS 125 #define MAX_CHANNELS 125
#define MAX_SAMPLES 30 #define MAX_SAMPLES 30
// For RC Deadband
#define RC_DEADBAND 5
int channel_loads[MAX_CHANNELS]; // Channel 0 ~ Channel 124 int channel_loads[MAX_CHANNELS]; // Channel 0 ~ Channel 124
uint64_t pipeIn = 0xE8E8F0F0E1LL; // TODO: set it to EEPROM uint64_t pipeIn = 0xE8E8F0F0E1LL; // TODO: set it to EEPROM
RF24 radio(NRF24_CE, NRF24_CSN); // Starting up the module on GPIO5 (CE), GPIO4 (CSN) RF24 radio(NRF24_CE, NRF24_CSN); // Starting up the module on GPIO5 (CE), GPIO4 (CSN)
@ -382,7 +385,7 @@ input[type=button] {
/*** Index Page ***/ /*** Index Page ***/
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.0.10</strong>
const char* index_html PROGMEM = R"rawliteral(<pre><strong>OpenFlightTX v1.2</strong>
)rawliteral"; )rawliteral";
// WebPages ----- END // WebPages ----- END
@ -582,12 +585,12 @@ uint8_t towards(struct menu_state *current, struct menu_state *destination) {
} }
// For Menu Navigation and Setup // For Menu Navigation and Setup
#define MENU_STICK_ROLL_MAX 3000
#define MENU_STICK_ROLL_MAX 2800
#define MENU_STICK_ROLL_MIN 800 #define MENU_STICK_ROLL_MIN 800
#define MENU_STICK_PITCH_MAX 3000
#define MENU_STICK_PITCH_MAX 2700
#define MENU_STICK_PITCH_MIN 800 #define MENU_STICK_PITCH_MIN 800
#define MENU_STICK_YAW_MAX 3000
#define MENU_STICK_YAW_MIN 800
#define MENU_STICK_YAW_MAX 2500
#define MENU_STICK_YAW_MIN 500
typedef enum { typedef enum {
MENU_NONE = 0, MENU_NONE = 0,
@ -646,6 +649,7 @@ uint16_t throttle_value = 0;
uint16_t yaw_value = 0; uint16_t yaw_value = 0;
uint16_t pitch_value = 0; uint16_t pitch_value = 0;
uint16_t roll_value = 0; uint16_t roll_value = 0;
uint64_t vbat_value = 0;
/* /*
uint16_t tx_throttle = 0; uint16_t tx_throttle = 0;
uint16_t tx_yaw = 0; uint16_t tx_yaw = 0;
@ -666,8 +670,6 @@ uint16_t roll_min = 4096;
uint8_t freq_channel = 0; uint8_t freq_channel = 0;
uint8_t freq_txpower = 0; // 0: LOW, 1: MIN, 2: HIGH, 3: MAX uint8_t freq_txpower = 0; // 0: LOW, 1: MIN, 2: HIGH, 3: MAX
uint64_t vbat_value = 0;
bool sw1 = 0; bool sw1 = 0;
bool sw2 = 0; bool sw2 = 0;
bool sw3 = 0; bool sw3 = 0;
@ -822,7 +824,70 @@ uint16_t median_get(uint8_t median_type) {
} }
// Return the result // Return the result
return median_tmp[MEDIAN_POS];
// return median_tmp[MEDIAN_POS];
// Using RC dead band way....**** NEED TO IMPROvE!!
if(median_type == THROTTLE) {
if(throttle_value > median_tmp[MEDIAN_POS]) {
if(throttle_value - median_tmp[MEDIAN_POS] > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
if(median_tmp[MEDIAN_POS] - throttle_value > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
return throttle_value;
}
}
}
} else if(median_type == YAW) {
if(yaw_value > median_tmp[MEDIAN_POS]) {
if(yaw_value - median_tmp[MEDIAN_POS] > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
if(median_tmp[MEDIAN_POS] - yaw_value > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
return yaw_value;
}
}
}
} else if(median_type == PITCH) {
if(pitch_value > median_tmp[MEDIAN_POS]) {
if(pitch_value - median_tmp[MEDIAN_POS] > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
if(median_tmp[MEDIAN_POS] - pitch_value > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
return pitch_value;
}
}
}
} else if(median_type == ROLL) {
if(roll_value > median_tmp[MEDIAN_POS]) {
if(roll_value - median_tmp[MEDIAN_POS] > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
if(median_tmp[MEDIAN_POS] - roll_value > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
return roll_value;
}
}
}
} else if(median_type == VBAT) {
if(vbat_value > median_tmp[MEDIAN_POS]) {
if(vbat_value - median_tmp[MEDIAN_POS] > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
if(median_tmp[MEDIAN_POS] - vbat_value > RC_DEADBAND) {
return median_tmp[MEDIAN_POS];
} else {
return vbat_value;
}
}
}
}
} }
uint16_t throttle_insert(uint16_t val) { uint16_t throttle_insert(uint16_t val) {
@ -930,16 +995,27 @@ int readYaw() {
return samples / 10; return samples / 10;
} }
uint16_t read_voltage(byte pin) {
uint16_t reading = analogRead(pin);
if(reading < 1 || reading > 4095) return 0;
// float volt = -0.0000000016 * pow(reading,4) + 0.000000118171 * pow(reading,3)- 0.000301211691 * pow(reading,2)+ 1.109019271794 * reading + 34.143524634089;
// return volt;
// return reading;
//return -0.000000000009824 * pow(reading,3) + 0.000000016557283 * pow(reading,2) + 0.000854596860691 * reading + 0.065440348345433;
return -0.000000000016 * pow(reading,4) + 0.000000118171 * pow(reading,3)- 0.000301211691 * pow(reading,2)+ 1.109019271794 * reading + 34.143524634089;
}
void read_all_voltage() { void read_all_voltage() {
throttle_raw = analogRead(THROTTLE_PIN);
yaw_raw = analogRead(YAW_PIN);
throttle_raw = read_voltage(THROTTLE_PIN);
yaw_raw = read_voltage(YAW_PIN);
// yaw_raw = readYaw(); // yaw_raw = readYaw();
pitch_raw = analogRead(PITCH_PIN);
pitch_raw = read_voltage(PITCH_PIN);
// roll_raw = analogRead(ROLL_PIN); // roll_raw = analogRead(ROLL_PIN);
// Hardcode to increase the value a bit... // Hardcode to increase the value a bit...
roll_raw = analogRead(ROLL_PIN) + 150;
roll_raw = read_voltage(ROLL_PIN) + 150;
vbat_raw = read_voltage(VBAT_PIN);
vbat_raw = analogRead(VBAT_PIN);
// Serial.print("T:");Serial.print(throttle_raw);Serial.print(" Y:");Serial.print(yaw_raw);Serial.print(" P:");Serial.print(pitch_raw);Serial.print("R:");Serial.println(roll_raw);
sw1 = !digitalRead(SW1_PIN); sw1 = !digitalRead(SW1_PIN);
sw2 = !digitalRead(SW2_PIN); sw2 = !digitalRead(SW2_PIN);
@ -1006,7 +1082,8 @@ void battery_management() {
// strcpy(buf, ltoa(vbat_value, buf, 10)); // strcpy(buf, ltoa(vbat_value, buf, 10));
// u8g2_left.drawStr(0, 30, buf); // u8g2_left.drawStr(0, 30, buf);
float vbat_real_value = vbat_value * .0012142857;
// float vbat_real_value = vbat_value * .0012142857;
float vbat_real_value = vbat_value * .0012144857;
//strcpy(buf, ltoa(vbat_real_value, buf, 10)); //strcpy(buf, ltoa(vbat_real_value, buf, 10));
dtostrf(vbat_real_value, 2, 1, buf); dtostrf(vbat_real_value, 2, 1, buf);
@ -1042,6 +1119,9 @@ void setup() {
pinMode(SW5_PIN, INPUT_PULLUP); pinMode(SW5_PIN, INPUT_PULLUP);
pinMode(SW6_PIN, INPUT_PULLUP); pinMode(SW6_PIN, INPUT_PULLUP);
// For more precise analog readings
// analogSetCycles(128);
// Display Setup // Display Setup
// u8g2_SetI2CAddress(u8g2_right.getU8g2(), 0x3d*2); // u8g2_SetI2CAddress(u8g2_right.getU8g2(), 0x3d*2);
u8g2_left.begin(); u8g2_left.begin();
@ -1379,7 +1459,7 @@ void update_display(void) {
// u8g2_left.setFont(u8g2_font_micro_tr); // u8g2_left.setFont(u8g2_font_micro_tr);
u8g2_left.setFont(u8g2_font_5x7_tf); u8g2_left.setFont(u8g2_font_5x7_tf);
u8g2_left.setCursor(0,62); u8g2_left.setCursor(0,62);
u8g2_left.print(F("OpenFlightTX - 1.0.10"));
u8g2_left.print(F("OpenFlightTX - 1.2"));
// Battery // Battery
show_battery_level(115, 56); show_battery_level(115, 56);
@ -2656,7 +2736,8 @@ void show_battery_level(uint8_t x, uint8_t y) {
u8g2_left.drawLine(x+12, y+2, x+12, y+5); u8g2_left.drawLine(x+12, y+2, x+12, y+5);
// Battery level indicator // Battery level indicator
int vbat_bar_value = ((vbat_value * .0012142857) - 3.2) * 8;
// int vbat_bar_value = ((vbat_value * .0012142857) - 3.2) * 8;
int vbat_bar_value = ((vbat_value * .0012144857) - 3.2) * 8;
// int vbat_bar_value = vbat_value * 10 / 4096; // int vbat_bar_value = vbat_value * 10 / 4096;
uint8_t x1 = 0; uint8_t x1 = 0;
for(int i = 0; i < vbat_bar_value; i++) { for(int i = 0; i < vbat_bar_value; i++) {

Loading…
Cancel
Save