diff --git a/include/LoadCells.h b/include/LoadCells.h index 2b89a93..02dcc09 100644 --- a/include/LoadCells.h +++ b/include/LoadCells.h @@ -31,8 +31,8 @@ double loadCellCalibrate(HX711 loadCell) { } void update_LoadCells(LoadCells &loadCells) { - loadCells.lc0Val = loadCells.lc0.read(); - loadCells.lc1Val = loadCells.lc1.read(); - loadCells.lc2Val = loadCells.lc2.read(); - loadCells.lc3Val = loadCells.lc3.read(); + loadCells.lc0Val = loadCells.lc0.read() - loadCells.lc0Cal; + loadCells.lc1Val = loadCells.lc1.read() - loadCells.lc1Cal; + loadCells.lc2Val = loadCells.lc2.read() - loadCells.lc2Cal; + loadCells.lc3Val = loadCells.lc3.read() - loadCells.lc3Cal; } \ No newline at end of file diff --git a/include/Vehicle.h b/include/Vehicle.h index a5de21e..03db381 100644 --- a/include/Vehicle.h +++ b/include/Vehicle.h @@ -22,7 +22,7 @@ struct Vehicle { double thrust, burnElapsed, burnStart; int thrustFiring = 0; // 0: Pre-burn, 1: Mid-burn, 2: Post-burn - double PIDx, PIDy, Fx, Fy, Fz; + double PIDx, PIDy, Fx, Fy, Fz, F; double momentX, momentY, momentZ; double I11, I22, I33; diff --git a/include/teensy.h b/include/teensy.h index b04d15c..ad34b43 100644 --- a/include/teensy.h +++ b/include/teensy.h @@ -97,19 +97,22 @@ void processTVC(Vehicle &State, LoadCells &loadCells) { if (State.time == 0) { Serial.println("WARNING: processTVC not implemented for TEENSY"); } - + double r = 3.0; + double R = 5.0; // Vector math to aqcuire thrust vector components // PLACEHOLDER PLACEHOLDERPLACEHOLDER PLACEHOLDERPLACEHOLDER // PLACEHOLDERPLACEHOLDER PLACEHOLDERPLACEHOLDER PLACEHOLDER - State.Fx = loadCells.lc1Val + loadCells.lc2Val; - State.Fy = loadCells.lc0Val + loadCells.lc3Val; - State.Fz = sqrt(pow(State.thrust, 2) - pow(State.Fx, 2) - pow(State.Fy, 2)) + - (State.mass * g); + State.Fx = (loadCells.lc1Val - loadCells.lc2Val) * r / R; + State.Fy = (loadCells.lc0Val - loadCells.lc3Val) * r / R; + State.Fz = + loadCells.lc0Val + loadCells.lc1Val + loadCells.lc2Val + loadCells.lc3Val; // Calculate moment created by Fx and Fy State.momentX = State.Fx * State.momentArm; State.momentY = State.Fy * State.momentArm; State.momentZ = 0.0; + + State.F = sqrt(pow(State.Fx, 2) + pow(State.Fy, 2) + pow(State.Fz, 2)); } void write2CSV(Vehicle &State, double a, double b, double c, double d) {