Update Overview authored by Colton Glick's avatar Colton Glick
...@@ -19,115 +19,4 @@ The pitch-roll drone mount allows the drone to be mounted to the test stand when ...@@ -19,115 +19,4 @@ The pitch-roll drone mount allows the drone to be mounted to the test stand when
See here: https://git.ece.iastate.edu/danc/MicroCART/-/wikis/Test-Stand/Electronics See here: https://git.ece.iastate.edu/danc/MicroCART/-/wikis/Test-Stand/Electronics
# The Firmware # The Firmware
``` cpp The firmware code to run the test stand control board can be viewed in [/test_stand_firmware](/../blob/master/test_stand_firmware)
#include <movingAvg.h> \ No newline at end of file
const int DATA_PIN = A7;
const int BUTTON_PIN = 2;
int buttonState = 0;
const boolean NO_HANDSHAKE = false;
const int SEND_CODE = 65;
int incomingByte = 0;
int val = 0;
const double TEN_BIT_SCALAR = 0.3516; // 360/1024
int homePosition;
// Rate variables
long lastTime = 0;
long currTime = 0;
long lastReading = 0;
long currReading = 0;
int prevRate = 0;
long deltaTime = 0;
long deltaReading = 0;
double rate;
// Long Press Variables
long buttonTimer = 0;
const long LONG_PRESS_MILLIS = 250;
boolean buttonActive = false;
boolean longPressActive = false;
boolean isInPositionMode = true;
movingAvg mySensor(10);
void serialFlush() {
while (Serial.available() > 0) {
char t = Serial.read();
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
homePosition = analogRead(DATA_PIN);
homePosition += 512;
lastTime = millis();
lastReading = analogRead(DATA_PIN);
mySensor.begin();
}
void loop() {
currTime = millis();
currReading = analogRead(DATA_PIN);
if (digitalRead(BUTTON_PIN) == HIGH) {
if (buttonActive == false) { // Button was not pressed last cycle
buttonActive = true;
buttonTimer = millis();
}
if (((millis() - buttonTimer) > LONG_PRESS_MILLIS) && (longPressActive == false)) { // Detected a long press, swap modes
longPressActive = true;
isInPositionMode = !isInPositionMode;
}
}
else {
if (buttonActive == true) { // Button was being pressed last cycle
if (longPressActive == true) { // Button was being long pressed last cycle, user has released the long press
longPressActive = false;
}
else { // Short press occured, grab current position regardless of mode
homePosition = analogRead(DATA_PIN);
homePosition += 512;
}
buttonActive = false;
}
}
// LED on if we're in position mode, off if we're in rate mode
digitalWrite(LED_BUILTIN, isInPositionMode);
if (isInPositionMode == true) {
double absoluteDegrees = TEN_BIT_SCALAR * (double) currReading;
double relativeDegrees = TEN_BIT_SCALAR * (double) homePosition;
double displayPosition = absoluteDegrees - relativeDegrees;
displayPosition += (displayPosition < 0) ? (360) : (0);
Serial.println((displayPosition-180));
delay(100);
}
else { // We're in rate mode
deltaTime = currTime - lastTime;
deltaReading = currReading - lastReading;
rate = 1000 * ((TEN_BIT_SCALAR * deltaReading) / (deltaTime));
// Thanks josh for the fix
if(abs(rate - prevRate) > 360) {
}else{
mySensor.reading(rate);
Serial.println(mySensor.getAvg()*-1);
delay(50);
}
prevRate = rate;
}
// Reset vars for next cycle
lastTime = currTime;
lastReading = currReading;
}
```
\ No newline at end of file