Skip to content

Commit

Permalink
User can specify the type that holds the sum of the Moving Average to…
Browse files Browse the repository at this point in the history
… prevent wrapping and overflows.
  • Loading branch information
gabryelreyes committed Sep 28, 2024
1 parent 11c51ee commit 551d9ab
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
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, 2> 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

0 comments on commit 551d9ab

Please sign in to comment.