Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MovAvg sum type #159

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/architecture/uml/LogicalView/Service.plantuml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ package "Service" as serviceLayer {
on the track.
end note

class MovAvg < T, length > <<service>>
class MovAvg < T, U, length > <<service>>

note top of MovAvg
Moving average filter which can be
Expand Down
2 changes: 1 addition & 1 deletion lib/APPConvoyFollower/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class App
/**
* Moving average filter for proximity sensors.
*/
MovAvg<uint8_t, MOVAVG_PROXIMITY_SENSOR_NUM_MEASUREMENTS> m_movAvgProximitySensor;
MovAvg<uint8_t, uint16_t, MOVAVG_PROXIMITY_SENSOR_NUM_MEASUREMENTS> m_movAvgProximitySensor;

/**
* Report the current vehicle data.
Expand Down
2 changes: 1 addition & 1 deletion lib/APPConvoyLeader/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class App
/**
* Moving average filter for proximity sensors.
*/
MovAvg<uint8_t, MOVAVG_PROXIMITY_SENSOR_NUM_MEASUREMENTS> m_movAvgProximitySensor;
MovAvg<uint8_t, uint16_t, MOVAVG_PROXIMITY_SENSOR_NUM_MEASUREMENTS> m_movAvgProximitySensor;

/**
* Report the current vehicle data.
Expand Down
2 changes: 1 addition & 1 deletion lib/APPConvoyLeader/src/DrivingState.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class DrivingState : public IState
LineStatus m_lineStatus; /**< Status of start-/end line detection */
TrackStatus m_trackStatus; /**< Status of track which means on track or track lost, etc. */
uint8_t m_startEndLineDebounce; /**< Counter used for easys debouncing of the start-/end line detection. */
MovAvg<int16_t, 2> m_posMovAvg; /**< The moving average of the position over 2 calling cycles. */
MovAvg<int16_t, uint32_t, 2U> m_posMovAvg; /**< The moving average of the position over 2 calling cycles. */

/**
* Default constructor.
Expand Down
2 changes: 1 addition & 1 deletion lib/APPRemoteControl/src/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class App
/**
* Moving average filter for proximity sensors.
*/
MovAvg<uint8_t, MOVAVG_PROXIMITY_SENSOR_NUM_MEASUREMENTS> m_movAvgProximitySensor;
MovAvg<uint8_t, uint16_t, MOVAVG_PROXIMITY_SENSOR_NUM_MEASUREMENTS> m_movAvgProximitySensor;

/**
* Report the current vehicle data.
Expand Down
5 changes: 3 additions & 2 deletions lib/Service/src/MovAvg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@
* It is designed for fix point integers.
*
* @tparam T The data type of the moving average result and input values.
* @tparam U The data type of the moving average sum. Must be able to store the maximum value of T * length.
* @tparam length The number of values, which are considered in the moving average calculation.
*/
template<typename T, uint8_t length>
template<typename T, typename U, uint8_t length>
class MovAvg
{
public:
Expand Down Expand Up @@ -149,7 +150,7 @@ class MovAvg
T m_values[length]; /**< List of values, used for moving average calculation. */
uint8_t m_wrIdx; /**< Write index to list of values */
uint8_t m_written; /**< The number of written values to the list of values, till length is reached. */
T m_sum; /**< Sum of all values */
U m_sum; /**< Sum of all values */

/**
* Copy construction of an instance.
Expand Down