|
@@ -1,14 +1,19 @@
|
|
|
|
+
|
|
#include <Arduino.h>
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
+
|
|
#include <Automaton.h>
|
|
#include <Automaton.h>
|
|
-#include "Atm_lien/Atm_stepper.h"
|
|
+#include "Atm_Teenstep.h"
|
|
-#include "Atm_lien/Atm_TeensyStep.h"
|
|
+#include "Atm_Teenstep_OSC.h"
|
|
|
|
|
|
|
|
+
|
|
#include <SPI.h>
|
|
#include <SPI.h>
|
|
#include <Ethernet.h>
|
|
#include <Ethernet.h>
|
|
#include <EthernetUdp.h>
|
|
#include <EthernetUdp.h>
|
|
#include <TeensyMAC.h>
|
|
#include <TeensyMAC.h>
|
|
-#include <OSCMessage.h>
|
|
+#include <OSCBundle.h>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
byte mac[] = {
|
|
byte mac[] = {
|
|
@@ -30,170 +35,144 @@ byte sendBuffer2[] = {0x80, 0x14, 0x00};
|
|
|
|
|
|
EthernetUDP Udp;
|
|
EthernetUDP Udp;
|
|
|
|
|
|
-
|
|
|
|
-Atm_TeensyStep stepper;
|
|
|
|
-Stepper A_stepper(2, 1);
|
|
|
|
-StepControl controller ;
|
|
|
|
-
|
|
|
|
-class Atm_blink : public Machine {
|
|
|
|
-
|
|
|
|
- public:
|
|
|
|
- Atm_blink( void ) : Machine() {};
|
|
|
|
- short pin;
|
|
|
|
- atm_timer_millis timer;
|
|
|
|
- OSCMessage _msg ;
|
|
|
|
- EthernetUDP* _udpRef ;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- enum { IDLE, LED_ON, LED_OFF };
|
|
|
|
- enum { EVT_TIMER, EVT_ON, EVT_OFF, ELSE };
|
|
|
|
- enum { ENT_ON, ENT_OFF };
|
|
|
|
-
|
|
|
|
- Atm_blink & begin( int attached_pin, uint32_t blinkrate, EthernetUDP& udpRef ) {
|
|
|
|
- const static state_t state_table[] PROGMEM = {
|
|
|
|
-
|
|
|
|
- ENT_OFF, -1, -1, -1, LED_ON, -1, -1,
|
|
|
|
- ENT_ON, -1, -1, LED_OFF, -1, IDLE, -1,
|
|
|
|
- ENT_OFF, -1, -1, LED_ON, -1, IDLE, -1,
|
|
|
|
- };
|
|
|
|
- Machine::begin( state_table, ELSE );
|
|
|
|
- pin = attached_pin;
|
|
|
|
- timer.set( blinkrate );
|
|
|
|
- pinMode( pin, OUTPUT );
|
|
|
|
- this->_udpRef = &udpRef;
|
|
|
|
-
|
|
|
|
- return *this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- int event( int id ) {
|
|
|
|
- switch ( id ) {
|
|
|
|
- case EVT_TIMER :
|
|
|
|
- return timer.expired( this );
|
|
|
|
|
|
|
|
- }
|
|
+
|
|
- }
|
|
+const int HIGH_SPEED = 800 ;
|
|
|
|
+const int HIGH_ACC = 800 ;
|
|
|
|
+const int LOW_SPEED = 100 ;
|
|
|
|
+const int LOW_ACC = 1000 ;
|
|
|
|
|
|
- void action( int id ) {
|
|
+Atm_Teenstep_OSC A_low_OSC;
|
|
|
|
+Atm_Teenstep A_low_step;
|
|
|
|
+Stepper A_low_stepper(8 , 7);
|
|
|
|
+StepControl A_low_controller ;
|
|
|
|
|
|
- switch ( id ) {
|
|
+Atm_Teenstep_OSC B_low_OSC;
|
|
- case ENT_ON :
|
|
+Atm_Teenstep B_low_step;
|
|
- digitalWrite( pin, HIGH );
|
|
+Stepper B_low_stepper(32 , 31);
|
|
|
|
+StepControl B_low_controller ;
|
|
|
|
|
|
|
|
+Atm_Teenstep_OSC TrBr_low_OSC;
|
|
|
|
+Atm_Teenstep TrBr_low_step;
|
|
|
|
+Stepper TrBr_low_stepper(2 , 1);
|
|
|
|
+StepControl TrBr_low_controller ;
|
|
|
|
|
|
- return;
|
|
+Atm_Teenstep_OSC LevBr_low_OSC;
|
|
|
|
+Atm_Teenstep LevBr_low_step;
|
|
|
|
+Stepper LevBr_low_stepper(5 , 4);
|
|
|
|
+StepControl LevBr_low_controller ;
|
|
|
|
|
|
- case ENT_OFF :
|
|
|
|
- digitalWrite( pin, LOW );
|
|
|
|
|
|
|
|
- return;
|
|
+
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Atm_blink& trigger( int event ) {
|
|
|
|
- Machine::trigger( event );
|
|
|
|
- return *this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- * Control what the machine returns when another process requests its state
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Atm_blink& onOSC(OSCMessage& msg ){
|
|
|
|
- Serial.println("OSC");
|
|
|
|
- if(msg.fullMatch("/blink")){
|
|
|
|
- Serial.println("ouais gros");
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- return *this;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
+const int peristaltic_pwm_pin = 3;
|
|
|
|
+const int peristaltic_dir_pin = 2;
|
|
|
|
+bool peristaltic_direction = 0 ;
|
|
|
|
|
|
-};
|
|
+Servo pill_trap ;
|
|
|
|
|
|
-Atm_blink led;
|
|
+void motorsOSC(OSCMessage &msg){
|
|
-
|
|
+ msg.dispatch("/pill_trap", [](OSCMessage &msg){pill_trap.write(msg.getFloat(0));});
|
|
-void test(OSCMessage &msg, int addrOffset){
|
|
+ msg.dispatch("/peristaltic", [](OSCMessage &msg){analogWrite(peristaltic_pwm_pin, msg.getInt(0));});
|
|
- Serial.println("test");
|
|
|
|
-msg.getInt(0)?led.trigger( led.EVT_ON ):led.trigger( led.EVT_OFF );
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
void setup() {
|
|
void setup() {
|
|
-
|
|
+ SPI.setSCK(27);
|
|
- Ethernet.init(15);
|
|
+ Ethernet.init(10);
|
|
teensyMAC(mac);
|
|
teensyMAC(mac);
|
|
Ethernet.begin(mac, ip);
|
|
Ethernet.begin(mac, ip);
|
|
-
|
|
|
|
Udp.beginMulticast(ipMulti, portMulti);
|
|
Udp.beginMulticast(ipMulti, portMulti);
|
|
|
|
+
|
|
|
|
+
|
|
Serial.begin(115200);
|
|
Serial.begin(115200);
|
|
|
|
+ delay(2000);
|
|
|
|
+ Serial.println("Started Low");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ A_low_step.trace( Serial );
|
|
|
|
+ A_low_step.begin(A_low_stepper, A_low_controller)
|
|
|
|
+ .setEnablePin(6)
|
|
|
|
+ .setLimitType(3).setLimitPins(A16).limitReversed(false).limitThresholds(600, 750, 950, 1200);
|
|
|
|
+ A_low_stepper.setMaxSpeed(HIGH_SPEED);
|
|
|
|
+ A_low_stepper.setAcceleration(HIGH_ACC);
|
|
|
|
+ A_low_stepper.setInverseRotation(true);
|
|
|
|
+ A_low_OSC.begin(A_low_step, Udp, bndl, "/A_low");
|
|
|
|
+ A_low_step.onChangeposition([](int idx, int v, int up){bndl.add("/A_low_OSC/step").add(v);});
|
|
|
|
+ A_low_step.onChange([](int idx, int v, int up){bndl.add("/A_low_OSC/state").add(v);});
|
|
|
|
+ A_low_step.onLimitlow([](int idx, int v, int up){bndl.add("/A_low_OSC/limitLow").add(v);});
|
|
|
|
+ A_low_step.onLimithigh([](int idx, int v, int up){bndl.add("/A_low_OSC/limitHigh").add(v);});
|
|
|
|
+
|
|
|
|
+ B_low_step.trace( Serial );
|
|
|
|
+ B_low_step.begin(B_low_stepper, B_low_controller)
|
|
|
|
+ .setEnablePin(30)
|
|
|
|
+ .setLimitType(3).setLimitPins(A14).limitReversed(false).limitThresholds(600, 750, 950, 1200);
|
|
|
|
+ B_low_stepper.setMaxSpeed(HIGH_SPEED);
|
|
|
|
+ B_low_stepper.setAcceleration(HIGH_ACC);
|
|
|
|
+ B_low_stepper.setInverseRotation(true);
|
|
|
|
+ B_low_OSC.begin(B_low_step, Udp, bndl, "/B_low");
|
|
|
|
+ B_low_step.onChangeposition([](int idx, int v, int up){bndl.add("/B_low_OSC/step").add(v);});
|
|
|
|
+ B_low_step.onChange([](int idx, int v, int up){bndl.add("/B_low_OSC/state").add(v);});
|
|
|
|
+ B_low_step.onLimitlow([](int idx, int v, int up){bndl.add("/B_low_OSC/limitLow").add(v);});
|
|
|
|
+ B_low_step.onLimithigh([](int idx, int v, int up){bndl.add("/B_low_OSC/limitHigh").add(v);});
|
|
|
|
+
|
|
|
|
+ TrBr_low_step.trace( Serial );
|
|
|
|
+ TrBr_low_step.begin(TrBr_low_stepper, TrBr_low_controller)
|
|
|
|
+ .setEnablePin(0)
|
|
|
|
+ .setLimitType(2).setLimitPins(17, 15).limitReversed(false).limitThresholds(600, 750, 950, 1200);
|
|
|
|
+ TrBr_low_stepper.setMaxSpeed(HIGH_SPEED);
|
|
|
|
+ TrBr_low_stepper.setAcceleration(HIGH_ACC);
|
|
|
|
+ TrBr_low_stepper.setInverseRotation(true);
|
|
|
|
+ TrBr_low_OSC.begin(TrBr_low_step, Udp, bndl, "/TrBr_low");
|
|
|
|
+ TrBr_low_step.onChangeposition([](int idx, int v, int up){bndl.add("/TrBr_low_OSC/step").add(v);});
|
|
|
|
+ TrBr_low_step.onChange([](int idx, int v, int up){bndl.add("/TrBr_low_OSC/state").add(v);});
|
|
|
|
+ TrBr_low_step.onLimitlow([](int idx, int v, int up){bndl.add("/TrBr_low_OSC/limitLow").add(v);});
|
|
|
|
+ TrBr_low_step.onLimithigh([](int idx, int v, int up){bndl.add("/TrBr_low_OSC/limitHigh").add(v);});
|
|
|
|
+
|
|
|
|
+ LevBr_low_step.trace( Serial );
|
|
|
|
+ LevBr_low_step.begin(LevBr_low_stepper, LevBr_low_controller)
|
|
|
|
+ .setEnablePin(3)
|
|
|
|
+ .setLimitType(2).setLimitPins(39, 37).limitReversed(false).limitThresholds(600, 750, 950, 1200);
|
|
|
|
+ LevBr_low_stepper.setMaxSpeed(HIGH_SPEED);
|
|
|
|
+ LevBr_low_stepper.setAcceleration(HIGH_ACC);
|
|
|
|
+ LevBr_low_stepper.setInverseRotation(true);
|
|
|
|
+ LevBr_low_OSC.begin(LevBr_low_step, Udp, bndl, "/LevBr_low");
|
|
|
|
+ LevBr_low_step.onChangeposition([](int idx, int v, int up){bndl.add("/LevBr_low_OSC/step").add(v);});
|
|
|
|
+ LevBr_low_step.onChange([](int idx, int v, int up){bndl.add("/LevBr_low_OSC/state").add(v);});
|
|
|
|
+ LevBr_low_step.onLimitlow([](int idx, int v, int up){bndl.add("/LevBr_low_OSC/limitLow").add(v);});
|
|
|
|
+ LevBr_low_step.onLimithigh([](int idx, int v, int up){bndl.add("/LevBr_low_OSC/limitHigh").add(v);});
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ pinMode(peristaltic_dir_pin, OUTPUT);
|
|
|
|
+ digitalWrite(peristaltic_dir_pin, peristaltic_direction);
|
|
|
|
+ pinMode(peristaltic_pwm_pin, OUTPUT);
|
|
|
|
+ analogWrite(peristaltic_pwm_pin, 50);
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- delay(1000);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void loop() {
|
|
void loop() {
|
|
-
|
|
+ automaton.run();
|
|
-
|
|
+ Udp.beginPacket(ipMulti, portMulti);
|
|
-
|
|
+ bndl.send(Udp);
|
|
- Serial.println("msgIn");
|
|
+ Udp.endPacket();
|
|
-
|
|
+ bndl.empty();
|
|
-
|
|
+
|
|
-
|
|
+ OSCMessage msgIn;
|
|
-
|
|
+ int size;
|
|
-
|
|
+ if( (size = Udp.parsePacket())>0)
|
|
-
|
|
+ {
|
|
-
|
|
+ while(size--)
|
|
-
|
|
+ msgIn.fill(Udp.read());
|
|
-
|
|
+
|
|
-
|
|
+ if(!msgIn.hasError()){
|
|
-
|
|
+ Serial.println("got OSC");
|
|
-
|
|
+
|
|
-
|
|
+ A_low_OSC.onOSC(msgIn);
|
|
- OSCMessage msg("/analog/0");
|
|
+ B_low_OSC.onOSC(msgIn);
|
|
- msg.add((int32_t)analogRead(0));
|
|
+ feederOSC(msgIn);
|
|
-
|
|
+ motorsOSC(msgIn);
|
|
- Udp.beginPacket(ipMulti, portMulti);
|
|
+
|
|
- msg.send(Udp);
|
|
+
|
|
- Udp.endPacket();
|
|
+ }
|
|
- msg.empty();
|
|
+ }
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- delay(100);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|