diff --git a/cli.cpp b/cli.cpp index 968e3c890c6329a390f07ae955cba205805da7d5..1a3d45fb424e26da08eef7237a9acf1a69cb16dd 100644 --- a/cli.cpp +++ b/cli.cpp @@ -76,18 +76,20 @@ void Cli::syntax (const char* cmd) { if (!cmd || kw(F("AT"), cmd)) Serial.printf("%sAT -> OK\n", _msgHeader.c_str()); if (!cmd || kw(F("HELP"), cmd)) Serial.printf("%sHELP [CMD]\n", _msgHeader.c_str()); - if (!cmd || kw(F("RAT"), cmd)) Serial.printf("%sRAT [ C <rate> <unit> ] - set or show rate (UM/MM/UH/MH)\n", _msgHeader.c_str()); - if (!cmd || kw(F("VOL"), cmd)) Serial.printf("%sVOL [ <vol> | <unit> ] - set volume or unit (UL / ML)\n", _msgHeader.c_str()); - if (!cmd || kw(F("MM"), cmd)) Serial.printf("%sMM [ <len> ] - set distance (mm)\n", _msgHeader.c_str()); - if (!cmd || kw(F("DIA"), cmd)) Serial.printf("%sDIA [ <dia> ] - set or show inside syringe diameter (in mm)\n", _msgHeader.c_str()); - if (!cmd || kw(F("DIR"), cmd)) Serial.printf("%sDIR [ INF | WDR ] - set or show direction (INFuse / WithDRaw)\n", _msgHeader.c_str()); - if (!cmd || kw(F("FIL"), cmd)) Serial.printf("%sFIL - start filling using direction at rate for volume\n", _msgHeader.c_str()); - if (!cmd || kw(F("STP"), cmd)) Serial.printf("%sSTP - stop\n", _msgHeader.c_str()); - if (!cmd || kw(F("DIS"), cmd)) Serial.printf("%sDIS - show volume dispensed\n", _msgHeader.c_str()); - if (!cmd || kw(F("ZERO"), cmd)) Serial.printf("%sZERO - go to stopper\n", _msgHeader.c_str()); - if (!cmd || kw(F("SET0"), cmd)) Serial.printf("%sSET0 - change ZERO to current position\n", _msgHeader.c_str()); - if (!cmd || kw(F("NLCK"), cmd)) Serial.printf("%sNLCK - try to get out from stopper\n", _msgHeader.c_str()); - if (!cmd || kw(F("CONF"), cmd)) Serial.printf("%sCONF - show configuration\n", _msgHeader.c_str()); + if (!cmd || kw(F("RAT"), cmd)) Serial.printf("%sRAT [ C <rate> [<unit>] ] - set or show rate ([UM]/MM/UH/MH)\n", _msgHeader.c_str()); + if (!cmd || kw(F("VOL"), cmd)) Serial.printf("%sVOL [ <vol> | <unit> ] - set volume or unit (UL / ML)\n", _msgHeader.c_str()); + if (!cmd || kw(F("MM"), cmd)) Serial.printf("%sMM [ <len> ] - set distance (mm)\n", _msgHeader.c_str()); + if (!cmd || kw(F("DIA"), cmd)) Serial.printf("%sDIA [ <dia> ] - set or show inside syringe diameter (in mm)\n", _msgHeader.c_str()); + if (!cmd || kw(F("ACC"), cmd)) Serial.printf("%sACC [ <mm/s/s> ] - set or show acceletaration (mm/s/s) (0<=>oo)\n", _msgHeader.c_str()); + if (!cmd || kw(F("RVM"), cmd)) Serial.printf("%sRVM [ <M4|M5> ] - set or show auger size\n", _msgHeader.c_str()); + if (!cmd || kw(F("DIR"), cmd)) Serial.printf("%sDIR [ INF | WDR ] - set or show direction (INFuse / WithDRaw)\n", _msgHeader.c_str()); + if (!cmd || kw(F("FIL"), cmd)) Serial.printf("%sFIL - start filling using direction at rate for volume\n", _msgHeader.c_str()); + if (!cmd || kw(F("STP"), cmd)) Serial.printf("%sSTP - stop\n", _msgHeader.c_str()); + if (!cmd || kw(F("DIS"), cmd)) Serial.printf("%sDIS - show volume dispensed\n", _msgHeader.c_str()); + if (!cmd || kw(F("ZERO"), cmd)) Serial.printf("%sZERO - go to stopper\n", _msgHeader.c_str()); + if (!cmd || kw(F("SET0"), cmd)) Serial.printf("%sSET0 - change ZERO to current position\n", _msgHeader.c_str()); + if (!cmd || kw(F("NLCK"), cmd)) Serial.printf("%sNLCK - try to get out from stopper\n", _msgHeader.c_str()); + if (!cmd || kw(F("CONF"), cmd)) Serial.printf("%sCONF - show configuration\n", _msgHeader.c_str()); } void Cli::answer (bool ok, const String& error_message) const @@ -101,7 +103,7 @@ void Cli::answer (bool ok, const String& error_message) const void Cli::checkEmergency () { if (syringe.emergency()) - Serial.printf("%s: in EMERGENCY state, try NLCK command\n", _msgHeader.c_str()); + Serial.printf("%sin EMERGENCY state, try NLCK command\n", _msgHeader.c_str()); } void Cli::loop (Stream& input) @@ -145,19 +147,19 @@ void Cli::loop (Stream& input) conf.rate_ul_per_s = atof(_temp.c_str()); copyNextToTemp(); if (_temp.length() == 0) - conf.rate_ul_per_s *= 60; // default uL/mn + conf.rate_ul_per_s /= 60; // default uL/mn else if (_temp.equalsIgnoreCase(F("us"))) - conf.rate_ul_per_s *= 1; + conf.rate_ul_per_s /= 1; else if (_temp.equalsIgnoreCase(F("ms"))) conf.rate_ul_per_s *= 1000; else if (_temp.equalsIgnoreCase(F("um"))) - conf.rate_ul_per_s *= 60; + conf.rate_ul_per_s /= 60; else if (_temp.equalsIgnoreCase(F("mm"))) - conf.rate_ul_per_s *= 1000 * 60.0; + conf.rate_ul_per_s *= 1000 / 60.0; else if (_temp.equalsIgnoreCase(F("uh"))) - conf.rate_ul_per_s *= 3600; + conf.rate_ul_per_s /= 3600; else if (_temp.equalsIgnoreCase(F("mh"))) - conf.rate_ul_per_s *= 1000 * 3600.0; + conf.rate_ul_per_s *= 1000 / 3600.0; else conf.rate_ul_per_s = -1; answer(syringe.configureSyringe(conf), F("invalid 'RAT C rate [unit]'")); @@ -166,7 +168,7 @@ void Cli::loop (Stream& input) answer(false, F("RAT must be followed by C")); Serial.printf("%sRAT: %g ul/mn\n", _msgHeader.c_str(), - syringe.configuration().rate_ul_per_s / 60); + syringe.configuration().rate_ul_per_s * 60); } else if (kw(F("VOL"))) @@ -215,6 +217,24 @@ void Cli::loop (Stream& input) } Serial.printf("%sDIA: %g mm\n", _msgHeader.c_str(), syringe.configuration().diameter_mm); } + else if (kw(F("RVM"))) + { + copyNextToTemp(); + if (_temp == F("M4")) + syringe.setMmPerRev(M4_MMREV); + else if (_temp == F("M5")) + syringe.setMmPerRev(M5_MMREV); + else if (_temp.length() > 0) + answer(false, F("invalid auger size: M4 or M5 are accepted")); + Serial.printf("%sRVM: %g mm per revolution\n", _msgHeader.c_str(), syringe.getMmPerRev()); + } + else if (kw(F("ACC"))) + { + copyNextToTemp(); + if (_temp.length()) + syringe.setAccelMmPerSecPerSec(atof(_temp.c_str())); + Serial.printf("%sACC: %g mm per second per second\n", _msgHeader.c_str(), syringe.getAccelMmPerSecPerSec()); + } else if (kw(F("DIR"))) { copyNextToTemp(); diff --git a/motor.h b/motor.h index 755db7eb9ec73cab0c323ce2d8cdd19877281bbd..50b04fbde47471c96fc7f96f538348b31c73a741 100644 --- a/motor.h +++ b/motor.h @@ -22,22 +22,33 @@ public: Motor (AccelStepper& stepper): stepper(stepper) { setSpeedMmPerSec(1); - setAccelMmPerSecPerSec(0.1); // <----- this is not yet configured by user + setAccelMmPerSecPerSec(0.5); // <----- this is not yet configured by user } void setLock (bool locked) { _locked = locked; } bool locked () const { return _locked; } + void setMmPerRev (float mmPerRevolution) + { + _mmPerRevolution = mmPerRevolution; + } + + float getMmPerRev () const + { + return _mmPerRevolution; + } + void setPhysical (int stepsPerRevolution, float mmPerRevolution, bool forwardClockwise) { _stepsPerRevolution = stepsPerRevolution; - _mmPerRevolution = mmPerRevolution; + setMmPerRev(mmPerRevolution); _forwardClockwise = forwardClockwise; } void setSpeedMmPerSec (float mmPerSec) { + Serial.printf("# set speed to %g steps/s\n", mmToStep(mmPerSec)); #if !CORE_MOCK stepper.setMaxSpeed(mmToStep(mmPerSec)); #endif @@ -45,12 +56,19 @@ public: void setAccelMmPerSecPerSec (float mmPerSecPerSec) { + if (mmPerSecPerSec == 0) + mmPerSecPerSec = 1000; _retainAccel = mmPerSecPerSec; #if !CORE_MOCK stepper.setAcceleration(mmToStep(mmPerSecPerSec)); #endif } + float getAccelMmPerSecPerSec () const + { + return _retainAccel; + } + float mmToStep (float mm) const { return mm * _stepsPerRevolution / _mmPerRevolution; diff --git a/syringe.cpp b/syringe.cpp index 00993f4965716f7c7f35b9f1ac491095cf9ef52a..173bca925640d443d10d1995c46b03acf2a0e239 100644 --- a/syringe.cpp +++ b/syringe.cpp @@ -54,6 +54,7 @@ float Syringe::confToMm () const void Syringe::fill () { + Serial.printf("# set speed to %g mm/s\n", mm3ToMm(current_configuration.rate_ul_per_s)); setSpeedMmPerSec(mm3ToMm(current_configuration.rate_ul_per_s)); moveToMm(confToMm()); } diff --git a/syringe.h b/syringe.h index ce31982daeb4caafc6b1ef07cb985fcb84243d4f..315c6a9affc7e1fb519ee2a20ab0b540079f844d 100644 --- a/syringe.h +++ b/syringe.h @@ -83,7 +83,7 @@ private: { .diameter_mm = 10, .capacity_ul = 1000, - .rate_ul_per_s = 80, + .rate_ul_per_s = 100, .volume_value = 50, .volume_unit_ul = 1, .direction = 1,