1
0
mirror of https://gitlab.com/lander-team/lander-cpp.git synced 2025-06-16 07:06:51 +00:00

Added Struct for load cells

This commit is contained in:
Matthew Robinaugh 2021-11-08 15:37:56 -07:00
parent 3eb9369371
commit 541d7f4281
5 changed files with 67 additions and 17 deletions

View File

@ -1,8 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ms-vscode.cpptools",
"wayou.vscode-todo-highlight",
"platformio.platformio-ide",
"usernamehw.errorlens",
"platformio.platformio-ide"
"wayou.vscode-todo-highlight"
]
}

43
include/LoadCells.h Normal file
View File

@ -0,0 +1,43 @@
struct LoadCells {
HX711 loadcell_0;
HX711 loadcell_1;
HX711 loadcell_2;
HX711 loadcell_3;
double lc0Value;
double lc1Value;
double lc2Value;
double lc3Value;
double lc0Calibration;
double lc1Calibration;
double lc2Calibration;
double lc3Calibration;
};
void init_LoadCells(LoadCells &loadCells) {
const int lc_clock = 23;
const int lc_data_0 = 0;
const int lc_data_1 = 1;
const int lc_data_2 = 2;
const int lc_data_3 = 3;
Serial.begin(9600); // Begin serial connection
pinMode(LED_BUILTIN, OUTPUT); // Configure LED pin
// Configure clock pin with high impedance to protect pin (if this doesn't
// work, change to OUTPUT)
pinMode(lc_clock, INPUT);
// Configure load cell data pins as inputs
pinMode(lc_data_0, INPUT);
pinMode(lc_data_1, INPUT);
pinMode(lc_data_2, INPUT);
pinMode(lc_data_3, INPUT);
loadCells.lc0Calibration = loadCellCalibrate(loadcell_0);
loadCells.lc1Calibration = loadCellCalibrate(loadcell_1);
loadCells.lc2Calibration = loadCellCalibrate(loadcell_2);
loadCells.lc3Calibration = loadCellCalibrate(loadcell_3);
}

View File

@ -1,22 +1,20 @@
#include "Vehicle.h"
#include <Arduino.h>
void thrustInfo(struct Vehicle &);
void processTVC(struct Vehicle &);
void write2CSV(struct outVector &, struct Vehicle &);
void printSimResults(struct Vehicle &);
double loadCellCalibrate();
double loadCellCalibrate(struct LoadCells &);
double loadCellCalibrate() {
double loadCellCalibrate(LoadCells &loadCells) {
// place code to calibrate load cells in here
double loadTotal;
double loadTotal = 0.0;
for (double t = 0; t == 10; ++t) {
loadTotal += 1;
loadTotal += loadCell.read();
delay(15);
}
return loadTotal / 10;
return loadTotal / 10.0;
}
void thrustInfo(Vehicle &State) {

View File

@ -8,13 +8,14 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:NATIVE]
platform = native
build_flags = -std=c++11 -Wall -O1 -D NATIVE
lib_deps = bogde/HX711@^0.7.4
[env:teensy41]
platform = teensy
board = teensy41
framework = arduino
build_flags = -std=c++11 -Wall -O1 -D TEENSY
lib_deps = bogde/HX711@^0.7.4

View File

@ -10,6 +10,7 @@
#include <vector>
#elif defined(TEENSY)
#include <Arduino.h>
#include "HX711.h"
unsigned long last;
#endif
@ -21,6 +22,7 @@ unsigned long last;
#include "native.h"
#elif defined(TEENSY)
#include "teensy.h"
#include "LoadCells.h"
#endif
Vehicle State;
@ -45,7 +47,11 @@ void setup() {
burnStartTimeCalc(State);
Serial.println("Starting Height Calculated");
delay(1000);
loadCellCalibrate();
LoadCells loadCells;
init_LoadCells(loadCells);
Serial.println("Load Cells Calibrated");
delay(1000);
}