diff --git a/syringe.cpp b/syringe.cpp index 83b1a67377b078c49448808a03457a19ebc2b4f4..efdf0a6dde1506ec46f6b92383ad081e1fb67035 100644 --- a/syringe.cpp +++ b/syringe.cpp @@ -27,6 +27,43 @@ void Syringe::configureSyringe(Syringe_configuration_t config) this->is_configured = true; } +void Syringe::setInitialContent(float initial_volume) +{ + this->remaining_volume = initial_volume; +} + +void Syringe::moveMotor(bool direction, float duration, float speed) +{ + float quantity = speed*this->piston_surface*duration; + if (direction == true) + { + if (quantity <= this->remaining_volume) + { + this->remaining_volume -= quantity; + } + else + { + quantity = this->remaining_volume; + this->remaining_volume = 0; + } + } + else + { + if (this->remaining_volume + quantity <= this->current_configuration.capacity) + { + this->remaining_volume += quantity; + } + else + { + quantity = this->current_configuration.capacity - this->remaining_volume; + this->remaining_volume = this->current_configuration.capacity; + } + } + + // TODO: recompute duration to match quantity before sending commande to motor + motor.turn(direction, duration, speed); +} + void Syringe::reset() { // TODO: go back to home. At which speed? @@ -63,7 +100,17 @@ void Syringe::pushFor(float duration, float throughput) float distance = this->volumeToDistance(volume); float speed = distance/duration; - motor.turn(true, duration, speed); + this->moveMotor(true, duration, speed); +} + +void Syringe::pushVol(float volume, float duration) +{ + // Ensure syringe is configured before using it + if (this->is_configured == false) + return; + + float throughput = volume/duration; + this->push(volume, throughput); } void Syringe::pull(float volume, float throughput) @@ -95,5 +142,15 @@ void Syringe::pullFor(float duration, float throughput) float distance = this->volumeToDistance(volume); float speed = distance/duration; - motor.turn(false, duration, speed); + this->moveMotor(false, duration, speed); +} + +void Syringe::pullVol(float volume, float duration) +{ + // Ensure syringe is configured before using it + if (this->is_configured == false) + return; + + float throughput = volume/duration; + this->pull(volume, throughput); } diff --git a/syringe.h b/syringe.h index 24a7a53d6695e87f2e7b120bbe16e6e0213d6bfb..f28710fc0a389d2db72c89c97f2a12e8f175b71b 100644 --- a/syringe.h +++ b/syringe.h @@ -16,10 +16,12 @@ public: private: float volumeToDistance(float volume); + void moveMotor(bool direction, float duration, float speed); public: // Configuration void configureSyringe(Syringe_configuration_t config); + void setInitialContent(float initial_volume); // Actions void reset(); @@ -27,14 +29,17 @@ public: void push(float volume, float throughput); // Volume in mL, throughput in µL/min void pushAll(float throughput); // Throughput in µL/min void pushFor(float duration, float throughput); // Duration in min, throughput in µL/min + void pushVol(float volume, float duration); // Volume in mL, duration in min void pull(float volume, float throughput); // Volume in mL, throughput in µL/min void pullAll(float throughput); // Throughput in µL/min void pullFor(float duration, float throughput); // Duration in min, throughput in µL/min + void pullVol(float volume, float duration); // Volume in mL, duration in min private: Syringe_configuration_t current_configuration = {0}; bool is_configured = false; + float remaining_volume = 0; float piston_surface = 0; };