From efa9f8ecac8792b7b4910b63f260608f41c3d9f1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Foucher?= <cfoucher@laas.fr>
Date: Mon, 9 May 2022 15:26:18 +0200
Subject: [PATCH] Add squeletton for Syringe to Motor interface.

---
 motor.cpp   | 19 ++++++++++
 motor.h     | 14 ++++++++
 syringe.cpp | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 syringe.h   | 42 +++++++++++++++++++++++
 4 files changed, 174 insertions(+)
 create mode 100644 motor.cpp
 create mode 100644 motor.h
 create mode 100644 syringe.cpp
 create mode 100644 syringe.h

diff --git a/motor.cpp b/motor.cpp
new file mode 100644
index 0000000..51c65e2
--- /dev/null
+++ b/motor.cpp
@@ -0,0 +1,19 @@
+#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
+}
diff --git a/motor.h b/motor.h
new file mode 100644
index 0000000..5d72027
--- /dev/null
+++ b/motor.h
@@ -0,0 +1,14 @@
+
+
+class Motor
+{
+public:
+	void reset();
+	void turn(bool direction, float duration, float speed);
+
+private:
+	int current_step_count = 0;
+};
+
+// Global object
+extern Motor motor;
diff --git a/syringe.cpp b/syringe.cpp
new file mode 100644
index 0000000..83b1a67
--- /dev/null
+++ b/syringe.cpp
@@ -0,0 +1,99 @@
+#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);
+}
diff --git a/syringe.h b/syringe.h
new file mode 100644
index 0000000..24a7a53
--- /dev/null
+++ b/syringe.h
@@ -0,0 +1,42 @@
+
+
+
+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;
-- 
GitLab