Skip to content

Commit

Permalink
Added Photodiode array library first edition!
Browse files Browse the repository at this point in the history
  • Loading branch information
grwells committed Apr 8, 2022
1 parent 6116a60 commit fcf951a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/validation_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <global.h>
#include <DRV_10970.h>
#include <ICM_20948.h>
#include <ADCSPhotodiodeArray.h>
#include <FreeRTOS_SAMD51.h>
#include <stdint.h>
#include <comm.h> /* data packet and transmission functions */
Expand Down
70 changes: 70 additions & 0 deletions lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
30 changes: 30 additions & 0 deletions lib/ADCSPhotodiodeArray/src/ADCSPhotodiodeArray.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef ADCSPHOTODIODEARRAY_H
#define ADCSPHOTODIODEARRAY_H

#include <Arduino.h>

/*
* 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
12 changes: 11 additions & 1 deletion src/validation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,25 @@ 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");
#endif
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));
}
Expand Down

0 comments on commit fcf951a

Please sign in to comment.