mirror of
https://gitlab.com/lander-team/lander-cpp.git
synced 2025-07-23 14:41:25 +00:00
load cell integration
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
|
||||
#include <HX711.h>
|
||||
#pragma once
|
||||
|
||||
struct LoadCells {
|
||||
HX711 lc0;
|
||||
HX711 lc1;
|
||||
HX711 lc2;
|
||||
HX711 lc3;
|
||||
|
||||
// Current calibrated value
|
||||
double lc0Val;
|
||||
double lc1Val;
|
||||
double lc2Val;
|
||||
double lc3Val;
|
||||
|
||||
// Calibration offset
|
||||
double lc0Cal;
|
||||
double lc1Cal;
|
||||
double lc2Cal;
|
||||
double lc3Cal;
|
||||
};
|
||||
|
||||
double loadCellCalibrate(HX711 loadCell) {
|
||||
// place code to calibrate load cells in here
|
||||
double loadTotal = 0.0;
|
||||
for (int t = 0; t == 10; ++t) {
|
||||
loadTotal += loadCell.read();
|
||||
delay(15);
|
||||
}
|
||||
return loadTotal / 10.0;
|
||||
}
|
||||
|
||||
void update_LoadCells(LoadCells &loadCells) {
|
||||
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;
|
||||
}
|
@@ -44,6 +44,8 @@ struct Vehicle {
|
||||
double stepDuration;
|
||||
|
||||
double time = 0.0;
|
||||
|
||||
double lc0, lc1, lc2, lc3;
|
||||
};
|
||||
|
||||
void init_Vehicle(Vehicle &State) {
|
||||
|
@@ -1,4 +1,3 @@
|
||||
#include "LoadCells.h"
|
||||
#include "Vehicle.h"
|
||||
#include <Arduino.h>
|
||||
#include <SD.h>
|
||||
@@ -8,7 +7,7 @@ double loadCellCalibrate();
|
||||
void initFile();
|
||||
void thrustInfo(struct Vehicle &);
|
||||
void processTVC(struct Vehicle &);
|
||||
void write2CSV(struct Vehicle &, double a, double b, double c, double d);
|
||||
void write2CSV(struct Vehicle &);
|
||||
void printSimResults(struct Vehicle &);
|
||||
void teensyAbort();
|
||||
|
||||
@@ -94,7 +93,7 @@ void thrustInfo(Vehicle &State) {
|
||||
}
|
||||
}
|
||||
|
||||
void processTVC(Vehicle &State, LoadCells &loadCells) {
|
||||
void processTVC(Vehicle &State) {
|
||||
if (State.time == 0) {
|
||||
Serial.println("WARNING: processTVC not implemented for TEENSY");
|
||||
}
|
||||
@@ -103,10 +102,14 @@ void processTVC(Vehicle &State, LoadCells &loadCells) {
|
||||
// Vector math to aqcuire thrust vector components
|
||||
// PLACEHOLDER PLACEHOLDERPLACEHOLDER PLACEHOLDERPLACEHOLDER
|
||||
// PLACEHOLDERPLACEHOLDER PLACEHOLDERPLACEHOLDER PLACEHOLDER
|
||||
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;
|
||||
State.Fx = (State.lc1 - State.lc2) * r / R;
|
||||
State.Fy = (State.lc0 - State.lc3) * r / R;
|
||||
State.Fz = State.lc0 + State.lc1 + State.lc2 + State.lc3;
|
||||
|
||||
State.Fx = State.thrust * sin(State.xServoDegs * (M_PI / 180.0));
|
||||
State.Fy = State.thrust * sin(State.yServoDegs * (M_PI / 180.0));
|
||||
State.Fz = sqrt(pow(State.thrust, 2) - pow(State.Fx, 2) - pow(State.Fy, 2)) +
|
||||
(State.mass * g);
|
||||
|
||||
// Calculate moment created by Fx and Fy
|
||||
State.momentX = State.Fx * State.momentArm;
|
||||
@@ -116,7 +119,7 @@ void processTVC(Vehicle &State, LoadCells &loadCells) {
|
||||
State.F = sqrt(pow(State.Fx, 2) + pow(State.Fy, 2) + pow(State.Fz, 2));
|
||||
}
|
||||
|
||||
void write2CSV(Vehicle &State, LoadCells &loadCells) {
|
||||
void write2CSV(Vehicle &State) {
|
||||
dataFile.print(String(State.time, 5));
|
||||
dataFile.print(",");
|
||||
|
||||
@@ -168,13 +171,13 @@ void write2CSV(Vehicle &State, LoadCells &loadCells) {
|
||||
dataFile.print(String(State.stepDuration, 5));
|
||||
dataFile.print(",");
|
||||
|
||||
dataFile.print(String(loadCells.lc0Val, 5));
|
||||
dataFile.print(String(State.lc0, 5));
|
||||
dataFile.print(",");
|
||||
dataFile.print(String(loadCells.lc1Val, 5));
|
||||
dataFile.print(String(State.lc1, 5));
|
||||
dataFile.print(",");
|
||||
dataFile.print(String(loadCells.lc2Val, 5));
|
||||
dataFile.print(String(State.lc2, 5));
|
||||
dataFile.print(",");
|
||||
dataFile.print(String(loadCells.lc3Val, 5));
|
||||
dataFile.print(String(State.lc3, 5));
|
||||
|
||||
dataFile.print("\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user