mirror of
https://gitlab.com/lander-team/static-load-test-code.git
synced 2025-06-15 22:56:42 +00:00
setup for calibration values and some rudimentary filtering
This commit is contained in:
parent
91db1a179d
commit
11e2aeede6
78
src/main.cpp
78
src/main.cpp
@ -4,6 +4,7 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
LoadCells State;
|
||||
LoadCells PrevState;
|
||||
|
||||
HX711 lc0;
|
||||
HX711 lc1;
|
||||
@ -18,6 +19,13 @@ void read_lc0();
|
||||
void read_lc1();
|
||||
void read_lc2();
|
||||
void read_lc3();
|
||||
double limit(double current, double previous);
|
||||
|
||||
// Load Cell Calibration Constants
|
||||
const double k0 = -518.7;
|
||||
const double k1 = -633.39;
|
||||
const double k2 = -202.56;
|
||||
const double k3 = -295.53;
|
||||
|
||||
const int lc_clock = 23;
|
||||
const int pin_lc0 = 14;
|
||||
@ -28,11 +36,13 @@ const int pin_lc3 = 20;
|
||||
const int chipSelect = BUILTIN_SDCARD;
|
||||
File dataFile;
|
||||
|
||||
void setup() {
|
||||
void setup()
|
||||
{
|
||||
delay(1000);
|
||||
Serial.print("Initializing SD card...");
|
||||
|
||||
if (!SD.begin(chipSelect)) {
|
||||
if (!SD.begin(chipSelect))
|
||||
{
|
||||
|
||||
Serial.println("initialization failed. Things to check:");
|
||||
|
||||
@ -93,21 +103,22 @@ void setup() {
|
||||
String dataString = "lc0,lc1,lc2,lc3";
|
||||
File dataFile = SD.open("datalog.csv", FILE_WRITE);
|
||||
|
||||
if (dataFile) {
|
||||
|
||||
if (dataFile)
|
||||
{
|
||||
dataFile.println(dataString);
|
||||
|
||||
dataFile.close();
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
else
|
||||
{
|
||||
Serial.println("error opening datalog.csv");
|
||||
}
|
||||
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
String dataString = String(State.lc0) + "," + String(State.lc1) + "," +
|
||||
String(State.lc2) + "," + String(State.lc3);
|
||||
Serial.println(dataString);
|
||||
@ -115,23 +126,50 @@ void loop() {
|
||||
|
||||
File dataFile = SD.open("datalog.csv", FILE_WRITE);
|
||||
|
||||
if (dataFile) {
|
||||
|
||||
if (dataFile)
|
||||
{
|
||||
dataFile.println(dataString);
|
||||
|
||||
dataFile.close();
|
||||
|
||||
Serial.println(dataString);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
else
|
||||
{
|
||||
Serial.println("error opening datalog.csv");
|
||||
}
|
||||
}
|
||||
|
||||
void read_lc0() { State.lc0 = lc0.get_value(); }
|
||||
void read_lc1() { State.lc1 = lc1.get_value(); }
|
||||
void read_lc2() { State.lc2 = lc2.get_value(); }
|
||||
void read_lc3() { State.lc3 = lc3.get_value(); }
|
||||
void read_lc0()
|
||||
{
|
||||
State.lc0 = lc0.get_value();
|
||||
State.lc0 = limit(State.lc0, PrevState.lc0);
|
||||
PrevState.lc0 = State.lc0;
|
||||
}
|
||||
void read_lc1()
|
||||
{
|
||||
State.lc1 = lc1.get_value();
|
||||
State.lc1 = limit(State.lc1, PrevState.lc1);
|
||||
PrevState.lc1 = State.lc1;
|
||||
}
|
||||
void read_lc2()
|
||||
{
|
||||
State.lc2 = lc2.get_value();
|
||||
State.lc2 = limit(State.lc2, PrevState.lc2);
|
||||
PrevState.lc2 = State.lc2;
|
||||
}
|
||||
void read_lc3()
|
||||
{
|
||||
State.lc3 = lc3.get_value();
|
||||
State.lc3 = limit(State.lc3, PrevState.lc3);
|
||||
PrevState.lc3 = State.lc3;
|
||||
}
|
||||
|
||||
double limit(double current, double previous)
|
||||
{
|
||||
double limit = 1000000;
|
||||
|
||||
if (abs(current - previous) > limit)
|
||||
return previous;
|
||||
else
|
||||
return current;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user