50 float p0Voltage,
float p0Mass,
float p1Voltage,
52 : getVoltage{
std::move(getVoltage)},
53 staticScale{(p1Mass - p0Mass) / (p1Voltage - p0Voltage)},
54 staticOffset{p0Mass - staticScale * p0Voltage}
59 : getVoltage{
std::move(other.getVoltage)},
60 dynamicOffset{other.dynamicOffset.load()},
61 staticScale{other.staticScale}, staticOffset{other.staticOffset}
65 bool init()
override {
return true; }
72 void setOffset(
float value) { dynamicOffset = value; }
80 float currentOffset = 0.0f;
85 currentOffset = dynamicOffset.load();
86 }
while (!dynamicOffset.compare_exchange_weak(currentOffset,
87 currentOffset + value));
98 auto voltage = getVoltage();
99 auto mass = voltage.voltage * staticScale + staticOffset;
101 return {voltage.voltageTimestamp, mass - dynamicOffset};
107 std::atomic<float> dynamicOffset{0.0f};
109 const float staticScale;
110 const float staticOffset;
Base sensor class with has to be extended by any sensor driver.
Sensor class for a two point calibrated load cell.
LoadCellData sampleImpl() override
Read a data sample from the sensor. In case of errors, the method should return the last available co...
TwoPointAnalogLoadCell(TwoPointAnalogLoadCell &&other)
bool init() override
Initialize the sensor.
TwoPointAnalogLoadCell(std::function< VoltageData()> getVoltage, float p0Voltage, float p0Mass, float p1Voltage, float p1Mass)
Construct a TwoPointAnalogLoadCell.
bool selfTest() override
Check if the sensor is working.
void setOffset(float value)
Set the current load cell offset. Ignores any previous offsets.
float getOffset()
Retrieve the current offset.
void updateOffset(float value)
Update the current load cell offset. Adds the new value to the old offset.
This file includes all the types the logdecoder script will decode.
Structure to handle voltage data.