Skip to content

Commit edae7a8

Browse files
committed
Broken zeroing reorder
1 parent 5acf8aa commit edae7a8

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

Inc/ST-LIB_HIGH/Control/Blocks/Zeroing.hpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@
22
#include "../ControlBlock.hpp"
33
#include "MeanCalculator.hpp"
44
#include "Sensors/LinearSensor/LinearSensor.hpp"
5-
template<class Type, size_t Order>
6-
class Zeroing : public ControlBlock<Type,Type>{
7-
public:
8-
MeanCalculator<Order> mean_calculator;
9-
LinearSensor<Type>& sensor;
10-
Type max_value_offset;
11-
bool has_max_value = false;
12-
Zeroing(LinearSensor<Type>& sensor) : sensor(sensor), mean_calculator(){};
13-
Zeroing(LinearSensor<Type>& sensor, Type max_value_offset) : mean_calculator(), sensor(sensor), max_value_offset(max_value_offset), has_max_value(true){};
14-
void execute(){
15-
while(mean_calculator.output_value == 0){
16-
sensor.read();
17-
mean_calculator.input(*sensor.get_value_pointer());
18-
mean_calculator.execute();
19-
}
20-
if(has_max_value && abs(mean_calculator.output_value) > max_value_offset) {
21-
ErrorHandler("Zeroing offset is calculated to be above specified maximum");
22-
}
23-
else sensor.set_offset(sensor.get_offset() - mean_calculator.output_value);
24-
mean_calculator.reset();
25-
}
5+
template <class Type, size_t Order>
6+
class Zeroing : public ControlBlock<Type, Type> {
7+
public:
8+
LinearSensor<Type>& sensor;
9+
MeanCalculator<Order> mean_calculator;
10+
Type max_value_offset;
11+
bool has_max_value = false;
12+
Zeroing(LinearSensor<Type>& sensor) : sensor(sensor), mean_calculator() {};
13+
Zeroing(LinearSensor<Type>& sensor, Type max_value_offset)
14+
: mean_calculator(),
15+
sensor(sensor),
16+
max_value_offset(max_value_offset),
17+
has_max_value(true) {};
18+
void execute() {
19+
while (mean_calculator.output_value == 0) {
20+
sensor.read();
21+
mean_calculator.input(*sensor.get_value_pointer());
22+
mean_calculator.execute();
23+
}
24+
if (has_max_value &&
25+
abs(mean_calculator.output_value) > max_value_offset) {
26+
ErrorHandler(
27+
"Zeroing offset is calculated to be above specified maximum");
28+
} else
29+
sensor.set_offset(sensor.get_offset() -
30+
mean_calculator.output_value);
31+
mean_calculator.reset();
32+
}
2633
};

0 commit comments

Comments
 (0)