Skip to content
Snippets Groups Projects
Verified Commit f50ff25c authored by Thomas Lambert's avatar Thomas Lambert :helicopter:
Browse files

fix(logg): current calibration

parent f77c2948
No related branches found
No related tags found
No related merge requests found
...@@ -45,10 +45,10 @@ ...@@ -45,10 +45,10 @@
#define DIV_RES1 47800.0 // Resistance of R1 in the voltage dividers #define DIV_RES1 47800.0 // Resistance of R1 in the voltage dividers
#define DIV_RES2 6800.0 // Resistance of R2 in the voltage dividers #define DIV_RES2 6800.0 // Resistance of R2 in the voltage dividers
#define SEN0098_VCC 5 // Supply voltage of the current sensors #define SEN0098_VCC 5 // Supply voltage of the current sensors
#define SEN0098_SENSI 40.0 // Chip ACS758LCB-050B-PFF-T #define SEN0098_SENSI 40.0 // Chip ACS758LCB-050B-PFF-T
#define SEN0098_VIOUT 0.12 // [FIXME] VERIFY! #define SEN0098_QUIESCENT_FACTOR 0.5 // Bidirectional chip-> V_IOUTQ = 0.5*VCC
#define SEN0098_OFFSET 0.007 // [FIXME] VERIFY! #define SEN0098_OFFSET 0.007 // [FIXME] VERIFY!
#define GEAR_RATIO 0.1 // Gear ratio between motor and wings #define GEAR_RATIO 0.1 // Gear ratio between motor and wings
...@@ -75,10 +75,11 @@ const uint16_t gMIN_RPM = 750; // Motor minimum RPM (set in ESC) ...@@ -75,10 +75,11 @@ const uint16_t gMIN_RPM = 750; // Motor minimum RPM (set in ESC)
const uint8_t gMAX_ESC_VAL = 160; // Value at which motor is at max RPM const uint8_t gMAX_ESC_VAL = 160; // Value at which motor is at max RPM
const uint8_t gMIN_ESC_VAL = 40; // Min value for ESC to start motor (trial-error) const uint8_t gMIN_ESC_VAL = 40; // Min value for ESC to start motor (trial-error)
const uint8_t gCSN_PINS[] = CSN_PINS; // Encoder Chip Select pins const uint8_t gCSN_PINS[] = CSN_PINS; // Encoder Chip Select pins
const int8_t gENC_ORIENT[] = ENC_ORIENT; // Encoder orientation const int8_t gENC_ORIENT[] = ENC_ORIENT; // Encoder orientation
const float gCUR_FACT = SEN0098_SENSI / 1000.0; // Factor for current measurement
const float gCUR_QOV = SEN0098_VIOUT * SEN0098_VCC; // [FIXME] Verify const float gCUR_FACT = SEN0098_SENSI / 1000.0; // Factor for current measurement
const float gCUR_QOV = SEN0098_QUIESCENT_FACTOR * SEN0098_VCC; // VIOUT_Q
// Other // Other
Servo gEsc1; // ESC for front motor Servo gEsc1; // ESC for front motor
...@@ -136,8 +137,9 @@ void setup() { ...@@ -136,8 +137,9 @@ void setup() {
Calibrate(); Calibrate();
} }
delay(1000);
Serial.println("[INFO]: Setup OK, starting now..."); Serial.println("[INFO]: Setup OK, starting now...");
delay(1000); // Ensure all is properly initialized delay(500);
} }
...@@ -265,9 +267,9 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[ ...@@ -265,9 +267,9 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[
Serial.print(freq); Serial.print(freq);
for (int i = 0; i < sizeof(gCSN_PINS); i++) { for (int i = 0; i < sizeof(gCSN_PINS); i++) {
Serial.print(","); Serial.print(",");
Serial.print(PosToDeg(wing_angles[i]) - gMaxWingPos[i] + TRUE_MAX_ANGLE); Serial.print(PosToDeg((wing_angles[i] - gMaxWingPos[i]) % ENC_PRECISION) + TRUE_MAX_ANGLE - 360);
} }
for (int i = 0; i < sizeof(psu_vol) / sizeof(psu_vol[0]); i++) { for (int i = 0; i < 2; i++) {
Serial.print(","); Serial.print(",");
Serial.print(psu_vol[i]); Serial.print(psu_vol[i]);
Serial.print(","); Serial.print(",");
......
...@@ -28,7 +28,7 @@ unsigned int ReadSensor(uint8_t csn, int8_t orient, int8_t offset) { ...@@ -28,7 +28,7 @@ unsigned int ReadSensor(uint8_t csn, int8_t orient, int8_t offset) {
} }
digitalWrite(csn, HIGH); //deselects the encoder from reading digitalWrite(csn, HIGH); //deselects the encoder from reading
return (1 - orient) / 2 * ENC_PRECISION + orient * ret - offset * ENC_PRECISION / 2; return (1 - orient) / 2 * ENC_PRECISION + orient * ret - (offset * ENC_PRECISION / 2);
} }
// Get the tension and current of a PSU // Get the tension and current of a PSU
...@@ -38,8 +38,7 @@ void GetPsu(byte vol_pin, byte cur_pin, float &vol, float &cur) { ...@@ -38,8 +38,7 @@ void GetPsu(byte vol_pin, byte cur_pin, float &vol, float &cur) {
} }
// Measure current consumed by module // Measure current consumed by module
// https://www.youtube.com/watch?v=SiHfjzcqnU4 // From https://www.youtube.com/watch?v=SiHfjzcqnU4
// [FIXME] Check properly
float GetCurrent(byte cur_pin) { float GetCurrent(byte cur_pin) {
float volt_raw = (5.0 / 1023.0) * analogRead(cur_pin); float volt_raw = (5.0 / 1023.0) * analogRead(cur_pin);
......
...@@ -37,10 +37,11 @@ float PosToDeg(unsigned int pos) { ...@@ -37,10 +37,11 @@ float PosToDeg(unsigned int pos) {
} }
void PrintArray(int array[]) { void PrintArray(int array[]) {
for (int i = 0; i < sizeof(array) / sizeof(array[0]); i++) { for (int i = 0; i < 4; i++) {
Serial.print(array[i]); Serial.print(array[i]);
if (i < sizeof(array) - 1) { if (i < 4 - 1) {
Serial.print(", "); Serial.print(", ");
} }
} }
Serial.println();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment