Skip to content
Snippets Groups Projects
Commit 8fae7851 authored by David Gauchard's avatar David Gauchard
Browse files

Merge branch 'syringe_2' into 'master'

Add initial volume and volume/duration control.

See merge request fablaas/pousseseringue/pousseseringue-arduino!11
parents 5355564e 77e6d2fc
No related branches found
No related tags found
1 merge request!11Add initial volume and volume/duration control.
......@@ -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);
}
......@@ -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;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment