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

Ptibibi/stroke engine speed api #149

Closed
Closed
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
10 changes: 3 additions & 7 deletions Software/lib/StrokeEngine/src/StrokeEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ void StrokeEngine::setSpeed(float speed, bool applyNow = false) {
// Update pattern with new speed, will be used with the next stroke or on
// update request
if (xSemaphoreTake(_patternMutex, portMAX_DELAY) == pdTRUE) {
// Convert FPM into seconds to complete a full stroke
// Constrain stroke time between 10ms and 120 seconds
_timeOfStroke = constrain(60.0 / speed, 0.01, 120.0);

pattern->setTimeOfStroke(_timeOfStroke);
_speed = speed;
pattern->setTimeOfStroke(speed);

#ifdef DEBUG_TALKATIVE
Serial.println("setTimeOfStroke: " + String(_timeOfStroke, 2));
Expand All @@ -75,8 +72,7 @@ void StrokeEngine::setSpeed(float speed, bool applyNow = false) {
}

float StrokeEngine::getSpeed() {
// Convert speed into FPMs
return 60.0 / _timeOfStroke;
return _speed;
}

void StrokeEngine::setDepth(float depth, bool applyNow = false) {
Expand Down
9 changes: 5 additions & 4 deletions Software/lib/StrokeEngine/src/StrokeEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ class StrokeEngine {

/**************************************************************************/
/*!
@brief Set the speed of a stroke. Speed is given in Strokes per Minute
@brief Set the speed of a stroke. Speed is given in mm per Second
and internally calculated to the time a full stroke needs to complete.
Settings tale effect with next stroke, or after calling
applyNewSettingsNow().
@param speed Strokes per Minute. Is constrained from 0.5 to 6000
@param speed mm per second. Is constrained from 0.0 to Config::Driver::maxSpeedMmPerSecond
@param applyNow Set to true if changes should take effect immediately
*/
/**************************************************************************/
void setSpeed(float speed, bool applyNow);

/**************************************************************************/
/*!
@brief Get the speed of a stroke. Speed is returned as Strokes per
Minute.
@brief Get the speed of a stroke. Speed is returned as mm per
Second.
@return Strokes per Minute.
*/
/**************************************************************************/
Expand Down Expand Up @@ -402,6 +402,7 @@ class StrokeEngine {
Pattern *pattern = new SimpleStroke("Simple Stroke");
bool _isHomed = false;
int _index = 0;
float _speed;
int _depth;
int _previousDepth;
int _stroke;
Expand Down
8 changes: 6 additions & 2 deletions Software/lib/StrokeEngine/src/pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ class Pattern {
/*!
@param speed time of a full stroke in [sec]
*/
virtual void setTimeOfStroke(float speed) { _timeOfStroke = speed; }
virtual void setTimeOfStroke(float speed) {
// Speed to time
_timeOfStroke = speed / (min(abs(_stroke), abs(_depth)) * 2.0F);
}

//! Set the maximum stroke a pattern may have
/*!
Expand Down Expand Up @@ -170,7 +173,8 @@ class SimpleStroke : public Pattern {

void setTimeOfStroke(float speed = 0) {
// In & Out have same time, so we need to divide by 2
_timeOfStroke = 0.5 * speed;
// time of stroke
_timeOfStroke = 0.5 * (speed / (min(abs(_stroke), abs(_depth)) * 2.0F));
}

motionParameter nextTarget(unsigned int index) {
Expand Down
5 changes: 2 additions & 3 deletions Software/src/ossm/OSSM.StrokeEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ void OSSM::startStrokeEngineTask(void *pvParameters) {
} else if (Stroker.getState() == READY) {
Stroker.startPattern();
}

Stroker.setSpeed(ossm->setting.speed * 3, true);
Stroker.setSpeed(ossm->setting.speed, true);
lastSetting.speed = ossm->setting.speed;
}

Expand Down Expand Up @@ -114,4 +113,4 @@ void OSSM::startStrokeEngine() {
xTaskCreatePinnedToCore(startStrokeEngineTask, "startStrokeEngineTask",
stackSize, this, configMAX_PRIORITIES - 1,
&runStrokeEngineTaskH, operationTaskCore);
}
}