Skip to content

Commit

Permalink
fixed casting and added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronP15 committed Feb 22, 2024
1 parent 97000a4 commit 59b4ad8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils/SensorDataUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,16 @@ namespace{
double i = 1;
double currentAvg = 0;
for (const auto& sensorData: datas){
// Aaron's Algorithm for Average
// The average is a simplified version of A' =(A(n-1) + a)/n
// where A' is the new average at n, A is the current average at n - 1, and a is the value at n
currentAvg *= 1 - (1.0 / i);
currentAvg += selectorFct(sensorData) / i;
i++;
}

// TODO: this cast is technically iffy, but once we switch to fixed size vectors we should be safe
return currentAvg;
return static_cast<int>(currentAvg);
}
}

Expand Down

0 comments on commit 59b4ad8

Please sign in to comment.