Hello all,
I've been working on code that controls a "skydiving" aircraft, but when I compile it says, Error compiling for board Arduino Uno. The code seems fine and I can upload other sketches, and I think I removed all the bugs. Any ideas on what is happening?
Thanks so much!
P.S Am I using this forum correctly? I'm a bit new here.
//Tuning Variables, PID gains for pitch and yaw, timing, etc.
int PpG = 0;
int IpG = 0;
int DpG = 0;
int PyG = 0;
int IyG = 0;
int DyG = 0;
int IntegralCutoff = 10;
int timeDelayAscent = 6;
int timeDelayBellyflop = 10;
int frequency = 50;
int PitchGoal = 0;
int YawGoal = 0;
//Libraries
#include <Arduino.h>
#include <TinyMPU6050.h>
#include <Wire.h>
#include <Servo.h>
MPU6050 mpu (Wire);
Servo front;
Servo back;
//Other variables
long timer = 0;
int Pitch;
int Yaw;
int LEDpin = 4;
int AccX;
int AccY;
int AccZ;
void setup() {
Serial.begin(9600);
mpu.Calibrate();
pinMode(LEDpin, OUTPUT);
front.write(90);
back.write(90);
}
//PHASES OF FLIGHT
void preLaunch();
void ascentPhase();
void bellyflopPhase();
void landingPhase();
void sensorData () {
mpu.Execute();
AccX = int(mpu.GetAccX());
AccY = int(mpu.GetAccY());
AccZ = int(mpu.GetAccZ());
Pitch = int(mpu.GetAngX());
Yaw = int(mpu.GetGyroZ());
}
void landingPhase () {
for (;;) {
digitalWrite(LEDpin, HIGH);
delay(2000);
digitalWrite(LEDpin, LOW);
delay(2000);
}
}
void bellyflopPhase () {
int k = 0;
int l = 0;
int PitchErrorIntegral = 0;
int YawErrorIntegral = 0;
digitalWrite(LEDpin, HIGH);
int PitchError = 0;
int YawError = 0;
while (k < (timeDelayBellyflop * (1000 / frequency))) {
k++;
int PrevPitchError = PitchError;
int PrevYawError = YawError;
sensorData();
int PitchError = Pitch - PitchGoal;
int YawError = Yaw - YawGoal;
if (abs(PitchErrorIntegral) < IntegralCutoff) {
int PitchErrorIntegral = PitchErrorIntegral + PitchError;
}
if (abs(YawErrorIntegral) < IntegralCutoff) {
int YawErrorIntegral = YawErrorIntegral + YawError;
}
int PitchErrorDerivative = PitchError - PrevPitchError;
int YawErrorDerivative = YawError - PrevYawError;
back.write(cos((PitchError * PpG) + (PitchErrorIntegral * IpG) + (PitchErrorDerivative * DpG)) * (180 / 3.14159));
front.write((YawError * PyG) + (YawErrorIntegral * IyG) + (YawErrorDerivative * DpG));
delay (frequency);
}
}
void ascentPhase() {
int j = 0;
while (j < (timeDelayAscent * (1000 / frequency))) {
delay(frequency);
digitalWrite(LEDpin, HIGH);
front.write(90);
back.write(170);
}
}
void preLauch () {
int i = 0;
front.write(90);
back.write(170); //all the way deployeed
while (i < 20) {
i = i + 1;
sensorData();
digitalWrite(LEDpin, HIGH);
delay(200);
digitalWrite(LEDpin, LOW);
delay(800);
}
while ((abs(AccY) < 1.5) or (abs(AccZ) < 1.5) or (abs(AccX) < 1.5)) {
digitalWrite(LEDpin, HIGH);
delay(200);
digitalWrite(LEDpin, LOW);
delay(200);
}
}