Skip to content

Store average accelerometer readings in Object Model#590

Open
BrendonBuilds wants to merge 6 commits intoDuet3D:3.5-devfrom
BrendonBuilds:3.5-dev
Open

Store average accelerometer readings in Object Model#590
BrendonBuilds wants to merge 6 commits intoDuet3D:3.5-devfrom
BrendonBuilds:3.5-dev

Conversation

@BrendonBuilds
Copy link
Copy Markdown

Store the average value of each axis of the last accelerometer run in the Object Model

Store the average value of each axis of the last accelerometer run in the Object Model
Comment thread src/Accelerometers/Accelerometers.cpp Outdated
static uint8_t resolution = DefaultResolution;
static uint8_t orientation = 20; // +Z -> +Z, +X -> +X
static volatile uint8_t axesRequested;
constexpr size_t NumAxis = 3;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this var name too generic?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NumAccelerometerAxes would be better

Comment thread src/CAN/ExpansionManager.cpp Outdated
{
{
nullptr, // no lock needed
[] (const ObjectModel *self, const ObjectExplorationContext& context) noexcept -> size_t { return 3; },
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prefer array sizes are tracked?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move NumAccelerometerAxes (renamed from NumAxis) into an existing common header file so that you can use that value instead of 3.

Comment thread 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; },
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prefer array sizes are tracked?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comment

Comment thread src/CAN/ExpansionManager.h Outdated

const char *_ecv_array typeName;
MinCurMax mcuTemp, vin, v12;
float accelerometerLastRunAverages[3];
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you prefer array sizes are defined?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
reprap.BoardsUpdated();
}

static void AddLocalAccelerometerAverages(float averages[]) noexcept
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not add extra arguments to AddLocalAccelerometerRun instead of adding this function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do the same thing for AddAccelerometerRun as well

Comment thread src/CAN/ExpansionManager.cpp Outdated
{
{
nullptr, // no lock needed
[] (const ObjectModel *self, const ObjectExplorationContext& context) noexcept -> size_t { return 3; },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move NumAccelerometerAxes (renamed from NumAxis) into an existing common header file so that you can use that value instead of 3.

Comment thread src/CAN/ExpansionManager.h Outdated

const char *_ecv_array typeName;
MinCurMax mcuTemp, vin, v12;
float accelerometerLastRunAverages[3];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment

Comment thread 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; },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comment

BrendonBuilds and others added 2 commits November 4, 2022 14:11
Add extra arguments to AddLocalAccelerometerRun instead of a separate function

Move NumAccelerometerAxes to CANLib\RRF3Common.h
@BrendonBuilds
Copy link
Copy Markdown
Author

The second commit will require the changes in: Duet3D/CANlib#8

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
static void AddLocalAccelerometerAverages(float averages[]) noexcept
{
for(unsigned int axis = 0;axis < NumAxis;++axis)
for(unsigned int axis = 0;axis < NumAccelerometerAxes;++axis)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest use memcpyf here instead of a loop

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
if (device.IsRemote())
{
reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0);
reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0, {0});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to pass an array of the correct size here because the compiler doesn't know how many values are expected

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
# endif
{
AddLocalAccelerometerRun(0);
AddLocalAccelerometerRun(0, {0});
Copy link
Copy Markdown
Collaborator

@dc42 dc42 Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
accelerometerFile = nullptr;
MassStorage::Delete(accelerometerFileName.c_str(), false);
reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0);
reprap.GetExpansion().AddAccelerometerRun(device.boardAddress, 0, {0});
Copy link
Copy Markdown
Collaborator

@dc42 dc42 Nov 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
f->Close();
accelerometerFile = nullptr;
reprap.GetExpansion().AddAccelerometerRun(src, 0);
reprap.GetExpansion().AddAccelerometerRun(src, 0, {0});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.

Comment thread src/Accelerometers/Accelerometers.cpp Outdated
f->Close();
accelerometerFile = nullptr;
reprap.GetExpansion().AddAccelerometerRun(src, 0);
reprap.GetExpansion().AddAccelerometerRun(src, 0, {0});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment.

Comment thread src/Accelerometers/Accelerometers.cpp Outdated

// find the average value for each axis
for (unsigned int axis = 0; axis < NumAxis; ++axis)
for (unsigned int axis = 0; axis < NumAccelerometerAxes; ++axis)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use a range-based for-loop here

Comment thread src/CAN/ExpansionManager.cpp Outdated
boards[address].accelerometerLastRunDataPoints = numDataPoints;
++boards[address].accelerometerRuns;

for(int32_t i = 0;i < NumAccelerometerAxes;++i)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use memcpyf here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants