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

refact: reorder stuff, better names

parent d643cd9d
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,8 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller ...@@ -32,7 +32,8 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
#define CLK_PIN 2 // Encoder CLK #define CLK_PIN 2 // Encoder CLK
#define DO_PIN 8 // Encoder Digital Output #define DO_PIN 8 // Encoder Digital Output
#define CSN_PINS { 3, 4, 5, 6 } // Encoder Chip Select pins #define CSN_PINS \
{ 3, 4, 5, 6 } // Encoder Chip Select pins
#define CUR1_PIN A1 // Current measurement for Front motor #define CUR1_PIN A1 // Current measurement for Front motor
#define CUR2_PIN A2 // Current measurement for Aft motor #define CUR2_PIN A2 // Current measurement for Aft motor
...@@ -43,10 +44,10 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller ...@@ -43,10 +44,10 @@ Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
#define DIV_RES1 9000.0 // Resistance of R1 in the voltage dividers #define DIV_RES1 9000.0 // Resistance of R1 in the voltage dividers
#define DIV_RES2 1000.0 // Resistance of R2 in the voltage dividers #define DIV_RES2 1000.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 20.0 // [FIXME] VERIFY! #define SEN0098_SENSI 20.0 // [FIXME] VERIFY!
#define SEN0098_VIOUT 0.12 // [FIXME] VERIFY! #define SEN0098_VIOUT 0.12 // [FIXME] VERIFY!
#define SEN0098_OFFSET 0.12 // [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
...@@ -159,8 +160,8 @@ void loop() { ...@@ -159,8 +160,8 @@ void loop() {
// Read current and power // Read current and power
float psu_cur[2], psu_vol[2]; float psu_cur[2], psu_vol[2];
GetPsu(TENS1_PIN,CUR1_PIN, psu_vol[0], psu_cur[0]); GetPsu(TENS1_PIN, CUR1_PIN, psu_vol[0], psu_cur[0]);
GetPsu(TENS2_PIN,CUR2_PIN, psu_vol[1], psu_cur[1]); GetPsu(TENS2_PIN, CUR2_PIN, psu_vol[1], psu_cur[1]);
SerialPrint(gMode, potent, gEsc_val, wing_angles, psu_vol, psu_cur); SerialPrint(gMode, potent, gEsc_val, wing_angles, psu_vol, psu_cur);
} }
...@@ -271,7 +272,9 @@ unsigned int ReadSensor(uint8_t csn) { ...@@ -271,7 +272,9 @@ unsigned int ReadSensor(uint8_t csn) {
// Output data to use with serial-studio // Output data to use with serial-studio
// The /* and */ indicate beginning and end of stream data. Do not modify!
void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[], float psu_vol[], float psu_cur[]) { void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[], float psu_vol[], float psu_cur[]) {
float freq = map(esc_val, 0, 180, 0, RpmToFreq(gMAX_RPM) * 100.0) / 100.0; float freq = map(esc_val, 0, 180, 0, RpmToFreq(gMAX_RPM) * 100.0) / 100.0;
Serial.print("/*"); Serial.print("/*");
...@@ -283,7 +286,7 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[ ...@@ -283,7 +286,7 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[
Serial.print(","); Serial.print(",");
Serial.print(esc_val); Serial.print(esc_val);
Serial.print(","); Serial.print(",");
Serial.print(freq); // [FIXME] Is it useful? 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(wing_angles[i]); Serial.print(wing_angles[i]);
...@@ -297,12 +300,19 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[ ...@@ -297,12 +300,19 @@ void SerialPrint(String mode, int potent, int esc_val, unsigned int wing_angles[
Serial.println("*/"); Serial.println("*/");
} }
// Get the tension and current of a PSU
void GetPsu(byte vol_pin, byte cur_pin, float &vol, float &cur) {
vol = GetTension(vol_pin);
cur = GetCurrent(cur_pin);
}
// Measure current consumed by module // Measure current consumed by module
float GetCurrent(byte cur_pin) { float GetCurrent(byte cur_pin) {
float cur_raw = (5.0 / 1023.0) * analogRead(cur_pin); float volt_raw = (5.0 / 1023.0) * analogRead(cur_pin);
float cur = cur_raw * -gCUR_QOV + 0.007; //Trimming vale to make current equal to 0 when no current float volt = volt_raw * -gCUR_QOV + SEN0098_OFFSET; // Trimming value to make current equal to 0 when no current
return cur / gCUR_FACT; // get actual current return volt / gCUR_FACT; // Actual current
} }
// Measure the tension provided by the PSU // Measure the tension provided by the PSU
...@@ -311,10 +321,3 @@ float GetTension(byte vol_pin) { ...@@ -311,10 +321,3 @@ float GetTension(byte vol_pin) {
return vol_raw * (DIV_RES1 + DIV_RES2) / (DIV_RES2); return vol_raw * (DIV_RES1 + DIV_RES2) / (DIV_RES2);
} }
// Get the tension and current of a PSU
void GetPsu(byte vol_pin, byte cur_pin, float &vol, float &cur) {
vol = GetTension(vol_pin);
cur= GetCurrent(cur_pin);
}
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