Skip to content
Snippets Groups Projects
Commit efa9f8ec authored by Clément Foucher's avatar Clément Foucher
Browse files

Add squeletton for Syringe to Motor interface.

parent d1da7935
No related branches found
No related tags found
1 merge request!7Add squeletton for Syringe to Motor interface.
#include "motor.h"
// Global object
Motor motor;
void Motor::reset()
{
// Open full
}
void Motor::turn(bool direction, float duration, float speed)
{
// Direction: push (true) or pull (false)
// Duration: in s
// Speed: in mm/min
// This function is in charge of converting the
// linar speed in mm/min to angular speed in steps/min
}
motor.h 0 → 100644
class Motor
{
public:
void reset();
void turn(bool direction, float duration, float speed);
private:
int current_step_count = 0;
};
// Global object
extern Motor motor;
#include <math.h>
#include "syringe.h"
#include "motor.h"
// Global object
Syringe syringe;
// Members definitions
float Syringe::volumeToDistance(float volume)
{
// Volume is in mL => convert to mm³
float volume_in_mm3 = 1000*volume;
// Distance to travel is in mm => use syringe piston surface in mm²
float distance = volume_in_mm3/this->piston_surface;
return distance;
}
void Syringe::configureSyringe(Syringe_configuration_t config)
{
this->current_configuration = config;
this->piston_surface = M_PI * pow(config.diameter,2) / 4.;
this->is_configured = true;
}
void Syringe::reset()
{
// TODO: go back to home. At which speed?
float speed = 100; // Default to 10 cm/min
this->pull(this->current_configuration.capacity, speed);
}
void Syringe::push(float volume, float throughput)
{
// Ensure syringe is configured before using it
if (this->is_configured == false)
return;
// Volume in mL, throughput in µL/min, duration in min
this->pushFor(volume/throughput, throughput);
}
void Syringe::pushAll(float throughput)
{
// Ensure syringe is configured before using it
if (this->is_configured == false)
return;
this->push(this->current_configuration.capacity, throughput);
}
void Syringe::pushFor(float duration, float throughput)
{
// Ensure syringe is configured before using it
if (this->is_configured == false)
return;
float volume = throughput*duration;
float distance = this->volumeToDistance(volume);
float speed = distance/duration;
motor.turn(true, duration, speed);
}
void Syringe::pull(float volume, float throughput)
{
// Ensure syringe is configured before using it
if (this->is_configured == false)
return;
// Volume in mL, throughput in µL/min, duration in min
this->pullFor(volume/throughput, throughput);
}
void Syringe::pullAll(float throughput)
{
// Ensure syringe is configured before using it
if (this->is_configured == false)
return;
this->pull(this->current_configuration.capacity, throughput);
}
void Syringe::pullFor(float duration, float throughput)
{
// Ensure syringe is configured before using it
if (this->is_configured == false)
return;
float volume = throughput*duration;
float distance = this->volumeToDistance(volume);
float speed = distance/duration;
motor.turn(false, duration, speed);
}
class Syringe
{
public:
/**
* Diameter in mm
* Capacity in mL
*/
typedef struct
{
int diameter;
int capacity;
} Syringe_configuration_t;
private:
float volumeToDistance(float volume);
public:
// Configuration
void configureSyringe(Syringe_configuration_t config);
// Actions
void reset();
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 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
private:
Syringe_configuration_t current_configuration = {0};
bool is_configured = false;
float piston_surface = 0;
};
// Global object
extern Syringe syringe;
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