|
@@ -5,22 +5,27 @@
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
+//Automaton and custom machines
|
|
|
#include <Automaton.h>
|
|
|
-#include "Atm_lien/Atm_stepper.h"
|
|
|
+// #include "Atm_lien/Atm_stepper.h"
|
|
|
#include "Atm_lien/Atm_TeensyStep.h"
|
|
|
|
|
|
+//osc
|
|
|
+
|
|
|
+
|
|
|
#include <SPI.h>
|
|
|
#include <Ethernet.h>
|
|
|
#include <EthernetUdp.h>
|
|
|
#include <TeensyMAC.h>
|
|
|
-#include <OSCMessage.h>
|
|
|
+#include <OSCBundle.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 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
|
|
@@ -30,6 +35,8 @@ byte sendBuffer2[] = {0x80, 0x14, 0x00}; // MIDI Note Off to Multicast ad
|
|
|
// An EthernetUDP instance to let us send and receive packets over UDP
|
|
|
EthernetUDP Udp;
|
|
|
|
|
|
+/////////////////// OSC ////////////////////////
|
|
|
+OSCBundle bndl;
|
|
|
|
|
|
/////////////////// STEPPER machines ////////////////////////
|
|
|
const int HIGH_SPEED = 800 ;
|
|
@@ -41,50 +48,98 @@ Atm_TeensyStep X_top_step;
|
|
|
Stepper X_top_stepper(20 , 19);
|
|
|
StepControl X_top_controller ;
|
|
|
|
|
|
+Atm_TeensyStep Y_top_step;
|
|
|
+Stepper Y_top_stepper(22 , 21);
|
|
|
+StepControl Y_top_controller ;
|
|
|
|
|
|
////////////// Setup /////////////////////
|
|
|
|
|
|
void setup() {
|
|
|
- //Configure and start ethernet module (not needed for feeder)
|
|
|
+ // ETHERNET (not needed for feeder)
|
|
|
//SPI.setSCK(27); //only bottom
|
|
|
Ethernet.init(15);//(10)
|
|
|
teensyMAC(mac);
|
|
|
- Ethernet.begin(mac, ip); // 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
|
|
|
|
|
|
- //Start serial
|
|
|
+ // SERIAL
|
|
|
Serial.begin(115200); // higher Baud rate for faster refresh, CHANGE IN SERIAL MONITOR
|
|
|
delay(2000);
|
|
|
Serial.println("Started");
|
|
|
- pinMode(13, OUTPUT);
|
|
|
|
|
|
- // pinMode(18, OUTPUT);
|
|
|
- // digitalWrite(18, LOW);
|
|
|
+ // LED
|
|
|
+
|
|
|
+
|
|
|
+ // STEPPERS
|
|
|
X_top_step.trace( Serial );
|
|
|
- X_top_step.begin(X_top_stepper, X_top_controller)
|
|
|
- .setEnablePin(18).enable(1)
|
|
|
- .setLimitType(1).setLimitPins(A3).limitReversed(true).limitThresholds(600, 800, 900, 1200);
|
|
|
+ X_top_step.begin(X_top_stepper, X_top_controller, Udp, bndl, "/X_top")
|
|
|
+ .setEnablePin(18).enable(1);
|
|
|
+ //.setLimitType(3).setLimitPins(A3).limitReversed(true).limitThresholds(600, 750, 950, 1200);
|
|
|
X_top_stepper.setMaxSpeed(HIGH_SPEED);
|
|
|
X_top_stepper.setAcceleration(HIGH_ACC);
|
|
|
X_top_stepper.setInverseRotation(true);
|
|
|
|
|
|
+ Y_top_step.trace( Serial );
|
|
|
+ Y_top_step.begin(Y_top_stepper, Y_top_controller, Udp, bndl, "/Y_top")
|
|
|
+ .setEnablePin(23).enableReversed(1)
|
|
|
+ //limit pin is on 7 and 8
|
|
|
+ .setLimitType(1).setLimitPins(16).limitReversed(true);
|
|
|
+ Y_top_stepper.setMaxSpeed(800);
|
|
|
+ Y_top_stepper.setAcceleration(2500);
|
|
|
+ Y_top_stepper.setInverseRotation(false);
|
|
|
//stepper.onOnchange(Machine &machine, optional int event = 0)
|
|
|
//stepper.cycle(1000);
|
|
|
- X_top_step.move(100000);
|
|
|
+ X_top_step.move(-10000);
|
|
|
+ Y_top_step.move(10000);
|
|
|
//controller.moveAsync(*stepper.motor);
|
|
|
//pinMode(17, INPUT);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
+
|
|
|
automaton.run();
|
|
|
+ Udp.beginPacket(ipMulti, portMulti);
|
|
|
+ bndl.send(Udp); // send the bytes to the SLIP stream
|
|
|
+ Udp.endPacket(); // mark the end of the OSC Packet
|
|
|
+ bndl.empty(); // empty the bundle to free room for a new one
|
|
|
+
|
|
|
+ OSCMessage msgIn;
|
|
|
+ int size;
|
|
|
+ if( (size = Udp.parsePacket())>0)
|
|
|
+ {
|
|
|
+ while(size--)
|
|
|
+ msgIn.fill(Udp.read());
|
|
|
+
|
|
|
+ if(!msgIn.hasError()){
|
|
|
+ Serial.println("got OSC");
|
|
|
+ // msgIn.route("/blink", test);
|
|
|
+ X_top_step.onOSC(msgIn);
|
|
|
+ Y_top_step.onOSC(msgIn);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Serial.print(analogRead(A3));
|
|
|
Serial.print(" ");
|
|
|
- Serial.print(X_top_step.limitState[0]);
|
|
|
+ Serial.print(Y_top_step.limitState[0]);
|
|
|
Serial.print(" ");
|
|
|
Serial.println(X_top_step.limitState[1]);
|
|
|
- delay(10);
|
|
|
+
|
|
|
+ // OSCMessage msg("/analog/0");
|
|
|
+ // msg.add((int32_t)analogRead(0));
|
|
|
+ //
|
|
|
+ // Udp.beginPacket(ipMulti, portMulti);
|
|
|
+ // msg.send(Udp); // send the bytes to the SLIP stream
|
|
|
+ // Udp.endPacket(); // mark the end of the OSC Packet
|
|
|
+ // msg.empty(); // free space occupied by message
|
|
|
+
|
|
|
+ delay(1);
|
|
|
|
|
|
}
|