diff --git a/include/validation_tests.h b/include/validation_tests.h index 5a17fdf..f850431 100644 --- a/include/validation_tests.h +++ b/include/validation_tests.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include /* data packet and transmission functions */ diff --git a/lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.cpp b/lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.cpp new file mode 100644 index 0000000..754ca99 --- /dev/null +++ b/lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.cpp @@ -0,0 +1,70 @@ +#include "ADCSPhotodiodeArray.h" + +/* + * Configure the pins attached to the multiplexer (a-c) as outputs and the pin on analog input as an input. + */ +ADCSPhotodiodeArray::ADCSPhotodiodeArray(uint8_t analog_input, uint8_t a, uint8_t b, uint8_t c){ + // configure digital pins + pinMode(a, OUTPUT); + digitalWrite(a, LOW); + + pinMode(b, OUTPUT); + digitalWrite(b, LOW); + + pinMode(c, OUTPUT); + digitalWrite(c, LOW); + + // configure analog pins + pinMode(analog_input, INPUT); +} + +/* + * Read the value measured on one of the 6 multiplexer channels. + */ +int ADCSPhotodiodeArray::read(uint8_t channel){ + switch(channel){ + case 0: + digitalWrite(a, LOW); + digitalWrite(b, LOW); + digitalWrite(c, LOW); + break; + + case 1: + digitalWrite(a, HIGH); + digitalWrite(b, LOW); + digitalWrite(c, LOW); + break; + + case 2: + digitalWrite(a, LOW); + digitalWrite(b, HIGH); + digitalWrite(c, LOW); + break; + + case 3: + digitalWrite(a, HIGH); + digitalWrite(b, HIGH); + digitalWrite(c, LOW); + break; + + case 4: + digitalWrite(a, LOW); + digitalWrite(b, LOW); + digitalWrite(c, HIGH); + break; + + case 5: + digitalWrite(a, LOW); + digitalWrite(b, LOW); + digitalWrite(c, HIGH); + break; + + default: + digitalWrite(a, LOW); + digitalWrite(b, LOW); + digitalWrite(c, LOW); + + } + + return analogRead(analog_pin); +} \ No newline at end of file diff --git a/lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.h b/lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.h new file mode 100644 index 0000000..30e284f --- /dev/null +++ b/lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.h @@ -0,0 +1,30 @@ +#ifndef ADCSPHOTODIODEARRAY_H +#define ADCSPHOTODIODEARRAY_H + +#include + +/* + * Truth table for the multiplexer that the 6 photodiodes will be hooked up to. + * + * INPUTS + * | A | B | C | CHANNEL | + * ----------------------- + * | L | L | L | 0 | + * | H | L | L | 1 | + * | L | H | L | 2 | + * | H | H | L | 3 | + * | L | L | H | 4 | + * | H | L | H | 5 | + * + */ + +class ADCSPhotodiodeArray { +private: + uint8_t analog_pin, a, b, c; + +public: + ADCSPhotodiodeArray(uint8_t analog_input, uint8_t a, uint8_t b, uint8_t c); + int read(uint8_t channel); // select which channel to read from by number +}; + +#endif diff --git a/src/validation_tests.cpp b/src/validation_tests.cpp index 9ae0d16..7e60512 100644 --- a/src/validation_tests.cpp +++ b/src/validation_tests.cpp @@ -149,7 +149,10 @@ void basic_attitude_control(void* pvParameters){ * @param pvParameters The pv parameters */ void simple_detumble(void* pvParameters){ + uint8_t mode; + uint8_t pwm = 10; + while(true){ #if DEBUG SERCOM_USB.println("[BASIC DETUMBLE] checked mode"); @@ -157,7 +160,14 @@ void simple_detumble(void* pvParameters){ xQueuePeek(modeQ, &mode, 0); if(mode == CMD_TST_SIMPLE_DETUMBLE){ - // TODO: write the detumble test in validation_tests.cpp + + float rot_vel_z = IMU1.gyrZ(); + if(rot_vel_z > 0){ // spinning clockwise + flywhl.run(REV, pwm); + + }else if(rot_vel_z < 0){ // spinning counter-clockwise + flywhl.run(FWD, pwm); + } } vTaskDelay(pdMS_TO_TICKS(1000)); }