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

StrokeEngine: fix: drive StrokeEngine by speed #134

Closed

Conversation

Ptibibi
Copy link
Contributor

@Ptibibi Ptibibi commented Oct 30, 2024

use speed on main consigne to reduce injuries risk.
speed is more stable when stroke, depth and sensation are updated.

@Ptibibi
Copy link
Contributor Author

Ptibibi commented Oct 30, 2024

I noticed an increase in speed if the stroke setpoint is higher than the depth setpoint.
This behavior is not new, just highlighted by the fix.
I'll investigate.

workaround - https://github.com/Ptibibi/OSSM-hardware/tree/ptibibi/workaround_api_override_stroke_if_bigger_than_depth

@Ptibibi Ptibibi force-pushed the ptibibi/StrokeEngine_integration branch 2 times, most recently from c23a7c2 to cbb5c79 Compare November 1, 2024 12:16
Comment on lines 41 to 58
float speedConsignePercent = ossm->setting.speed;
ESP_LOGD("UTILS", "speedConsignePercent: %f%", speedConsignePercent);
ESP_LOGD("UTILS", "maxSpeedMmPerSecond: %fmm/s", Config::Driver::maxSpeedMmPerSecond);
float speedMmPerSecond = (Config::Driver::maxSpeedMmPerSecond * speedConsignePercent) / 100.0F;
ESP_LOGD("UTILS", "speedMmPerSecond: %fmm/s", speedMmPerSecond);

float strokeMm = Stroker.getStroke();
ESP_LOGD("UTILS", "strokeMm: %fmm", strokeMm);
float depthMm = Stroker.getDepth();
ESP_LOGD("UTILS", "depthMm: %fmm", depthMm);
float travelMm = min(abs(strokeMm), abs(depthMm));
ESP_LOGD("UTILS", "travelMm: %fmm", travelMm);
float tripMm = travelMm * 2.0F;
ESP_LOGD("UTILS", "tripMm: %fmm", tripMm);

float tripPerSecond = speedMmPerSecond / tripMm;
ESP_LOGD("UTILS", "tripPerSecond: %ftrip/s", tripPerSecond);
float tripPerMinute = tripPerSecond * 60.0F;
ESP_LOGD("UTILS", "tripPerMinute: %ftrip/min", tripPerMinute);

float newSpeedMmPerSecond = tripPerMinute * tripMm / 60.0F;
ESP_LOGD("UTILS", "newSpeedMmPerSecond: %fmm/s", newSpeedMmPerSecond);

Stroker.setSpeed(tripPerMinute, true);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
float speedConsignePercent = ossm->setting.speed;
ESP_LOGD("UTILS", "speedConsignePercent: %f%", speedConsignePercent);
ESP_LOGD("UTILS", "maxSpeedMmPerSecond: %fmm/s", Config::Driver::maxSpeedMmPerSecond);
float speedMmPerSecond = (Config::Driver::maxSpeedMmPerSecond * speedConsignePercent) / 100.0F;
ESP_LOGD("UTILS", "speedMmPerSecond: %fmm/s", speedMmPerSecond);
float strokeMm = Stroker.getStroke();
ESP_LOGD("UTILS", "strokeMm: %fmm", strokeMm);
float depthMm = Stroker.getDepth();
ESP_LOGD("UTILS", "depthMm: %fmm", depthMm);
float travelMm = min(abs(strokeMm), abs(depthMm));
ESP_LOGD("UTILS", "travelMm: %fmm", travelMm);
float tripMm = travelMm * 2.0F;
ESP_LOGD("UTILS", "tripMm: %fmm", tripMm);
float tripPerSecond = speedMmPerSecond / tripMm;
ESP_LOGD("UTILS", "tripPerSecond: %ftrip/s", tripPerSecond);
float tripPerMinute = tripPerSecond * 60.0F;
ESP_LOGD("UTILS", "tripPerMinute: %ftrip/min", tripPerMinute);
float newSpeedMmPerSecond = tripPerMinute * tripMm / 60.0F;
ESP_LOGD("UTILS", "newSpeedMmPerSecond: %fmm/s", newSpeedMmPerSecond);
Stroker.setSpeed(tripPerMinute, true);
float tripPerMinute = 0.0F;
#ifdef DEBUG_TALKATIVE
float speedConsignePercent = ossm->setting.speed;
ESP_LOGD("UTILS", "speedConsignePercent: %f%", speedConsignePercent);
ESP_LOGD("UTILS", "maxSpeedMmPerSecond: %fmm/s", Config::Driver::maxSpeedMmPerSecond);
float speedMmPerSecond = (Config::Driver::maxSpeedMmPerSecond * speedConsignePercent) / 100.0F;
ESP_LOGD("UTILS", "speedMmPerSecond: %fmm/s", speedMmPerSecond);
float strokeMm = Stroker.getStroke();
ESP_LOGD("UTILS", "strokeMm: %fmm", strokeMm);
float depthMm = Stroker.getDepth();
ESP_LOGD("UTILS", "depthMm: %fmm", depthMm);
float travelMm = min(abs(strokeMm), abs(depthMm));
ESP_LOGD("UTILS", "travelMm: %fmm", travelMm);
float tripMm = travelMm * 2.0F;
ESP_LOGD("UTILS", "tripMm: %fmm", tripMm);
float tripPerSecond = speedMmPerSecond / tripMm;
ESP_LOGD("UTILS", "tripPerSecond: %ftrip/s", tripPerSecond);
tripPerMinute = tripPerSecond * 60.0F;
ESP_LOGD("UTILS", "tripPerMinute: %ftrip/min", tripPerMinute);
float newSpeedMmPerSecond = tripPerMinute * tripMm / 60.0F;
ESP_LOGD("UTILS", "newSpeedMmPerSecond: %fmm/s", newSpeedMmPerSecond);
#endif
tripPerMinute = ((Config::Driver::maxSpeedMmPerSecond * ossm->setting.speed / 100.0F) / (min(abs(Stroker.getStroke()), abs(Stroker.getDepth())) * 2.0F)) * 60.0F;
Stroker.setSpeed(tripPerMinute, true);

Suggestion: Reduce memory footprint of calculations and cpu footprint of debug logging unless in debug mode.

Code suggestion is not an implied approval.
Will bench test this functionality later this week.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@armpitMFG , suggestion applied and checked with my setup.
Thank for your review.
I'll keep the footprint in mind for the future.
It's been a long time since I did any dev on mcu.

@Ptibibi Ptibibi force-pushed the ptibibi/StrokeEngine_integration branch 2 times, most recently from 985ee03 to 7ee0f81 Compare November 6, 2024 22:57
use speed on main consigne to reduce injuries risk.
speed is more stable when depth, distance and sensation are updated

Signed-off-by: benoit robert <benoit.robert.dev@gmail.com>
@Ptibibi Ptibibi force-pushed the ptibibi/StrokeEngine_integration branch from 7ee0f81 to db70c5f Compare November 15, 2024 21:08
@Ptibibi
Copy link
Contributor Author

Ptibibi commented Nov 15, 2024

@armpitMFG, I've adjusting your proposition to group some values

@Ptibibi Ptibibi closed this Nov 27, 2024
@Ptibibi Ptibibi deleted the ptibibi/StrokeEngine_integration branch November 27, 2024 18:11
@Ptibibi
Copy link
Contributor Author

Ptibibi commented Nov 29, 2024

@AJ-Koenig, @armpitMFG
I close this proposition because I show some little side effect and integration is more like a workaround.
I will propose a better fix soon

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