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

refact: minor changes and doc improvements

parent 21848595
No related branches found
Tags v2.0.0
No related merge requests found
...@@ -26,8 +26,9 @@ ...@@ -26,8 +26,9 @@
#define BAUD_RATE 115200 // baud rate for serial #define BAUD_RATE 115200 // baud rate for serial
// Pins // Pins
#define ESC1_PIN 10 // ESC Front motor #define ESC1_PIN 10 // ESC Front motor
#define ESC2_PIN 9 // ESC Aft motor #define ESC2_PIN 9 // ESC Aft motor
#define SWITCH_PIN 7 // ON/OFF switch (mode control) #define SWITCH_PIN 7 // ON/OFF switch (mode control)
#define POT_PIN A0 // Potentiometer #define POT_PIN A0 // Potentiometer
...@@ -42,17 +43,17 @@ ...@@ -42,17 +43,17 @@
#define TENS2_PIN A1 // Tension measurement for Aft motor #define TENS2_PIN A1 // Tension measurement for Aft motor
// Values // Values
#define DIV_RES1 48254.0 // Resistance of R1 in the voltage dividers #define DIV_RES1 48254.0 // Resistance of R1 in the voltage dividers (calibrated so voltage matches)
#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_QUIESCENT_FACTOR 0.5 // Bidirectional chip-> V_IOUTQ = 0.5*VCC #define SEN0098_QUIESCENT_FACTOR 0.5 // Bidirectional chip -> V_IOUTQ = 0.5*VCC
#define SEN0098_OFFSET 0.0122 // Manually set so current is 0 when no current #define SEN0098_OFFSET 0.0122 // Calibrated so current is 0 when no current
#define GEAR_RATIO 0.1 // Gear ratio between motor and wings #define GEAR_RATIO 0.1 // Gear ratio between motor and wings
// Calibration of encoders (NEEDS TO BE REDONE WHEN ENCODERS ARE MOVED) // Calibration of encoders
#define ENC_PRECISION 4096 // 12-Bits encoders (nb of points per rot) #define ENC_PRECISION 4096 // 12-Bits encoders (nb of points per rot)
#define ENC_ORIENT \ #define ENC_ORIENT \
{ 1, -1, 1, -1 } // Encoder orientation { 1, -1, 1, -1 } // Encoder orientation
...@@ -118,10 +119,10 @@ void setup() { ...@@ -118,10 +119,10 @@ void setup() {
// Initialize modes // Initialize modes
int switch_state = digitalRead(SWITCH_PIN); int switch_state = digitalRead(SWITCH_PIN);
if (switch_state == LOW) { if (switch_state == LOW) {
gMode = "MANUAL"; gMode = "MANUAL";
Serial.println("[WARNING]: Control motors using potentiometer"); Serial.println("[WARNING]: Control motors using potentiometer");
} else { } else {
gEsc1.write(0); // Must be initialized at 0 otherwise will not start gEsc1.write(0); // Must be initialized at 0 otherwise will not start
gEsc2.write(0); gEsc2.write(0);
...@@ -137,7 +138,7 @@ void setup() { ...@@ -137,7 +138,7 @@ void setup() {
Calibrate(); Calibrate();
} }
delay(1000); delay(1000); // Ensure proper initialization
Serial.println("[INFO]: Setup OK, starting now..."); Serial.println("[INFO]: Setup OK, starting now...");
delay(500); delay(500);
} }
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller Repo: https://gitlab.uliege.be/thlamb/mecharaptor-controller
*******************************************************************************/ *******************************************************************************/
//Read 12-bit rotary encoder (RobinL modified by linarism on forum.arduino.cc) // Read 12-bit rotary encoder
// Inspired from RobinL modified by linarism on forum.arduino.cc
unsigned int ReadSensor(uint8_t csn, int8_t orient, int8_t offset) { unsigned int ReadSensor(uint8_t csn, int8_t orient, int8_t offset) {
unsigned int ret = 0; unsigned int ret = 0;
...@@ -28,6 +29,7 @@ unsigned int ReadSensor(uint8_t csn, int8_t orient, int8_t offset) { ...@@ -28,6 +29,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);
} }
...@@ -46,7 +48,7 @@ float GetCurrent(byte cur_pin) { ...@@ -46,7 +48,7 @@ float GetCurrent(byte cur_pin) {
return volt / gCUR_FACT; // Actual current return volt / gCUR_FACT; // Actual current
} }
// Measure the tension provided by the PSU // Measure the tension provided by the PSU using the voltage divider
float GetTension(byte vol_pin) { float GetTension(byte vol_pin) {
float vol_raw = analogRead(vol_pin) * (5.0 / 1023.0); float vol_raw = analogRead(vol_pin) * (5.0 / 1023.0);
......
...@@ -36,10 +36,11 @@ float PosToDeg(unsigned int pos) { ...@@ -36,10 +36,11 @@ float PosToDeg(unsigned int pos) {
return pos * 360.0 / ENC_PRECISION; return pos * 360.0 / ENC_PRECISION;
} }
// Print an array
void PrintArray(int array[]) { void PrintArray(int array[]) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < sizeof(gCSN_PINS); i++) {
Serial.print(array[i]); Serial.print(array[i]);
if (i < 4 - 1) { if (i < sizeof(gCSN_PINS) - 1) {
Serial.print(", "); Serial.print(", ");
} }
} }
......
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