|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
#include <Automaton.h>
|
|
#include <Automaton.h>
|
|
//#include "Atm_lien/Atm_stepper.h"
|
|
//#include "Atm_lien/Atm_stepper.h"
|
|
-#include "Atm_Tstepper.h"
|
|
|
|
|
|
+#include "Atm_Teenstep.h"
|
|
#include "Atm_TeensyStep.h"
|
|
#include "Atm_TeensyStep.h"
|
|
#include <SPI.h>
|
|
#include <SPI.h>
|
|
#include <Ethernet.h>
|
|
#include <Ethernet.h>
|
|
@@ -10,71 +10,74 @@
|
|
#include <TeensyMAC.h>
|
|
#include <TeensyMAC.h>
|
|
#include <OSCMessage.h>
|
|
#include <OSCMessage.h>
|
|
|
|
|
|
-//////////////// Ethernet /////////////////////////////
|
|
|
|
-// Enter a MAC address and IP address for your controller below.
|
|
|
|
-// The IP address will be dependent on your local network:
|
|
|
|
-byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
|
|
|
|
-IPAddress ip(192, 168, 1, 204); //local IP of Arduino/Teensy
|
|
|
|
-//unsigned int localPort = 8888; // local port to listen on (not needed for multicast)
|
|
|
|
-IPAddress ipMulti(239, 200, 200, 200); // ipMidi Multicast address
|
|
|
|
-unsigned int portMulti = 9977; // ipMidi Mutlicast port 1
|
|
|
|
-// buffers for receiving and sending data
|
|
|
|
-byte packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet
|
|
|
|
-byte sendBuffer1[] = {0x90, 0x14, 0x22}; // MIDI Note On to Multicast address
|
|
|
|
-byte sendBuffer2[] = {0x80, 0x14, 0x00}; // MIDI Note Off to Multicast address
|
|
|
|
-// An EthernetUDP instance to let us send and receive packets over UDP
|
|
|
|
-EthernetUDP Udp;
|
|
|
|
-
|
|
|
|
-/////////////////// OSC ////////////////////////
|
|
|
|
-OSCBundle bndl;
|
|
|
|
|
|
+// //////////////// Ethernet /////////////////////////////
|
|
|
|
+// // Enter a MAC address and IP address for your controller below.
|
|
|
|
+// // The IP address will be dependent on your local network:
|
|
|
|
+// byte mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
|
|
|
|
+// IPAddress ip(192, 168, 1, 204); //local IP of Arduino/Teensy
|
|
|
|
+// //unsigned int localPort = 8888; // local port to listen on (not needed for multicast)
|
|
|
|
+// IPAddress ipMulti(239, 200, 200, 200); // ipMidi Multicast address
|
|
|
|
+// unsigned int portMulti = 9977; // ipMidi Mutlicast port 1
|
|
|
|
+// // buffers for receiving and sending data
|
|
|
|
+// byte packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet
|
|
|
|
+// byte sendBuffer1[] = {0x90, 0x14, 0x22}; // MIDI Note On to Multicast address
|
|
|
|
+// byte sendBuffer2[] = {0x80, 0x14, 0x00}; // MIDI Note Off to Multicast address
|
|
|
|
+// // An EthernetUDP instance to let us send and receive packets over UDP
|
|
|
|
+// EthernetUDP Udp;
|
|
|
|
+//
|
|
|
|
+// /////////////////// OSC ////////////////////////
|
|
|
|
+// OSCBundle bndl;
|
|
|
|
|
|
/////////////////// STEPPER machines ////////////////////////
|
|
/////////////////// STEPPER machines ////////////////////////
|
|
/*move are always meant in full steps on the motor output (after reduction)
|
|
/*move are always meant in full steps on the motor output (after reduction)
|
|
so all motors have 200steps per turn */
|
|
so all motors have 200steps per turn */
|
|
-const int BARREL_SPEED = 8000 ;
|
|
|
|
|
|
+const int BARREL_SPEED = 20 ;
|
|
const int BARREL_ACC = 800 ;
|
|
const int BARREL_ACC = 800 ;
|
|
const int BARREL_DISTANCE = 10 ; //in full steps
|
|
const int BARREL_DISTANCE = 10 ; //in full steps
|
|
const int BARREL_REDUCTION_RATIO = 26.85;
|
|
const int BARREL_REDUCTION_RATIO = 26.85;
|
|
const int BARREL_MICROSTEP = 32;
|
|
const int BARREL_MICROSTEP = 32;
|
|
|
|
|
|
-static uint16_t BARREL_THRESHOLD[] = {5} ; //for sensor to trig
|
|
|
|
|
|
+static uint16_t BARREL_THRESHOLD[] = {880} ; //for sensor to trig
|
|
const int BARREL_INIBSENSOR = 5000;
|
|
const int BARREL_INIBSENSOR = 5000;
|
|
|
|
|
|
-const int PILL_SPEED = 10 ;
|
|
|
|
|
|
+const int PILL_SPEED = 20 ;
|
|
const int PILL_ACC = 1000 ;
|
|
const int PILL_ACC = 1000 ;
|
|
const int PILL_DISTANCE = 200 ; //in full steps
|
|
const int PILL_DISTANCE = 200 ; //in full steps
|
|
const int PILL_MICROSTEP = 32;
|
|
const int PILL_MICROSTEP = 32;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-Atm_TeensyStep barrel_step;
|
|
|
|
|
|
+Atm_Teenstep barrel_step;
|
|
Stepper barrel_stepper(3, 2);
|
|
Stepper barrel_stepper(3, 2);
|
|
StepControl barrel_controller ;
|
|
StepControl barrel_controller ;
|
|
|
|
|
|
-Atm_comparator barrel_sensor;
|
|
|
|
|
|
+Atm_analog barrel_sensor;
|
|
|
|
|
|
-Atm_TeensyStep pill_step;
|
|
|
|
|
|
+
|
|
|
|
+Atm_Teenstep pill_step;
|
|
Stepper pill_stepper(6, 5);
|
|
Stepper pill_stepper(6, 5);
|
|
StepControl pill_controller ;
|
|
StepControl pill_controller ;
|
|
|
|
|
|
-Atm_comparator pill_sensor ;
|
|
|
|
-
|
|
|
|
|
|
+Atm_analog pill_sensor ;
|
|
|
|
+uint16_t avgbuffer[16];
|
|
|
|
|
|
void barrel_homing(){
|
|
void barrel_homing(){
|
|
|
|
+ barrel_step.move(5*BARREL_MICROSTEP*BARREL_REDUCTION_RATIO);
|
|
|
|
+ //automaton.delay(BARREL_INIBSENSOR); //let the current position go
|
|
|
|
+ automaton.delay(BARREL_INIBSENSOR);
|
|
barrel_step.move(BARREL_DISTANCE*BARREL_MICROSTEP*BARREL_REDUCTION_RATIO);
|
|
barrel_step.move(BARREL_DISTANCE*BARREL_MICROSTEP*BARREL_REDUCTION_RATIO);
|
|
- automaton.delay(BARREL_INIBSENSOR); //let the current position go
|
|
|
|
bool foundHome = false ;
|
|
bool foundHome = false ;
|
|
- while(barrel_step.state() != barrel_step.STOPPING){
|
|
|
|
|
|
+ while(barrel_step.state() != barrel_step.ENABLED){
|
|
// automaton.run();
|
|
// automaton.run();
|
|
- barrel_step.cycle();
|
|
|
|
|
|
+ automaton.run();
|
|
|
|
+ Serial.println(barrel_sensor.state());
|
|
if(barrel_sensor.state()<BARREL_THRESHOLD[0]){
|
|
if(barrel_sensor.state()<BARREL_THRESHOLD[0]){
|
|
- barrel_step.emergencyStop();
|
|
|
|
|
|
+ barrel_step.emergencystop();
|
|
barrel_stepper.setPosition(0);
|
|
barrel_stepper.setPosition(0);
|
|
foundHome = true ;
|
|
foundHome = true ;
|
|
break ;
|
|
break ;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- digitalWrite( 13, LOW );
|
|
|
|
if (!foundHome){Serial.println("homing 0");}
|
|
if (!foundHome){Serial.println("homing 0");}
|
|
else{Serial.println("homing 1");}
|
|
else{Serial.println("homing 1");}
|
|
|
|
|
|
@@ -82,23 +85,25 @@ void barrel_homing(){
|
|
|
|
|
|
|
|
|
|
void barrel_move(int stepRel){
|
|
void barrel_move(int stepRel){
|
|
- Serial.println(stepRel);
|
|
|
|
- barrel_step.move(stepRel);
|
|
|
|
|
|
+ Serial.println(stepRel*BARREL_MICROSTEP*BARREL_REDUCTION_RATIO);
|
|
|
|
+ barrel_step.move(stepRel*BARREL_MICROSTEP*BARREL_REDUCTION_RATIO);
|
|
}
|
|
}
|
|
|
|
|
|
void pill_move(int stepRel){
|
|
void pill_move(int stepRel){
|
|
- Serial.println(stepRel);
|
|
|
|
- pill_step.move(stepRel);
|
|
|
|
|
|
+ Serial.println(stepRel* PILL_MICROSTEP);
|
|
|
|
+ pill_step.move(stepRel* PILL_MICROSTEP);
|
|
}
|
|
}
|
|
|
|
|
|
void pill_next(){
|
|
void pill_next(){
|
|
- pill_move(200 * PILL_MICROSTEP);
|
|
|
|
|
|
+ pill_step.move(PILL_DISTANCE * PILL_MICROSTEP);
|
|
|
|
|
|
//make one turn, if nothing was seen by sensor try again up to 5 times
|
|
//make one turn, if nothing was seen by sensor try again up to 5 times
|
|
bool foundPill = false ;
|
|
bool foundPill = false ;
|
|
- while(pill_step.state() != barrel_step.STOPPING){
|
|
|
|
|
|
+ while(pill_step.state() != pill_step.ENABLED){
|
|
|
|
+ int value = pill_sensor.state();
|
|
automaton.run();
|
|
automaton.run();
|
|
- if(pill_sensor.state()<BARREL_THRESHOLD[0]){foundPill = true ;}
|
|
|
|
|
|
+ Serial.println(value);
|
|
|
|
+ if(value<650){foundPill = true ;break;}
|
|
}
|
|
}
|
|
if (!foundPill){Serial.println("pill 0");}
|
|
if (!foundPill){Serial.println("pill 0");}
|
|
else{Serial.println("pill 1");}
|
|
else{Serial.println("pill 1");}
|
|
@@ -175,23 +180,23 @@ void setup() {
|
|
// pinMode(4, OUTPUT);
|
|
// pinMode(4, OUTPUT);
|
|
// pinMode(4, LOW);
|
|
// pinMode(4, LOW);
|
|
barrel_step.trace( Serial );
|
|
barrel_step.trace( Serial );
|
|
- barrel_step.begin(barrel_stepper, barrel_controller, Udp, bndl, "/Y_top")
|
|
|
|
|
|
+ barrel_step.begin(barrel_stepper, barrel_controller)
|
|
.setEnablePin(4).enableReversed(1);
|
|
.setEnablePin(4).enableReversed(1);
|
|
//.setLimitType(3).setLimitPins(A3).limitThresholds(800, 1000, 0, 100).homing(1);
|
|
//.setLimitType(3).setLimitPins(A3).limitThresholds(800, 1000, 0, 100).homing(1);
|
|
- barrel_stepper.setMaxSpeed(BARREL_SPEED);
|
|
|
|
- barrel_stepper.setAcceleration(BARREL_ACC);
|
|
|
|
|
|
+ barrel_stepper.setMaxSpeed(BARREL_SPEED*BARREL_MICROSTEP);
|
|
|
|
+ barrel_stepper.setAcceleration(BARREL_ACC*BARREL_MICROSTEP);
|
|
barrel_stepper.setInverseRotation(true);
|
|
barrel_stepper.setInverseRotation(true);
|
|
- barrel_sensor.begin(A3, 50).threshold(BARREL_THRESHOLD, 1)
|
|
|
|
- .onChange( []( int idx, int v, int up ){Serial.println(up);} )
|
|
|
|
- .onChange( true, []( int idx, int v, int up ){Serial.println(up);} )
|
|
|
|
- .onChange( false, []( int idx, int v, int up ){Serial.println(up);} );
|
|
|
|
|
|
+ barrel_sensor.begin(A3, 50);//.threshold(BARREL_THRESHOLD, 1)
|
|
|
|
+ // .onChange( []( int idx, int v, int up ){Serial.println(up);} )
|
|
|
|
+ // .onChange( true, []( int idx, int v, int up ){Serial.println(up);} )
|
|
|
|
+ // .onChange( false, []( int idx, int v, int up ){Serial.println(up);} );
|
|
|
|
|
|
pill_step.trace( Serial );
|
|
pill_step.trace( Serial );
|
|
- pill_step.begin(pill_stepper, pill_controller, Udp, bndl, "/Y_top")
|
|
|
|
|
|
+ pill_step.begin(pill_stepper, pill_controller)
|
|
.setEnablePin(7).enableReversed(1);
|
|
.setEnablePin(7).enableReversed(1);
|
|
- pill_stepper.setMaxSpeed(PILL_SPEED);
|
|
|
|
- pill_stepper.setAcceleration(PILL_ACC);
|
|
|
|
- pill_sensor.begin(A1, 50);
|
|
|
|
|
|
+ pill_stepper.setMaxSpeed(PILL_SPEED*PILL_MICROSTEP);
|
|
|
|
+ pill_stepper.setAcceleration(PILL_ACC*PILL_MICROSTEP);
|
|
|
|
+ pill_sensor.begin(A1, 50).average( avgbuffer, sizeof( avgbuffer ) );
|
|
//stepper.onOnchange(Machine &machine, optional int event = 0)
|
|
//stepper.onOnchange(Machine &machine, optional int event = 0)
|
|
//stepper.cycle(1000);
|
|
//stepper.cycle(1000);
|
|
//barrel_step.move(10000);
|
|
//barrel_step.move(10000);
|