瀏覽代碼

started basic feeder version
included a controller in the machine stepper class to ease use. Need to
add rotator version and shared controller ?
first state switching version.

eLandon 6 年之前
父節點
當前提交
f6b6675015

+ 10 - 4
HTequi-firmware/src/Atm_lien/Atm_TeensyStep.cpp

@@ -4,7 +4,7 @@
  * Add extra initialization code
  */
 
-Atm_TeensyStep& Atm_TeensyStep::begin(Stepper & motorRef) {
+Atm_TeensyStep& Atm_TeensyStep::begin(Stepper & motorRef, StepControl & stepControlRef) {
   // clang-format off
   const static state_t state_table[] PROGMEM = {
     /*                 ON_ENTER     ON_LOOP       ON_EXIT  EVT_IDLE_TIMER  EVT_ON_TARGET  EVT_GOTO  ELSE */
@@ -17,6 +17,7 @@ Atm_TeensyStep& Atm_TeensyStep::begin(Stepper & motorRef) {
   Machine::begin( state_table, ELSE );
   // AccelStepper _motor (1, stepPin, dirPin);
   this-> motor =   &motorRef;
+  this-> controller = &stepControlRef;
   // Stepper _motor(stepPin, dirPin );
   // StepControl _controller;
   // _motor.setMaxSpeed(20000);
@@ -36,7 +37,8 @@ int Atm_TeensyStep::event( int id ) {
     case EVT_IDLE_TIMER:
       return 0;
     case EVT_ON_TARGET:
-      return 0;
+      //motor->get(targetStep);
+      return _currentStep == _targetStep ;
       // return _motor.distanceToGo()== 0 ;
   }
   return 0;
@@ -59,11 +61,13 @@ void Atm_TeensyStep::action( int id ) {
       return;
     case ENT_RUNNING:
       digitalWrite(0, HIGH);
+
       // _controller.moveAsync(*_motor);
       return;
     case LP_RUNNING:
       // _motor.run();
-
+      _currentStep = motor->getPosition();
+      
      // Serial.println(_motor.currentPosition());
       return;
     case ENT_STOPPING:
@@ -99,7 +103,9 @@ int Atm_TeensyStep::state( void ) {
  */
 
 Atm_TeensyStep& Atm_TeensyStep::gotoStep(long int targetStep ) {
-  motor->setTargetRel(targetStep);
+  _targetStep   = targetStep;
+  motor->setTargetRel(_targetStep);
+  controller->moveAsync(*motor);
 
   // _motor.move(targetStep);
   // _motor.run();

+ 6 - 1
HTequi-firmware/src/Atm_lien/Atm_TeensyStep.h

@@ -9,7 +9,7 @@ class Atm_TeensyStep: public Machine {
   enum { IDLE, READY, RUNNING, STOPPING }; // STATES
   enum { EVT_IDLE_TIMER, EVT_ON_TARGET, EVT_GOTO, ELSE }; // EVENTS
   Atm_TeensyStep( void ) : Machine()  {};
-  Atm_TeensyStep& begin( Stepper & motorRef ) ;
+  Atm_TeensyStep& begin( Stepper & motorRef , StepControl & stepControlRef ) ;
   Atm_TeensyStep& trace( Stream & stream );
   Atm_TeensyStep& trigger( int event );
   int state( void );
@@ -17,17 +17,22 @@ class Atm_TeensyStep: public Machine {
   Atm_TeensyStep& onOnchange( atm_cb_push_t callback, int idx = 0 );
   Atm_TeensyStep& gotoStep( long int targetStep );
   Stepper * motor;
+  StepControl * controller;
 
  private:
   // AccelStepper _motor;
   // Stepper *_motor;       // STEP pin: 2, DIR pin: 3
   // StepControl _controller;
+
   enum { ENT_IDLE, ENT_READY, ENT_RUNNING, LP_RUNNING, ENT_STOPPING, EXT_STOPPING }; // ACTIONS
   enum { ON_ONCHANGE, CONN_MAX }; // CONNECTORS
   atm_connector connectors[CONN_MAX];
   int event( int id );
   void action( int id );
 
+  long int _currentStep ;
+  long int _targetStep ;
+
 };
 
 /*

+ 64 - 0
HTequi-firmware/src/blobcnc_feeder/main.cpp

@@ -0,0 +1,64 @@
+#include <Arduino.h>
+
+#include <Automaton.h>
+#include "Atm_lien/Atm_stepper.h"
+#include "Atm_lien/Atm_TeensyStep.h"
+
+#include <SPI.h>
+#include <Ethernet.h>
+#include <EthernetUdp.h>
+#include <TeensyMAC.h>
+#include <OSCMessage.h>
+
+// 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;
+
+// Atm_stepper stepper;
+Atm_TeensyStep stepper;
+Stepper A_stepper(22, 21);
+StepControl controller ;
+
+void setup() {
+  //Configure and start ethernet module (not needed for feeder)
+  //SPI.setSCK(27);
+ //  Ethernet.init(15);//(10)
+ //  teensyMAC(mac);
+ //  Ethernet.begin(mac, ip);              // 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.begin(115200); // higher Baud rate for faster refresh, CHANGE IN SERIAL MONITOR
+  delay(2000);
+  Serial.println("Started");
+
+  stepper.trace( Serial );
+  stepper.begin(A_stepper, controller);
+  //stepper.cycle(1000);
+  stepper.gotoStep(10000);
+  //controller.moveAsync(*stepper.motor);
+
+}
+
+void loop() {
+  automaton.run();
+
+}