|
@@ -11,8 +11,6 @@
|
|
#include "Atm_out.h"
|
|
#include "Atm_out.h"
|
|
|
|
|
|
//osc
|
|
//osc
|
|
-
|
|
|
|
-
|
|
|
|
#include <SPI.h>
|
|
#include <SPI.h>
|
|
#include <Ethernet.h>
|
|
#include <Ethernet.h>
|
|
#include <EthernetUdp.h>
|
|
#include <EthernetUdp.h>
|
|
@@ -20,6 +18,9 @@
|
|
#include <OSCBundle.h>
|
|
#include <OSCBundle.h>
|
|
|
|
|
|
|
|
|
|
|
|
+#include <Servo.h>
|
|
|
|
+
|
|
|
|
+
|
|
//////////////// Ethernet /////////////////////////////
|
|
//////////////// Ethernet /////////////////////////////
|
|
// Enter a MAC address and IP address for your controller below.
|
|
// Enter a MAC address and IP address for your controller below.
|
|
// The IP address will be dependent on your local network:
|
|
// The IP address will be dependent on your local network:
|
|
@@ -46,24 +47,27 @@ const int LOW_ACC = 1000 ;
|
|
|
|
|
|
Atm_Teenstep_OSC X_top_OSC;
|
|
Atm_Teenstep_OSC X_top_OSC;
|
|
Atm_Teenstep X_top_step;
|
|
Atm_Teenstep X_top_step;
|
|
-// Atm_TeensyStep X_top_step;
|
|
|
|
Stepper X_top_stepper(20 , 19);
|
|
Stepper X_top_stepper(20 , 19);
|
|
StepControl X_top_controller ;
|
|
StepControl X_top_controller ;
|
|
|
|
|
|
-Atm_TeensyStep Y_top_step;
|
|
|
|
-Stepper Y_top_stepper(6 , 5);
|
|
|
|
-// Stepper Y_top_stepper(22 , 21);
|
|
|
|
|
|
+Atm_Teenstep_OSC Y_top_OSC;
|
|
|
|
+Atm_Teenstep Y_top_step;
|
|
|
|
+Stepper Y_top_stepper(22 , 21);
|
|
StepControl Y_top_controller ;
|
|
StepControl Y_top_controller ;
|
|
|
|
|
|
-Atm_out peristaltic;
|
|
|
|
-int peristaltic_pwm_pin = 3;
|
|
|
|
-int peristaltic_dir_pin = 2;
|
|
|
|
-
|
|
|
|
|
|
|
|
void testCallback(){
|
|
void testCallback(){
|
|
// printPosition
|
|
// printPosition
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/////////////////// Servo and pump ////////////////////////
|
|
|
|
+
|
|
|
|
+const int peristaltic_pwm_pin = 3;
|
|
|
|
+const int peristaltic_dir_pin = 2;
|
|
|
|
+bool peristaltic_direction = 0 ;
|
|
|
|
+
|
|
|
|
+Servo pill_trap ;
|
|
|
|
+
|
|
/////////////////// Feeders serial communication ////////////////////////
|
|
/////////////////// Feeders serial communication ////////////////////////
|
|
char feeder1_buffer[80];
|
|
char feeder1_buffer[80];
|
|
Atm_command feeder1;
|
|
Atm_command feeder1;
|
|
@@ -136,6 +140,11 @@ void feederOSC(OSCMessage &msg){
|
|
msg.dispatch("/feeder2/pill_move", [](OSCMessage &msg){Serial2.print("pill_move ");Serial2.print(msg.getInt(0));Serial2.println(" ");Serial.println(msg.getInt(0));});
|
|
msg.dispatch("/feeder2/pill_move", [](OSCMessage &msg){Serial2.print("pill_move ");Serial2.print(msg.getInt(0));Serial2.println(" ");Serial.println(msg.getInt(0));});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void motorsOSC(OSCMessage &msg){
|
|
|
|
+ msg.dispatch("/pill_trap", [](OSCMessage &msg){pill_trap.write(msg.getFloat(0));});
|
|
|
|
+ msg.dispatch("/peristaltic", [](OSCMessage &msg){analogWrite(peristaltic_pwm_pin, msg.getInt(0));});
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
////////////// Setup /////////////////////
|
|
////////////// Setup /////////////////////
|
|
|
|
|
|
@@ -145,7 +154,6 @@ void setup() {
|
|
Ethernet.init(15);//(10)
|
|
Ethernet.init(15);//(10)
|
|
teensyMAC(mac);
|
|
teensyMAC(mac);
|
|
Ethernet.begin(mac); // start the Ethernet and UDP:
|
|
Ethernet.begin(mac); // start the Ethernet and UDP:
|
|
- // Udp.beginMulti(ipMulti, portMulti); // for modified Arduino library
|
|
|
|
Udp.beginMulticast(ipMulti, portMulti); // for modified Teensy Ethernet library
|
|
Udp.beginMulticast(ipMulti, portMulti); // for modified Teensy Ethernet library
|
|
|
|
|
|
// SERIAL
|
|
// SERIAL
|
|
@@ -158,7 +166,6 @@ void setup() {
|
|
|
|
|
|
// STEPPERS
|
|
// STEPPERS
|
|
X_top_step.trace( Serial );
|
|
X_top_step.trace( Serial );
|
|
- // X_top_step.begin(X_top_stepper, X_top_controller, Udp, bndl, "/X_top")
|
|
|
|
X_top_step.begin(X_top_stepper, X_top_controller)
|
|
X_top_step.begin(X_top_stepper, X_top_controller)
|
|
.setEnablePin(18)//.enableReversed(1);//.enable(1);
|
|
.setEnablePin(18)//.enableReversed(1);//.enable(1);
|
|
.setLimitType(3).setLimitPins(A3).limitReversed(false).limitThresholds(600, 750, 950, 1200);
|
|
.setLimitType(3).setLimitPins(A3).limitReversed(false).limitThresholds(600, 750, 950, 1200);
|
|
@@ -169,18 +176,15 @@ void setup() {
|
|
// X_top_step.onOnchangeposition();
|
|
// X_top_step.onOnchangeposition();
|
|
|
|
|
|
Y_top_step.trace( Serial );
|
|
Y_top_step.trace( Serial );
|
|
- Y_top_step.begin(Y_top_stepper, Y_top_controller, Udp, bndl, "/Y_top")
|
|
|
|
|
|
+ Y_top_step.begin(Y_top_stepper, Y_top_controller)
|
|
.setEnablePin(23).enableReversed(1)
|
|
.setEnablePin(23).enableReversed(1)
|
|
//limit pin is on 7 and 8
|
|
//limit pin is on 7 and 8
|
|
.setLimitType(1).setLimitPins(16).limitReversed(true);
|
|
.setLimitType(1).setLimitPins(16).limitReversed(true);
|
|
Y_top_stepper.setMaxSpeed(800);
|
|
Y_top_stepper.setMaxSpeed(800);
|
|
Y_top_stepper.setAcceleration(2500);
|
|
Y_top_stepper.setAcceleration(2500);
|
|
Y_top_stepper.setInverseRotation(false);
|
|
Y_top_stepper.setInverseRotation(false);
|
|
- //stepper.onOnchange(Machine &machine, optional int event = 0)
|
|
|
|
- //stepper.cycle(1000);
|
|
|
|
- // X_top_step.move(-100000).disable();
|
|
|
|
- // Y_top_step.move(1000);
|
|
|
|
- // //delay(2000);
|
|
|
|
|
|
+ Y_top_OSC.begin(Y_top_step, Udp, bndl, "/Y_top");
|
|
|
|
+
|
|
|
|
|
|
// FEEDERS
|
|
// FEEDERS
|
|
Serial1.begin(9600);
|
|
Serial1.begin(9600);
|
|
@@ -195,23 +199,24 @@ void setup() {
|
|
.list( feeder2list )
|
|
.list( feeder2list )
|
|
.onCommand( feeder2_callback );
|
|
.onCommand( feeder2_callback );
|
|
|
|
|
|
- //automaton.delay(5000);
|
|
|
|
- //X_top_step.stop();
|
|
|
|
- //controller.moveAsync(*stepper.motor);
|
|
|
|
- //pinMode(17, INPUT);
|
|
|
|
-
|
|
|
|
- // PERISTALTIC PUMP
|
|
|
|
- //analogWriteResolution(8);
|
|
|
|
- // pinMode(peristaltic_dir_pin, OUTPUT);
|
|
|
|
- // //pinMode(peristaltic_pwm_pin, OUTPUT);
|
|
|
|
- // digitalWrite(peristaltic_dir_pin, LOW); //choose pump direction
|
|
|
|
- // analogWrite(peristaltic_pwm_pin, 50);
|
|
|
|
- // peristaltic.begin(peristaltic_pwm_pin).trigger(peristaltic.EVT_ON);
|
|
|
|
- // peristaltic.start();
|
|
|
|
- // peristaltic.begin( peristaltic_pwm_pin, 0, Udp, bndl, "/peristaltic" );
|
|
|
|
- // //.brightness( 100 );
|
|
|
|
- // peristaltic.blink( 2000 ).start();
|
|
|
|
-
|
|
|
|
|
|
+ // Servo controlling pill trap
|
|
|
|
+ pill_trap.attach(14);
|
|
|
|
+
|
|
|
|
+ // Peristaltic pump
|
|
|
|
+ pinMode(peristaltic_dir_pin, OUTPUT);
|
|
|
|
+ digitalWrite(peristaltic_dir_pin, peristaltic_direction);
|
|
|
|
+ pinMode(peristaltic_pwm_pin, OUTPUT);
|
|
|
|
+ analogWrite(peristaltic_pwm_pin, 50);
|
|
|
|
+ // for(int pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
|
|
|
|
+ // { // in steps of 1 degree
|
|
|
|
+ // pill_trap.write(pos); // tell servo to go to position in variable 'pos'
|
|
|
|
+ // delay(5); // waits 15ms for the servo to reach the position
|
|
|
|
+ // }
|
|
|
|
+ // for(int pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
|
|
|
|
+ // {
|
|
|
|
+ // pill_trap.write(pos); // tell servo to go to position in variable 'pos'
|
|
|
|
+ // delay(5); // waits 15ms for the servo to reach the position
|
|
|
|
+ // }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -235,7 +240,9 @@ void loop() {
|
|
Serial.println("got OSC");
|
|
Serial.println("got OSC");
|
|
// msgIn.route("/blink", test);
|
|
// msgIn.route("/blink", test);
|
|
X_top_OSC.onOSC(msgIn);
|
|
X_top_OSC.onOSC(msgIn);
|
|
|
|
+ Y_top_OSC.onOSC(msgIn);
|
|
feederOSC(msgIn);
|
|
feederOSC(msgIn);
|
|
|
|
+ motorsOSC(msgIn);
|
|
// Y_top_step.onOSC(msgIn);
|
|
// Y_top_step.onOSC(msgIn);
|
|
// peristaltic.onOSC(msgIn);
|
|
// peristaltic.onOSC(msgIn);
|
|
}
|
|
}
|