From 492f21fda860de017f5bdc1558637321a5c94786 Mon Sep 17 00:00:00 2001
From: Alfonso Parra Rubio <alfonso.parra@cba.mit.edu>
Date: Sat, 15 Jun 2024 20:40:47 -0700
Subject: [PATCH] stable code motors running

---
 .DS_Store                          | Bin 0 -> 6148 bytes
 code/.DS_Store                     | Bin 0 -> 6148 bytes
 code/motors_accel/motors_accel.ino |  66 +++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)
 create mode 100644 .DS_Store
 create mode 100644 code/.DS_Store
 create mode 100755 code/motors_accel/motors_accel.ino

diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..339bbf1aac038f05bcf007f101fd2bc9fda20ef3
GIT binary patch
literal 6148
zcmZQzU|@7AO)+F(5MW?n;9!8zj35RBCIAV8Fop~hRD=y=9>|R1<fQ!k97YBP1{SE)
zpr=4?XJ$xdNMuM!OF?#jGDAK?3PUPZ!JKr%;N<+=0wmwDFhDir=DWBg<>V)U0yglV
zr@(#QV~*eefy<}hl`qJ^FdNC5QRZj}jE2By2#kinXb4ao0-%Z-R84VHY|^L!qaiRF
z0>do?K;?r1q;1dO0HqrsG)Rhpk%0l+1z<#K?=yn>0T4AHtspfZtsoktm4Ok&0?UK7
zGB85B3XI@x2m=EnxJv?}!P*%Z!8U{VVC@WyV4E2j7$Mpj7@<84Sm%Wi)T05J57ExR
z2)2E=#muOGMniz|5MYKFApolXT^Sf)SqLIJN{)uWXb6mm5MX3+33hP;Rhl@w3#w~D
z^=SfB9#jWIs$)>ajM@lbf($51K$U{3dyrNT4X%nA85qD?M;ijL5E`XNLxBDv006Ro
BFU9}>

literal 0
HcmV?d00001

diff --git a/code/.DS_Store b/code/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..2666bd64da3b01adf6a00b1eb823ddf7947c92b2
GIT binary patch
literal 6148
zcmZQzU|@7AO)+F(5MW?n;9!8z3~dZp0Z1N%F(jFwB8(vOz-AON6f?v#Br+s3Btzv0
zQ6RlM47m*X3?&Tt49NOZ8FJE6ij$M_^K(Fo2pKdgKN<p~Aut*OqaiRF0;3^7R0u$;
zRSs^VRF5he4S~@R7)c=jDjyUeZF>d>DBS>|K~fBi3=H5d03!nf3oKk1!TkURkQ_)W
zhz4l|(IBl1j35@+46s%PMyOUsa5n^`57Z?A(O~Tij9{BVe6V%~MzGBc42%%%42)2l
z8KFHCMu>I>Mu>I>MzHNL*NxJnAut*Oun=H|Fa$vLzbgX+uKqtn)hIa{0;3@?EJJ{i
z#U<Fq30x^-_aCUP1=XhsP&Egj${0cQGDHld1XQ(yt79g}prQm+8Au$Y9YlkxV@3uB
TaBV)?7=VS)C_Nei^bG+3=X@4T

literal 0
HcmV?d00001

diff --git a/code/motors_accel/motors_accel.ino b/code/motors_accel/motors_accel.ino
new file mode 100755
index 0000000..58482ec
--- /dev/null
+++ b/code/motors_accel/motors_accel.ino
@@ -0,0 +1,66 @@
+
+// Include the AccelStepper Library
+#include <AccelStepper.h>
+
+// Define pin connections
+const int guillotinedirPin = 1;
+const int guillotinestepPin = 2;
+const int feederdirPin = 14;
+const int feederstepPin = 15;
+// Define motor interface type
+#define motorInterfaceType 1
+
+
+           // outside leads to ground and +5V
+int val = 0;  // variable to store the value read
+int analogPin = 26; // potentiometer wiper (middle terminal) connected to analog pin 3
+                    // outside leads to ground and +5V
+
+// Creates an instance
+AccelStepper guillotine(motorInterfaceType, guillotinestepPin, guillotinedirPin);
+AccelStepper feeder(motorInterfaceType, feederstepPin, feederdirPin);
+
+void setup() {
+	// set the maximum speed, acceleration factor,
+	// guillotine initial speed and target position
+	guillotine.setMaxSpeed(10000);
+	guillotine.setAcceleration(5500);
+	guillotine.setSpeed(9000);
+	guillotine.moveTo(200*16*5);
+  //feeder params
+  feeder.setMaxSpeed(10000);
+	feeder.setAcceleration(5500);
+	feeder.setSpeed(9000);
+	feeder.moveTo(200*16*0.5);
+  // microstepping the guillotine and the feeder? can they share a bus? we will see 
+  pinMode(3, OUTPUT);
+  pinMode(4, OUTPUT);
+  pinMode(5, OUTPUT);
+  //microstepping the feeder
+
+}
+
+void loop() {
+  val = analogRead(analogPin); 
+  val = map(val, 0, 1023, 1, 10);
+  guillotine.setSpeed(val*1000);
+  Serial.println(val);          // debug value
+	// Change direction once the motor reaches target position
+  digitalWrite(3, HIGH);
+  digitalWrite(4, HIGH);
+  digitalWrite(5, HIGH);
+
+
+
+  if (feeder.distanceToGo() == 0) 
+		feeder.moveTo(-feeder.currentPosition());
+    
+	// Move the motor one step
+	guillotine.run();
+  feeder.run(); 
+
+
+}
+
+
+
-- 
GitLab