Store average accelerometer readings in Object Model#590
Store average accelerometer readings in Object Model#590BrendonBuilds wants to merge 6 commits intoDuet3D:3.5-devfrom
Conversation
Store the average value of each axis of the last accelerometer run in the Object Model
| static uint8_t resolution = DefaultResolution; | ||
| static uint8_t orientation = 20; // +Z -> +Z, +X -> +X | ||
| static volatile uint8_t axesRequested; | ||
| constexpr size_t NumAxis = 3; |
There was a problem hiding this comment.
Is this var name too generic?
There was a problem hiding this comment.
NumAccelerometerAxes would be better
src/CAN/ExpansionManager.cpp
Outdated
| { | ||
| { | ||
| nullptr, // no lock needed | ||
| [] (const ObjectModel *self, const ObjectExplorationContext& context) noexcept -> size_t { return 3; }, |
There was a problem hiding this comment.
How would you prefer array sizes are tracked?
There was a problem hiding this comment.
Move NumAccelerometerAxes (renamed from NumAxis) into an existing common header file so that you can use that value instead of 3.
src/Platform/Platform.cpp
Outdated
| // 2. Average readings from last accelerometer run | ||
| { | ||
| nullptr, // no lock needed | ||
| [] (const ObjectModel *self, const ObjectExplorationContext& context) noexcept -> size_t { return 3; }, |
There was a problem hiding this comment.
How would you prefer array sizes are tracked?
src/CAN/ExpansionManager.h
Outdated
|
|
||
| const char *_ecv_array typeName; | ||
| MinCurMax mcuTemp, vin, v12; | ||
| float accelerometerLastRunAverages[3]; |
There was a problem hiding this comment.
How would you prefer array sizes are defined?
| reprap.BoardsUpdated(); | ||
| } | ||
|
|
||
| static void AddLocalAccelerometerAverages(float averages[]) noexcept |
There was a problem hiding this comment.
Why not add extra arguments to AddLocalAccelerometerRun instead of adding this function?
There was a problem hiding this comment.
I will do the same thing for AddAccelerometerRun as well
src/CAN/ExpansionManager.cpp
Outdated
| { | ||
| { | ||
| nullptr, // no lock needed | ||
| [] (const ObjectModel *self, const ObjectExplorationContext& context) noexcept -> size_t { return 3; }, |
There was a problem hiding this comment.
Move NumAccelerometerAxes (renamed from NumAxis) into an existing common header file so that you can use that value instead of 3.
src/CAN/ExpansionManager.h
Outdated
|
|
||
| const char *_ecv_array typeName; | ||
| MinCurMax mcuTemp, vin, v12; | ||
| float accelerometerLastRunAverages[3]; |
src/Platform/Platform.cpp
Outdated
| // 2. Average readings from last accelerometer run | ||
| { | ||
| nullptr, // no lock needed | ||
| [] (const ObjectModel *self, const ObjectExplorationContext& context) noexcept -> size_t { return 3; }, |
Add extra arguments to AddLocalAccelerometerRun instead of a separate function Move NumAccelerometerAxes to CANLib\RRF3Common.h
|
The second commit will require the changes in: Duet3D/CANlib#8 |
| static void AddLocalAccelerometerAverages(float averages[]) noexcept | ||
| { | ||
| for(unsigned int axis = 0;axis < NumAxis;++axis) | ||
| for(unsigned int axis = 0;axis < NumAccelerometerAxes;++axis) |
There was a problem hiding this comment.
Suggest use memcpyf here instead of a loop
| if (device.IsRemote()) | ||
| { | ||
| reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0); | ||
| reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0, {0}); |
There was a problem hiding this comment.
Need to pass an array of the correct size here because the compiler doesn't know how many values are expected
| # endif | ||
| { | ||
| AddLocalAccelerometerRun(0); | ||
| AddLocalAccelerometerRun(0, {0}); |
There was a problem hiding this comment.
Need to pass an array of the correct size here because the compiler doesn't know how many values are expected, or add a new function AddFailedLocalAccelerometerRun that doesn't take the averages parameter
| accelerometerFile = nullptr; | ||
| MassStorage::Delete(accelerometerFileName.c_str(), false); | ||
| reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0); | ||
| reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0, {0}); |
There was a problem hiding this comment.
Need to pass an array of the correct size here because the compiler doesn't know how many values are expected. Alternatively, add another function AddFailedAccelerometerRun that doesn't take the averages as a parameter and instead sets them to zero, since this appears to be done in several places.
| f->Close(); | ||
| accelerometerFile = nullptr; | ||
| reprap.GetExpansion().AddAccelerometerRun(src, 0); | ||
| reprap.GetExpansion().AddAccelerometerRun(src, 0, {0}); |
| f->Close(); | ||
| accelerometerFile = nullptr; | ||
| reprap.GetExpansion().AddAccelerometerRun(src, 0); | ||
| reprap.GetExpansion().AddAccelerometerRun(src, 0, {0}); |
|
|
||
| // find the average value for each axis | ||
| for (unsigned int axis = 0; axis < NumAxis; ++axis) | ||
| for (unsigned int axis = 0; axis < NumAccelerometerAxes; ++axis) |
There was a problem hiding this comment.
Better to use a range-based for-loop here
src/CAN/ExpansionManager.cpp
Outdated
| boards[address].accelerometerLastRunDataPoints = numDataPoints; | ||
| ++boards[address].accelerometerRuns; | ||
|
|
||
| for(int32_t i = 0;i < NumAccelerometerAxes;++i) |
Store the average value of each axis of the last accelerometer run in the Object Model