浏览代码

lots of mods of the day
just before rewritting part of feeder management

eLandon 5 年之前
父节点
当前提交
05f350c7bc

+ 456 - 0
3Dprints/DCMotor.dxf

@@ -0,0 +1,456 @@
+  0
+SECTION
+  2
+HEADER
+  9
+$ACADVER
+  1
+AC1009
+  9
+$INSBASE
+ 10
+0.0
+ 20
+0.0
+ 30
+0.0
+  9
+$EXTMIN
+ 10
+0.0
+ 20
+0.0
+ 30
+0.0
+  9
+$EXTMAX
+ 10
+0.0
+ 20
+0.0
+ 30
+0.0
+  0
+ENDSEC
+  0
+SECTION
+  2
+TABLES
+  0
+TABLE
+  2
+VPORT
+ 70
+0
+  0
+ENDTAB
+  0
+TABLE
+  2
+LTYPE
+ 70
+1
+  0
+LTYPE
+  2
+CONTINUOUS
+ 70
+0
+  3
+Solid line
+ 72
+65
+ 73
+0
+ 40
+0.0
+  0
+ENDTAB
+  0
+TABLE
+  2
+LAYER
+ 70
+1
+  0
+LAYER
+  2
+0
+ 70
+64
+ 62
+7
+  6
+continuous
+  0
+ENDTAB
+  0
+TABLE
+  2
+STYLE
+ 70
+1
+  0
+STYLE
+  2
+STANDARD
+ 70
+0
+ 40
+0
+ 41
+1.0
+ 50
+0.0
+ 71
+0
+ 42
+1
+ 3
+ARIAL.TTF
+ 4
+
+  0
+ENDTAB
+  0
+TABLE
+  2
+VIEW
+ 70
+0
+  0
+ENDTAB
+  0
+ENDSEC
+  0
+SECTION
+  2
+BLOCKS
+  0
+BLOCK
+  8
+0
+  2
+SHAPE2DVIEW
+ 70
+0
+ 10
+0.0
+ 20
+0.0
+ 30
+0.0
+  3
+SHAPE2DVIEW
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+-40.0
+ 20
+23.0
+ 30
+0.0
+ 11
+40.0
+ 21
+23.0
+ 31
+0.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+-40.0
+ 20
+-23.0
+ 30
+0.0
+ 11
+-40.0
+ 21
+23.0
+ 31
+0.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+40.0
+ 20
+23.0
+ 30
+0.0
+ 11
+40.0
+ 21
+-23.0
+ 31
+0.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+40.0
+ 20
+-23.0
+ 30
+0.0
+ 11
+-40.0
+ 21
+-23.0
+ 31
+0.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+-6.776054
+ 20
+16.0
+ 30
+0.0
+ 11
+-1.776054
+ 21
+16.0
+ 31
+0.0
+  0
+ARC
+  8
+0
+ 62
+0
+ 10
+-1.776054
+ 20
+11.5
+ 30
+0.0
+ 40
+4.5
+ 50
+-90.0
+ 51
+90.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+-6.776054
+ 20
+7.0
+ 30
+0.0
+ 11
+-1.776054
+ 21
+7.0
+ 31
+0.0
+  0
+ARC
+  8
+0
+ 62
+0
+ 10
+-6.776054
+ 20
+11.5
+ 30
+0.0
+ 40
+4.5
+ 50
+90.0
+ 51
+-90.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+-31.776054
+ 20
+16.0
+ 30
+0.0
+ 11
+-26.776054
+ 21
+16.0
+ 31
+0.0
+  0
+ARC
+  8
+0
+ 62
+0
+ 10
+-26.776054
+ 20
+11.5
+ 30
+0.0
+ 40
+4.5
+ 50
+-90.0
+ 51
+90.0
+  0
+LINE
+  8
+0
+ 62
+0
+ 10
+-31.776054
+ 20
+7.0
+ 30
+0.0
+ 11
+-26.776054
+ 21
+7.0
+ 31
+0.0
+  0
+ARC
+  8
+0
+ 62
+0
+ 10
+-31.776054
+ 20
+11.5
+ 30
+0.0
+ 40
+4.5
+ 50
+90.0
+ 51
+-90.0
+  0
+CIRCLE
+  8
+0
+ 62
+0
+ 10
+14.223946
+ 20
+-16.5
+ 30
+0.0
+ 40
+1.75
+  0
+CIRCLE
+  8
+0
+ 62
+0
+ 10
+14.223946
+ 20
+16.5
+ 30
+0.0
+ 40
+1.75
+  0
+CIRCLE
+  8
+0
+ 62
+0
+ 10
+32.223946
+ 20
+-16.5
+ 30
+0.0
+ 40
+1.75
+  0
+CIRCLE
+  8
+0
+ 62
+0
+ 10
+23.223946
+ 20
+7.5
+ 30
+0.0
+ 40
+4.0
+  0
+CIRCLE
+  8
+0
+ 62
+0
+ 10
+32.223946
+ 20
+16.5
+ 30
+0.0
+ 40
+1.75
+  0
+ENDBLK
+  0
+ENDSEC
+  0
+SECTION
+  2
+ENTITIES
+  0
+INSERT
+  2
+SHAPE2DVIEW
+  8
+0
+ 62
+0
+ 10
+0.0
+ 20
+0.0
+ 30
+0.0
+  0
+ENDSEC
+  0
+EOF

二进制
3Dprints/DCMotorHolder.fcstd


二进制
3Dprints/DCMotorHolder.stl


+ 24 - 0
3Dprints/DCMotorHolder.svg

@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg width="81.6mm" height="47.6mm" viewBox="0 0 81.6 47.6" xmlns="http://www.w3.org/2000/svg" version="1.1">
+<g id="Shape2DView" transform="translate(40.800000,23.800000) scale(1,-1)">
+<path id="Shape2DView_nwe0000"  d="M -40.0 23.0 L 40.0 23.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0001"  d="M -40.0 -23.0 L -40.0 23.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0002"  d="M 40.0 23.0 L 40.0 -23.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0003"  d="M 40.0 -23.0 L -40.0 -23.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0004"  d="M -6.776054 16.0 L -1.776054 16.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0005"  d="M -1.776054 7.0 A 4.5 4.5 0 0 1 -1.77605 16" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0006"  d="M -6.776054 7.0 L -1.776054 7.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0007"  d="M -6.776054 16.0 A 4.5 4.5 0 0 1 -6.77605 7" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0008"  d="M -31.776054 16.0 L -26.776054 16.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0009"  d="M -26.776054 7.0 A 4.5 4.5 0 0 1 -26.7761 16" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0010"  d="M -31.776054 7.0 L -26.776054 7.0 " stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<path id="Shape2DView_nwe0011"  d="M -31.776054 16.0 A 4.5 4.5 0 0 1 -31.7761 7" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none;fill-rule: evenodd "/>
+<circle cx="14.223946" cy="-16.5" r="1.75" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none"/>
+<circle cx="14.223946" cy="16.5" r="1.75" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none"/>
+<circle cx="32.223946" cy="-16.5" r="1.75" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none"/>
+<circle cx="23.223946" cy="7.5" r="4.0" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none"/>
+<circle cx="32.223946" cy="16.5" r="1.75" stroke="#191919" stroke-width="0.35 px" style="stroke-width:0.35;stroke-miterlimit:4;stroke-dasharray:none;fill:none"/>
+<title>Shape2DView</title>
+</g>
+</svg>

+ 5 - 2
HTequi-firmware/src/Atm_lien/Atm_TeensyStep.cpp

@@ -77,8 +77,9 @@ void Atm_TeensyStep::action( int id ) {
     case ENT_STOPPING:
       return;
     case EXT_STOPPING:
-      if(_isHoming && limitState[0]){motor->setPosition(0);_isHoming=0;}
-      if(_isHoming && limitState[1]){maxStep = motor->getPosition();_isHoming=0;}
+      if(_isHoming && limitState[0]){motor->setPosition(0);}
+      if(_isHoming && limitState[1]){maxStep = motor->getPosition();;}
+      _isHoming=0;
       return;
   }
 }
@@ -231,11 +232,13 @@ Atm_TeensyStep& Atm_TeensyStep::moveTo(long int stepAbs ) {
 Atm_TeensyStep& Atm_TeensyStep::stop(){
   controller->stopAsync();
   //trigger( EVT_STOPPING );
+  return *this;
 }
 
 Atm_TeensyStep& Atm_TeensyStep::emergencyStop(){
   controller->emergencyStop();
   //trigger( EVT_STOPPING );
+  return *this;
 }
 
 //Atm_TeensyStep& Atm_TeensyStep::onOSC(OSCMessage& msg)

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

@@ -71,6 +71,7 @@ class Atm_TeensyStep: public Machine {
 
 
 
+
   int _limitPin[2];
   enum { NONE, DIGITAL_1, DIGITAL_2, ANALOG_1 };
   int _limitType; //type of limit switch, from list over

+ 519 - 0
HTequi-firmware/lib/Atm_lien/Atm_Tstepper.cpp

@@ -0,0 +1,519 @@
+#include "Atm_Tstepper.h"
+
+/* Add optional parameters for the state machine to begin()
+ * Add extra initialization code
+ */
+
+Atm_Tstepper& Atm_Tstepper::begin(Stepper & motorRef, StepControl & stepControlRef) {
+  // clang-format off
+  const static state_t state_table[] PROGMEM = {
+    /*                              ON_ENTER      ON_LOOP     ON_EXIT  EVT_HOMING_COUNTER  EVT_IDLE_TIMEOUT  EVT_MOVE_TIMEOUT  EVT_LIMIT_LOW  EVT_LIMIT_HIGH  EVT_EMERGENCY  EVT_STOP  EVT_ONTARGET  EVT_MOVE  EVT_DISABLE  EVT_ENABLE  EVT_HOMING  ELSE */
+    /*          DISABLED */     ENT_DISABLED,          -1,         -1,                 -1,               -1,               -1,            -1,             -1,            -1,       -1,           -1,       -1,          -1,    ENABLED,        -1,    -1,
+    /*           ENABLED */      ENT_ENABLED,          -1,         -1,                 -1,         DISABLED,               -1,            -1,             -1,            -1,       -1,           -1,  RUNNING,    DISABLED,         -1,    HOMING,    -1,
+    /*           RUNNING */      ENT_RUNNING,  LP_RUNNING,         -1,                 -1,               -1,     MOVE_TIMEOUT,     EMERGENCY,      EMERGENCY,     EMERGENCY, STOPPING,      ENABLED,  RUNNING,          -1,         -1,        -1,    -1,
+    /*          STOPPING */     ENT_STOPPING, LP_STOPPING,         -1,                 -1,               -1,               -1,     EMERGENCY,      EMERGENCY,     EMERGENCY,       -1,           -1,  RUNNING,          -1,         -1,        -1,    -1,
+    /*         EMERGENCY */    ENT_EMERGENCY,          -1,         -1,                 -1,               -1,               -1,            -1,             -1,            -1,       -1,           -1,       -1,          -1,         -1,        -1,    -1,
+    /*            HOMING */       ENT_HOMING,   LP_HOMING, EXT_HOMING,                 -1,               -1,     MOVE_TIMEOUT,     EMERGENCY,      EMERGENCY,     EMERGENCY, STOPPING, MOVE_TIMEOUT,       -1,          -1,         -1,        -1,    -1,
+    /*      MOVE_TIMEOUT */ ENT_MOVE_TIMEOUT,          -1,         -1,                 -1,               -1,               -1,     EMERGENCY,             -1,     EMERGENCY,       -1,           -1,       -1,          -1,         -1,        -1,    -1,
+    /* HOMING_COUNTEROUT */               -1,          -1,         -1,                 -1,               -1,               -1,            -1,             -1,            -1,       -1,           -1,       -1,          -1,         -1,        -1,    -1
+  };
+  // clang-format on
+  Machine::begin( state_table, ELSE );
+  this-> motor =   &motorRef;
+  this-> controller = &stepControlRef;
+  idle_timer.set(ATM_TIMER_OFF);
+  moving_timer.set(ATM_TIMER_OFF);
+  return *this;
+}
+
+/* Add C++ code for each internally handled event (input)
+ * The code must return 1 to trigger the event
+ */
+
+int Atm_Tstepper::event( int id ) {
+  switch ( id ) {
+    case EVT_HOMING_COUNTER:
+      return 0;
+    case EVT_IDLE_TIMEOUT:
+      return idle_timer.expired(this);
+    case EVT_MOVE_TIMEOUT:
+      return moving_timer.expired(this);
+    case EVT_LIMIT_LOW:
+      return limitState[0];//limitState[0];
+    case EVT_LIMIT_HIGH:
+      return limitState[1];///limitState[1];
+    case EVT_EMERGENCY:
+      return 0;
+    case EVT_STOP:
+      return 0;
+    case EVT_ONTARGET: //triggers if stepper reached _targetStep
+      return _currentStep == _targetStep ;
+    case EVT_MOVE:
+      return 0;
+    case EVT_DISABLE:
+      return 0;
+    case EVT_ENABLE:
+      return 0;
+    case EVT_HOMING:
+      return 0;
+  }
+  return 0;
+}
+
+/* Add C++ code for each action
+ * This generates the 'output' for the state machine
+ *
+ * Available connectors:
+ *   push( connectors, ON_ONCHANGE, 0, <v>, <up> );
+ *   push( connectors, ON_ONCHANGEACCELERATION, 0, <v>, <up> );
+ *   push( connectors, ON_ONCHANGEPOSITION, 0, <v>, <up> );
+ *   push( connectors, ON_ONCHANGESTATE, 0, <v>, <up> );
+ *   push( connectors, ON_ONHIGHLIMIT, 0, <v>, <up> );
+ *   push( connectors, ON_ONHOMINGCOUNTEROUT, 0, <v>, <up> );
+ *   push( connectors, ON_ONHOMINGTIMEOUT, 0, <v>, <up> );
+ *   push( connectors, ON_ONIDLETIMEOUT, 0, <v>, <up> );
+ *   push( connectors, ON_ONLOWLIMIT, 0, <v>, <up> );
+ *   push( connectors, ON_ONMOVETIMEOUT, 0, <v>, <up> );
+ *   push( connectors, ON_SPEED, 0, <v>, <up> );
+ */
+
+void Atm_Tstepper::action( int id ) {
+  switch ( id ) {
+    long int tempStep ;
+    case ENT_DISABLED:
+      idle_timer.set(ATM_TIMER_OFF);
+      moving_timer.set(ATM_TIMER_OFF);
+      enabled = _enableReversed ? HIGH : LOW;
+      digitalWrite(_enablePin, enabled);
+      sendOSC();
+      return;
+    case ENT_ENABLED:
+      // idle_timer.set(IDLE_TIMEOUT_DURATION);
+      // moving_timer.set(ATM_TIMER_OFF);
+      enabled = _enableReversed ? LOW : HIGH ;
+      digitalWrite(_enablePin, enabled);
+      sendOSC();
+      return;
+    case ENT_RUNNING:
+      // idle_timer.set(ATM_TIMER_OFF);
+      // moving_timer.set(MOVING_TIMEOUT_DURATION);
+      return;
+    case LP_RUNNING:
+      tempStep = motor->getPosition();
+      connectors[ON_ONCHANGEPOSITION].push(_currentStep);
+      // if (tempStep != _currentStep){push( connectors, ON_ONCHANGEPOSITION, 0, _currentStep, 0 );} ;
+      _currentStep =  tempStep;
+      updateLimitSwitch();
+      sendOSC();
+      return;
+    case ENT_STOPPING:
+      idle_timer.set(ATM_TIMER_OFF);
+      moving_timer.set(ATM_TIMER_OFF);
+      sendOSC();
+      return;
+    case LP_STOPPING:
+      return;
+    case ENT_EMERGENCY:
+      idle_timer.set(ATM_TIMER_OFF);
+      moving_timer.set(ATM_TIMER_OFF);
+      controller->emergencyStop();
+      sendOSC();
+      return;
+    case ENT_HOMING:
+      // idle_timer.set(ATM_TIMER_OFF);
+      // moving_timer.set(MOVING_TIMEOUT_DURATION);
+      _limitType ? move(-2147483647) : trigger(EVT_STOP) ;
+      sendOSC();
+      return;
+    case LP_HOMING:
+      updateLimitSwitch();
+      sendOSC();
+      return;
+    case EXT_HOMING:
+      switch(next_trigger){
+        case EVT_LIMIT_LOW:
+          Serial.println("LOW");
+          move(10);
+          return;
+        case EVT_LIMIT_HIGH:
+          Serial.println("HIGH");
+          move(-10);
+          return;
+      }
+
+      return;
+    case ENT_MOVE_TIMEOUT:
+      idle_timer.set(ATM_TIMER_OFF);
+      moving_timer.set(ATM_TIMER_OFF);
+      emergency();
+      return;
+  }
+}
+
+/* Optionally override the default trigger() method
+ * Control how your machine processes triggers
+ */
+
+Atm_Tstepper& Atm_Tstepper::trigger( int event ) {
+  Machine::trigger( event );
+  return *this;
+}
+
+/* Optionally override the default state() method
+ * Control what the machine returns when another process requests its state
+ */
+
+int Atm_Tstepper::state( void ) {
+  return Machine::state();
+}
+
+/* CUSTOM METHODS
+********************************************************************************************************
+*/
+
+// Atm_TeensyStep& Atm_TeensyStep::enable( bool enable ){
+//
+//   return *this;
+// }
+
+/////////   ENABLE/DISABLE    ////////
+
+Atm_Tstepper& Atm_Tstepper::setEnablePin( int enablePin ){
+  _enablePin = enablePin ;
+  pinMode(_enablePin, OUTPUT);
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::enableReversed( bool reverse ){
+  _enableReversed = reverse ;
+  return *this;
+}
+
+/////////   LIMITS    ////////
+
+Atm_Tstepper& Atm_Tstepper::setLimitPins( int limitPinLow){
+  _limitPin[0] = limitPinLow;
+  pinMode(_limitPin[0], INPUT);
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::setLimitPins( int limitPinLow, int limitPinHigh){
+ _limitPin[0] = limitPinLow;
+ _limitPin[1] = limitPinHigh;
+ pinMode(_limitPin[0], INPUT);
+ pinMode(_limitPin[1], INPUT);
+ return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::setLimitType( int limitType){
+ _limitType = limitType;
+ return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::limitReversed( bool reversed){
+ _limitReversed = reversed;
+ return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::limitThresholds( int limitThreshold0,
+       int limitThreshold1,  int limitThreshold2, int limitThreshold3){
+ _limitThresholds[0] = limitThreshold0;
+ _limitThresholds[1] = limitThreshold1;
+ _limitThresholds[2] = limitThreshold2;
+ _limitThresholds[3] = limitThreshold3;
+ return *this;
+}
+
+void Atm_Tstepper::updateLimitSwitch(){
+  switch (_limitType) { // limitType!=0 means there is limit to check
+    case NONE:
+      return ;
+    case DIGITAL_1:
+      limitState[0] = digitalRead(_limitPin[0]);
+      limitState[0] = _limitReversed ? !limitState[0] : limitState[0];
+      return;
+    case DIGITAL_2:
+    limitState[0] = digitalRead(_limitPin[0]);
+    limitState[1] = digitalRead(_limitPin[1]);
+    limitState[0] = _limitReversed ? !limitState[0] : limitState[0];
+    limitState[1] = _limitReversed ? !limitState[1] : limitState[1];
+      return;
+    case ANALOG_1:
+    int read = analogRead(_limitPin[0]) ;
+    limitState[0] = _limitThresholds[0] < read && read < _limitThresholds[1] ;
+    limitState[1] = _limitThresholds[2] < read && read < _limitThresholds[3] ;
+      return;
+  }
+
+}
+
+int Atm_Tstepper::printPosition(){Serial.println(_currentStep);return 0;}
+
+Atm_Tstepper& Atm_Tstepper::onOSC( void ){
+//  _enableReversed = reverse ;
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::sendOSC( void ){
+//  _enableReversed = reverse ;
+  return *this;
+}
+
+
+// Atm_Tstepper& Atm_Tstepper::move(long int stepRel ) {
+//
+//   // _motor.move(targetStep);
+//   // _motor.run();
+//   // Serial.println(_motor.distanceToGo());
+//   // _motor.setMaxSpeed(5000);
+//   // _motor.setAcceleration(6000);
+//   trigger( EVT_GOTO );
+//   return *this;
+// }
+
+/* Nothing customizable below this line
+ ************************************************************************************************
+*/
+
+/* Public event methods
+ *
+ */
+
+Atm_Tstepper& Atm_Tstepper::homing_counter() {
+  trigger( EVT_HOMING_COUNTER );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::idle_timeout() {
+  trigger( EVT_IDLE_TIMEOUT );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::move_timeout() {
+  trigger( EVT_MOVE_TIMEOUT );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::limit_low() {
+  trigger( EVT_LIMIT_LOW );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::limit_high() {
+  trigger( EVT_LIMIT_HIGH );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::emergency() {
+  controller->emergencyStop();
+  trigger( EVT_EMERGENCY );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::stop() {
+  controller->stop();
+  trigger( EVT_STOP );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::ontarget() {
+  trigger( EVT_ONTARGET );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::move(long int stepRel) {
+  _targetStep   += stepRel;
+  motor->setTargetAbs(_targetStep);
+  controller->moveAsync(*motor);
+  enable();
+  trigger( EVT_MOVE );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::moveTo(long int stepAbs) {
+  _targetStep   = stepAbs;
+  motor->setTargetAbs(_targetStep);
+  controller->moveAsync(*motor);
+  enable();
+  trigger( EVT_MOVE );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::disable() {
+  trigger( EVT_DISABLE );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::enable() {
+  trigger( EVT_ENABLE );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::homing(int direction) {
+  trigger( EVT_HOMING );
+  return *this;
+}
+
+/*
+ * onOnchange() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnchange( Machine& machine, int event ) {
+  onPush( connectors, ON_ONCHANGE, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnchange( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONCHANGE, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnchangeacceleration() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnchangeacceleration( Machine& machine, int event ) {
+  onPush( connectors, ON_ONCHANGEACCELERATION, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnchangeacceleration( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONCHANGEACCELERATION, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnchangeposition() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnchangeposition( Machine& machine, int event ) {
+  onPush( connectors, ON_ONCHANGEPOSITION, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnchangeposition( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONCHANGEPOSITION, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnchangestate() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnchangestate( Machine& machine, int event ) {
+  onPush( connectors, ON_ONCHANGESTATE, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnchangestate( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONCHANGESTATE, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnhighlimit() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnhighlimit( Machine& machine, int event ) {
+  onPush( connectors, ON_ONHIGHLIMIT, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnhighlimit( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONHIGHLIMIT, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnhomingcounterout() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnhomingcounterout( Machine& machine, int event ) {
+  onPush( connectors, ON_ONHOMINGCOUNTEROUT, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnhomingcounterout( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONHOMINGCOUNTEROUT, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnhomingtimeout() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnhomingtimeout( Machine& machine, int event ) {
+  onPush( connectors, ON_ONHOMINGTIMEOUT, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnhomingtimeout( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONHOMINGTIMEOUT, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnidletimeout() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnidletimeout( Machine& machine, int event ) {
+  onPush( connectors, ON_ONIDLETIMEOUT, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnidletimeout( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONIDLETIMEOUT, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnlowlimit() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnlowlimit( Machine& machine, int event ) {
+  onPush( connectors, ON_ONLOWLIMIT, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnlowlimit( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONLOWLIMIT, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onOnmovetimeout() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onOnmovetimeout( Machine& machine, int event ) {
+  onPush( connectors, ON_ONMOVETIMEOUT, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onOnmovetimeout( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_ONMOVETIMEOUT, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/*
+ * onSpeed() push connector variants ( slots 1, autostore 0, broadcast 0 )
+ */
+
+Atm_Tstepper& Atm_Tstepper::onSpeed( Machine& machine, int event ) {
+  onPush( connectors, ON_SPEED, 0, 1, 1, machine, event );
+  return *this;
+}
+
+Atm_Tstepper& Atm_Tstepper::onSpeed( atm_cb_push_t callback, int idx ) {
+  onPush( connectors, ON_SPEED, 0, 1, 1, callback, idx );
+  return *this;
+}
+
+/* State trace method
+ * Sets the symbol table and the default logging method for serial monitoring
+ */
+
+Atm_Tstepper& Atm_Tstepper::trace( Stream & stream ) {
+  Machine::setTrace( &stream, atm_serial_debug::trace,
+    "TSTEPPER\0EVT_HOMING_COUNTER\0EVT_IDLE_TIMEOUT\0EVT_MOVE_TIMEOUT\0EVT_LIMIT_LOW\0EVT_LIMIT_HIGH\0EVT_EMERGENCY\0EVT_STOP\0EVT_ONTARGET\0EVT_MOVE\0EVT_DISABLE\0EVT_ENABLE\0ELSE\0DISABLED\0ENABLED\0RUNNING\0STOPPING\0EMERGENCY\0HOMING\0MOVE_TIMEOUT\0HOMING_COUNTEROUT" );
+  return *this;
+}

+ 184 - 0
HTequi-firmware/lib/Atm_lien/Atm_Tstepper.h

@@ -0,0 +1,184 @@
+#pragma once
+
+#include <Automaton.h>
+//#include <Atm_timer.h>
+
+#include <TeensyStep.h>
+
+class Atm_Tstepper: public Machine {
+
+ public:
+  enum { DISABLED, ENABLED, RUNNING, STOPPING, EMERGENCY, HOMING, MOVE_TIMEOUT, HOMING_COUNTEROUT }; // STATES
+  enum { EVT_HOMING_COUNTER, EVT_IDLE_TIMEOUT, EVT_MOVE_TIMEOUT, EVT_LIMIT_LOW, EVT_LIMIT_HIGH, EVT_EMERGENCY, EVT_STOP, EVT_ONTARGET, EVT_MOVE, EVT_DISABLE, EVT_ENABLE, EVT_HOMING, ELSE }; // EVENTS
+  Atm_Tstepper( void ) : Machine() {};
+  Atm_Tstepper& begin( Stepper & motorRef, StepControl & stepControlRef );
+  Atm_Tstepper& trace( Stream & stream );
+  Atm_Tstepper& trigger( int event );
+  int state( void );
+  Atm_Tstepper& onOnchange( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnchange( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnchangeacceleration( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnchangeacceleration( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnchangeposition( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnchangeposition( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnchangestate( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnchangestate( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnhighlimit( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnhighlimit( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnhomingcounterout( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnhomingcounterout( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnhomingtimeout( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnhomingtimeout( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnidletimeout( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnidletimeout( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnlowlimit( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnlowlimit( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onOnmovetimeout( Machine& machine, int event = 0 );
+  Atm_Tstepper& onOnmovetimeout( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& onSpeed( Machine& machine, int event = 0 );
+  Atm_Tstepper& onSpeed( atm_cb_push_t callback, int idx = 0 );
+  Atm_Tstepper& homing_counter( void );
+  Atm_Tstepper& idle_timeout( void );
+  Atm_Tstepper& move_timeout( void );
+  Atm_Tstepper& limit_low( void );
+  Atm_Tstepper& limit_high( void );
+  Atm_Tstepper& emergency( void );
+  Atm_Tstepper& stop( void );
+  Atm_Tstepper& ontarget( void );
+  Atm_Tstepper& move( long int stepRel );
+  Atm_Tstepper& moveTo( long int stepAbs );
+  Atm_Tstepper& disable( void );
+  Atm_Tstepper& enable( void );
+  Atm_Tstepper& homing( int direction );
+
+
+  Atm_Tstepper& setLimitType( int limitType = 0);
+  Atm_Tstepper& setLimitPins( int limitPinLow);
+  Atm_Tstepper& setLimitPins( int limitPinLow, int limitPinHigh);
+  Atm_Tstepper& limitReversed( bool reversed );
+  Atm_Tstepper& limitThresholds( int limitThreshold0, int limitThreshold1,
+                                  int limitThreshold2, int limitThreshold3);
+  bool limitState[2] ; // up to two limits, at least one for homing
+
+  virtual Atm_Tstepper& onOSC( void );
+  virtual Atm_Tstepper& sendOSC( void );
+
+  Stepper * motor;
+  StepControl * controller;
+
+  Atm_Tstepper& setEnablePin( int enablePin );
+  Atm_Tstepper& enableReversed( bool reverse );
+  bool enabled ;
+  // Atm_TeensyStep& enable( bool enable );
+
+  int printPosition();
+
+ private:
+  enum { ENT_DISABLED, ENT_ENABLED, ENT_RUNNING, LP_RUNNING, ENT_STOPPING, LP_STOPPING, ENT_EMERGENCY, ENT_HOMING, LP_HOMING, EXT_HOMING, ENT_MOVE_TIMEOUT }; // ACTIONS
+  enum { ON_ONCHANGE, ON_ONCHANGEACCELERATION, ON_ONCHANGEPOSITION, ON_ONCHANGESTATE, ON_ONHIGHLIMIT, ON_ONHOMINGCOUNTEROUT, ON_ONHOMINGTIMEOUT, ON_ONIDLETIMEOUT, ON_ONLOWLIMIT, ON_ONMOVETIMEOUT, ON_SPEED, CONN_MAX }; // CONNECTORS
+  atm_connector connectors[CONN_MAX];
+  int event( int id );
+  void action( int id );
+
+  atm_timer_millis idle_timer ;
+  int IDLE_TIMEOUT_DURATION = 500000 ;
+  atm_timer_millis moving_timer ;
+  int MOVING_TIMEOUT_DURATION = 12000000 ;
+  atm_counter homing_counterout ;
+
+  long int _currentStep ;
+  long int _targetStep ;
+
+  int _enablePin = -1;
+  bool _enableReversed = 0 ;
+
+  int _limitPin[2];
+  enum { NONE, DIGITAL_1, DIGITAL_2, ANALOG_1 };
+  int _limitType; //type of limit switch, from list over
+  bool _limitReversed ; //invert logic of limit switches
+  int _limitThresholds[4] ; //analog value  range for two analog limits
+  void updateLimitSwitch();
+
+
+
+};
+
+/*
+Automaton::ATML::begin - Automaton Markup Language
+
+<?xml version="1.0" encoding="UTF-8"?>
+<machines>
+  <machine name="Atm_Tstepper">
+    <states>
+      <DISABLED index="0" on_enter="ENT_DISABLED">
+        <EVT_ENABLE>ENABLED</EVT_ENABLE>
+      </DISABLED>
+      <ENABLED index="1" on_enter="ENT_ENABLED">
+        <EVT_IDLE_TIMEOUT>DISABLED</EVT_IDLE_TIMEOUT>
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+        <EVT_DISABLE>DISABLED</EVT_DISABLE>
+      </ENABLED>
+      <RUNNING index="2" on_enter="ENT_RUNNING" on_loop="LP_RUNNING">
+        <EVT_MOVE_TIMEOUT>MOVE_TIMEOUT</EVT_MOVE_TIMEOUT>
+        <EVT_LIMIT_LOW>EMERGENCY</EVT_LIMIT_LOW>
+        <EVT_LIMIT_HIGH>EMERGENCY</EVT_LIMIT_HIGH>
+        <EVT_EMERGENCY>EMERGENCY</EVT_EMERGENCY>
+        <EVT_STOP>STOPPING</EVT_STOP>
+        <EVT_ONTARGET>ENABLED</EVT_ONTARGET>
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+      </RUNNING>
+      <STOPPING index="3" on_enter="ENT_STOPPING" on_loop="LP_STOPPING">
+        <EVT_LIMIT_LOW>EMERGENCY</EVT_LIMIT_LOW>
+        <EVT_LIMIT_HIGH>EMERGENCY</EVT_LIMIT_HIGH>
+        <EVT_EMERGENCY>EMERGENCY</EVT_EMERGENCY>
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+      </STOPPING>
+      <EMERGENCY index="4" on_enter="ENT_EMERGENCY">
+      </EMERGENCY>
+      <HOMING index="5" on_enter="ENT_HOMING" on_loop="LP_HOMING" on_exit="EXT_HOMING">
+        <EVT_MOVE_TIMEOUT>MOVE_TIMEOUT</EVT_MOVE_TIMEOUT>
+        <EVT_LIMIT_LOW>ENABLED</EVT_LIMIT_LOW>
+        <EVT_LIMIT_HIGH>ENABLED</EVT_LIMIT_HIGH>
+        <EVT_EMERGENCY>EMERGENCY</EVT_EMERGENCY>
+        <EVT_STOP>STOPPING</EVT_STOP>
+        <EVT_ONTARGET>MOVE_TIMEOUT</EVT_ONTARGET>
+      </HOMING>
+      <MOVE_TIMEOUT index="6" on_enter="ENT_MOVE_TIMEOUT">
+        <EVT_MOVE_TIMEOUT>MOVE_TIMEOUT</EVT_MOVE_TIMEOUT>
+      </MOVE_TIMEOUT>
+      <HOMING_COUNTEROUT index="7">
+      </HOMING_COUNTEROUT>
+    </states>
+    <events>
+      <EVT_HOMING_COUNTER index="0" access="MIXED"/>
+      <EVT_IDLE_TIMEOUT index="1" access="MIXED"/>
+      <EVT_MOVE_TIMEOUT index="2" access="MIXED"/>
+      <EVT_LIMIT_LOW index="3" access="MIXED"/>
+      <EVT_LIMIT_HIGH index="4" access="MIXED"/>
+      <EVT_EMERGENCY index="5" access="MIXED"/>
+      <EVT_STOP index="6" access="MIXED"/>
+      <EVT_ONTARGET index="7" access="MIXED"/>
+      <EVT_MOVE index="8" access="MIXED"/>
+      <EVT_DISABLE index="9" access="MIXED"/>
+      <EVT_ENABLE index="10" access="MIXED"/>
+    </events>
+    <connectors>
+      <ONCHANGE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONCHANGEACCELERATION autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONCHANGEPOSITION autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONCHANGESTATE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONHIGHLIMIT autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONHOMINGCOUNTEROUT autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONHOMINGTIMEOUT autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONIDLETIMEOUT autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONLOWLIMIT autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <ONMOVETIMEOUT autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <SPEED autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+    </connectors>
+    <methods>
+    </methods>
+  </machine>
+</machines>
+
+Automaton::ATML::end
+*/

+ 30 - 0
HTequi-firmware/lib/Atm_lien/Atm_Tstepper_OSC.cpp

@@ -0,0 +1,30 @@
+#include "Atm_Tstepper_OSC.h"
+
+Atm_Tstepper_OSC& Atm_Tstepper_OSC::begin(Atm_Tstepper & stepperMachineRef, EthernetUDP& udpRef, OSCBundle& bndl, const char* address) {
+  this-> stepperMachine = &stepperMachineRef;
+  _adress = address;
+  this->_udpRef =   &udpRef;
+  this->_bndl = &bndl ;
+  return *this;
+}
+
+
+
+Atm_Tstepper_OSC& Atm_Tstepper_OSC::onOSC(OSCMessage& msg ){
+  Serial.println("OSC");
+  int patternOffset = msg.match(_adress) ;
+  if(patternOffset){
+    if(msg.fullMatch("/speedAcc", patternOffset)){
+      stepperMachine->motor->setMaxSpeed(msg.getInt(0));
+      stepperMachine->motor->setAcceleration(msg.getInt(1));
+    }
+    if(msg.fullMatch("/enable", patternOffset)){msg.getInt(0) ? stepperMachine->trigger(stepperMachine->EVT_ENABLE) : stepperMachine->trigger(stepperMachine->EVT_DISABLE);}
+    //if(msg.fullMatch("/home", patternOffset)){home(msg.getInt(0));}
+    if(msg.fullMatch("/move", patternOffset)){stepperMachine->move(msg.getInt(0));}
+    if(msg.fullMatch("/moveTo", patternOffset)){stepperMachine->moveTo(msg.getInt(0));}
+    if(msg.fullMatch("/stop", patternOffset)){stepperMachine->stop();}
+    if(msg.fullMatch("/emergencyStop", patternOffset)){stepperMachine->emergency();}
+
+    return *this;
+  }
+}

+ 26 - 0
HTequi-firmware/lib/Atm_lien/Atm_Tstepper_OSC.h

@@ -0,0 +1,26 @@
+#pragma once
+
+#include "Atm_Tstepper.h"
+
+#include <EthernetUdp.h>
+#include <OSCMessage.h>
+#include <OSCBundle.h>
+
+class Atm_Tstepper_OSC {
+
+  public:
+    Atm_Tstepper_OSC( void ){};
+    Atm_Tstepper_OSC& begin(Atm_Tstepper & stepperMachineRef, EthernetUDP& udpRef, OSCBundle& bndl, const char* address);
+    Atm_Tstepper* stepperMachine ;
+    const char* _adress = "/OSC";
+    EthernetUDP* _udpRef ;
+    Atm_Tstepper_OSC& onOSC(OSCMessage& msg );
+    Atm_Tstepper& sendOSC( void );
+
+  private:
+   // AccelStepper _motor;
+   // Stepper *_motor;       // STEP pin: 2, DIR pin: 3
+   // StepControl _controller;
+   OSCBundle* _bndl;
+
+};

+ 260 - 0
HTequi-firmware/lib/Atm_lien/Atm_out.cpp

@@ -0,0 +1,260 @@
+#include "Atm_out.h"
+
+Atm_out& Atm_out::begin( int attached_pin, bool activeLow,
+            EthernetUDP& udpRef, OSCBundle& bndl, const char* address ) {
+  // clang-format off
+  static const state_t state_table[] PROGMEM = {
+    /*               ON_ENTER    ON_LOOP    ON_EXIT  EVT_ON_TIMER  EVT_OFF_TIMER EVT_WT_TIMER EVT_COUNTER  EVT_ON  EVT_OFF  EVT_BLINK  EVT_TOGGLE  EVT_TOGGLE_BLINK   ELSE */
+    /* IDLE      */  ENT_INIT, ATM_SLEEP,        -1,           -1,            -1,          -1,         -1,  WT_ON,      -1,  WT_START,         ON,         WT_START,    -1, // LED off
+    /* ON        */    ENT_ON, ATM_SLEEP,        -1,           -1,            -1,          -1,         -1,     -1,     OFF,  WT_START,        OFF,              OFF,    -1, // LED on
+    /* START     */    ENT_ON,        -1,        -1,    BLINK_OFF,            -1,          -1,         -1,  WT_ON,     OFF,        -1,        OFF,              OFF,    -1, // Start blinking
+    /* BLINK_OFF */   ENT_OFF,        -1,        -1,           -1,          LOOP,          -1,         -1,  WT_ON,     OFF,        -1,        OFF,              OFF,    -1,
+    /* LOOP      */        -1,        -1,        -1,           -1,            -1,          -1,       DONE,  WT_ON,     OFF,        -1,        OFF,              OFF, START,
+    /* DONE      */        -1,        -1, EXT_CHAIN,           -1,           OFF,          -1,         -1,  WT_ON,     OFF,  WT_START,        OFF,              OFF,    -1, // Wait after last blink
+    /* OFF       */   ENT_OFF,        -1,        -1,           -1,            -1,          -1,         -1,  WT_ON,     OFF,  WT_START,         -1,               -1,  IDLE, // All off -> IDLE
+    /* WT_ON     */        -1,        -1,        -1,           -1,            -1,          ON,         -1,  WT_ON,     OFF,  WT_START,         -1,               -1,    -1, // LEAD for ON
+    /* WT_START  */        -1,        -1,        -1,           -1,            -1,       START,         -1,  WT_ON,     OFF,  WT_START,         -1,               -1,    -1, // LEAD for BLINK
+  };
+  // clang-format on
+  Machine::begin( state_table, ELSE );
+  pin = attached_pin;
+  this->activeLow = activeLow;
+  level = 255;
+  toLow = 0;
+  toHigh = 255;
+  wrap = false;
+  pinMode( pin, OUTPUT );
+  digitalWrite( pin, activeLow ? HIGH : LOW );
+  on_timer.set( 500 );
+  off_timer.set( 500 );
+  pwm( 512, 1 );
+  lead_timer.set( 0 );
+  repeat_count = ATM_COUNTER_OFF;
+  counter.set( repeat_count );
+  while ( state() != 0 ) cycle();
+  _adress = address;
+  this->_udpRef =   &udpRef;
+  this->_bndl = &bndl ;
+  return *this;
+}
+
+Atm_out& Atm_out::pwm( uint16_t width, float freq ) {
+
+    if ( freq > -1 ) {
+		this->freq = freq;
+	} else {
+		freq = this->freq;
+	}
+	this->width = width;
+	float cycle_width = 1000 / freq;
+	on_timer.set( cycle_width / 1024 * this->width );
+	off_timer.set( cycle_width / 1024 * ( 1024 - this->width ) );
+	return *this;
+}
+
+Atm_out& Atm_out::frequency( float freq ) {
+
+	this->freq = freq;
+	float cycle_width = 1000 / freq;
+	on_timer.set( cycle_width / 1024 * this->width );
+	off_timer.set( cycle_width / 1024 * ( 1024 - this->width ) );
+	return *this;
+}
+
+int Atm_out::event( int id ) {
+  switch ( id ) {
+    case EVT_ON_TIMER:
+      return on_timer.expired( this );
+    case EVT_OFF_TIMER:
+      return off_timer.expired( this );
+    case EVT_WT_TIMER:
+      return lead_timer.expired( this );
+    case EVT_COUNTER:
+      return counter.expired();
+  }
+  return 0;
+}
+
+void Atm_out::action( int id ) {
+  switch ( id ) {
+    case ENT_INIT:
+      counter.set( repeat_count );
+      return;
+    case ENT_ON:
+      if ( on_timer.value > 0 ) { // Never turn if on_timer is zero (duty cycle 0 must be dark)
+        if ( activeLow ) {
+          digitalWrite( pin, LOW );
+        } else {
+          if ( level == toHigh ) {
+            digitalWrite( pin, HIGH );
+          } else {
+            analogWrite( pin, mapLevel( level ) );
+          }
+        }
+      }
+      return;
+    case ENT_OFF:
+      counter.decrement();
+      if ( !activeLow ) {
+        digitalWrite( pin, LOW );
+      } else {
+        if ( level == toHigh ) {
+          digitalWrite( pin, HIGH );
+        } else {
+          analogWrite( pin, mapLevel( level ) );
+        }
+      }
+      return;
+    case EXT_CHAIN:
+      onfinish.push( 0 );
+      return;
+  }
+}
+
+int Atm_out::mapLevel( int level ) {
+  if ( levelMapSize ) {
+    return levelMap[level];
+  } else {
+    return map( level, toLow, toHigh, 0, 255 );
+  }
+}
+
+Atm_out& Atm_out::on( void ) {
+  trigger( EVT_ON );
+  return *this;
+}
+
+Atm_out& Atm_out::off( void ) {
+  trigger( EVT_OFF );
+  return *this;
+}
+
+Atm_out& Atm_out::toggle( void ) {
+  trigger( EVT_TOGGLE );
+  return *this;
+}
+
+Atm_out& Atm_out::toggleBlink( void ) {
+  trigger( EVT_TOGGLE_BLINK );
+  return *this;
+}
+
+Atm_out& Atm_out::start( void ) {
+  trigger( EVT_BLINK );
+  return *this;
+}
+
+Atm_out& Atm_out::onFinish( Machine& machine, int event /* = 0 */ ) {
+  onfinish.set( &machine, event );
+  return *this;
+}
+
+Atm_out& Atm_out::onFinish( atm_cb_push_t callback, int idx /* = 0 */ ) {
+  onfinish.set( callback, idx );
+  return *this;
+}
+
+Atm_out& Atm_out::blink( uint32_t duration, uint32_t pause_duration, uint16_t repeat_count /* = ATM_COUNTER_OFF */ ) {
+  blink( duration );  // Time in which led is fully on
+  pause( pause_duration );
+  repeat( repeat_count );
+  return *this;
+}
+
+Atm_out& Atm_out::blink( uint32_t duration ) {
+  on_timer.set( duration );  // Time in which led is fully on
+  return *this;
+}
+
+Atm_out& Atm_out::blink( void ) {
+  trigger( EVT_BLINK );
+  return *this;
+}
+
+Atm_out& Atm_out::range( int toLow, int toHigh, bool wrap /* = false */ ) {
+  this->toLow = toLow;
+  this->toHigh = toHigh;
+  this->wrap = wrap;
+  level = toHigh;
+  return *this;
+}
+
+Atm_out& Atm_out::levels( unsigned char* map, int mapsize, bool wrap /* = false */ ) {
+  this->levelMap = map;
+  levelMapSize = mapsize;
+  range( 0, mapsize - 1, wrap );
+  return *this;
+}
+
+Atm_out& Atm_out::pause( uint32_t duration ) {  // Time in which led is fully off
+  off_timer.set( duration ? duration : 1 );     // Make sure off_timer is never 0 (work around)
+  return *this;
+}
+
+Atm_out& Atm_out::fade( int fade ) {
+  return *this;
+}  // Dummy for method compatibility with Atm_fade
+
+Atm_out& Atm_out::lead( uint32_t ms ) {
+  lead_timer.set( ms );
+  return *this;
+}
+
+Atm_out& Atm_out::repeat( uint16_t repeat ) {
+  counter.set( repeat_count = repeat );
+  return *this;
+}
+
+int Atm_out::brightness( int level /* = -1 */ ) {
+  if ( level > -1 ) {
+    this->level = level;
+    if ( current == ON || current == START ) {
+      analogWrite( pin, mapLevel( level ) );
+    }
+  }
+  return this->level;
+}
+
+int Atm_out::brighten( int v ) {
+  if ( abs( v ) == 1 ) {
+    int br = (int)this->level + v;
+    if ( br > toHigh )
+      br = wrap ? toLow : toHigh;
+    if ( br < toLow )
+      br = wrap ? toHigh : toLow;
+    brightness( br );
+  }
+  return this->level;
+}
+
+Atm_out& Atm_out::trigger( int event ) {
+  if ( event > ELSE ) {
+    brighten( event == EVT_BRUP ? 1 : -1 );
+  } else {
+    Machine::trigger( event );
+  }
+  return *this;
+}
+
+Atm_out& Atm_out::onOSC(OSCMessage& msg ){
+  Serial.println("OSC");
+  int patternOffset = msg.match(_adress) ;
+  if(patternOffset){
+
+    if(msg.fullMatch("/on", patternOffset)){trigger(EVT_ON);}
+    if(msg.fullMatch("/off", patternOffset)){trigger(EVT_OFF);}
+    if(msg.fullMatch("/toggle", patternOffset)){trigger(EVT_TOGGLE);}
+    if(msg.fullMatch("/blink", patternOffset)){trigger(EVT_BLINK);}
+    if(msg.fullMatch("/brightness", patternOffset)){brightness(msg.getInt(0));}
+
+    return *this;
+  }
+}
+
+Atm_out& Atm_out::trace( Stream& stream ) {
+  setTrace( &stream, atm_serial_debug::trace,
+            "LED\0EVT_ON_TIMER\0EVT_OFF_TIMER\0EVT_WT_TIMER\0EVT_COUNTER\0EVT_ON\0EVT_OFF\0EVT_"
+            "BLINK\0EVT_TOGGLE\0EVT_TOGGLE_BLINK\0ELSE\0"
+            "IDLE\0ON\0START\0BLINK_OFF\0LOOP\0DONE\0OFF\0WT_ON\0WT_START" );
+  return *this;
+}

+ 67 - 0
HTequi-firmware/lib/Atm_lien/Atm_out.h

@@ -0,0 +1,67 @@
+#pragma once
+
+#include <Automaton.h>
+
+#include <EthernetUdp.h>
+#include <OSCMessage.h>
+#include <OSCBundle.h>
+
+class Atm_out : public Machine {
+ public:
+  enum { IDLE, ON, START, BLINK_OFF, LOOP, DONE, OFF, WT_ON, WT_START };
+  enum { EVT_ON_TIMER, EVT_OFF_TIMER, EVT_WT_TIMER, EVT_COUNTER, EVT_ON, EVT_OFF, EVT_BLINK, EVT_TOGGLE, EVT_TOGGLE_BLINK, ELSE, EVT_BRUP, EVT_BRDN }; // BRUP/BRDN pseudo
+  enum { EVT_START = EVT_BLINK };
+
+  Atm_out( void ) : Machine(){};
+  Atm_out& begin( int attached_pin, bool activeLow,
+          EthernetUDP& udpRef, OSCBundle& bndl, const char* address  );
+  Atm_out& blink( void );
+  Atm_out& blink( uint32_t duration );
+  Atm_out& blink( uint32_t duration, uint32_t pause_duration, uint16_t repeat_count = ATM_COUNTER_OFF );
+  Atm_out& pwm( uint16_t width, float freq = -1 );
+  Atm_out& frequency( float freq );
+  Atm_out& pause( uint32_t duration );
+  Atm_out& fade( int fade );
+  Atm_out& lead( uint32_t ms );
+  Atm_out& repeat( uint16_t repeat );
+  int brightness( int level = -1 );
+  Atm_out& on( void );
+  Atm_out& off( void );
+  Atm_out& toggle( void );
+  Atm_out& toggleBlink( void );
+  Atm_out& start( void );
+  Atm_out& trace( Stream& stream );
+  Atm_out& onFinish( Machine& machine, int event = 0 );
+  Atm_out& onFinish( atm_cb_push_t callback, int idx = 0 );
+  Atm_out& range( int toLow, int toHigh, bool wrap = false );
+  Atm_out& levels( unsigned char* map, int mapsize, bool wrap = false );
+  int brighten( int v = 1 );
+  Atm_out& trigger( int event );
+
+  const char* _adress = "/OSC";
+  EthernetUDP* _udpRef ;
+  Atm_out& onOSC(OSCMessage& msg );
+  OSCBundle* _bndl;
+
+
+ private:
+  enum { ENT_INIT, ENT_ON, ENT_OFF, EXT_CHAIN };
+  uint8_t level;
+  short pin;
+  bool activeLow;
+  uint8_t toHigh, toLow;
+  bool wrap;
+  uint16_t repeat_count;
+  uint16_t width;
+  float freq;
+  atm_timer_millis on_timer, off_timer, lead_timer;
+  atm_counter counter;
+  atm_connector onfinish;
+  unsigned char* levelMap;
+  int levelMapSize;
+  int mapLevel( int level );
+
+
+  int event( int id );
+  void action( int id );
+};

HTequi-firmware/src/Atm_lien/Atm_stepper.cpp → HTequi-firmware/lib/Atm_stepper.cpp


+ 1 - 1
HTequi-firmware/src/Atm_lien/Atm_stepper.h

@@ -2,7 +2,7 @@
 
 #include <Automaton.h>
 // #include <TeensyStep.h>
-#include <AccelStepper.h>
+#include "AccelStepper.h"
 class Atm_stepper: public Machine {
 
  public:

+ 8 - 8
HTequi-firmware/lib/Automaton-1.0.2/src/Atm_led.cpp

@@ -8,12 +8,12 @@ Atm_led& Atm_led::begin( int attached_pin, bool activeLow ) {
     /* ON        */    ENT_ON, ATM_SLEEP,        -1,           -1,            -1,          -1,         -1,     -1,     OFF,  WT_START,        OFF,              OFF,    -1, // LED on
     /* START     */    ENT_ON,        -1,        -1,    BLINK_OFF,            -1,          -1,         -1,  WT_ON,     OFF,        -1,        OFF,              OFF,    -1, // Start blinking
     /* BLINK_OFF */   ENT_OFF,        -1,        -1,           -1,          LOOP,          -1,         -1,  WT_ON,     OFF,        -1,        OFF,              OFF,    -1,
-    /* LOOP      */        -1,        -1,        -1,           -1,            -1,          -1,       DONE,  WT_ON,     OFF,        -1,        OFF,              OFF, START,    
+    /* LOOP      */        -1,        -1,        -1,           -1,            -1,          -1,       DONE,  WT_ON,     OFF,        -1,        OFF,              OFF, START,
     /* DONE      */        -1,        -1, EXT_CHAIN,           -1,           OFF,          -1,         -1,  WT_ON,     OFF,  WT_START,        OFF,              OFF,    -1, // Wait after last blink
     /* OFF       */   ENT_OFF,        -1,        -1,           -1,            -1,          -1,         -1,  WT_ON,     OFF,  WT_START,         -1,               -1,  IDLE, // All off -> IDLE
     /* WT_ON     */        -1,        -1,        -1,           -1,            -1,          ON,         -1,  WT_ON,     OFF,  WT_START,         -1,               -1,    -1, // LEAD for ON
     /* WT_START  */        -1,        -1,        -1,           -1,            -1,       START,         -1,  WT_ON,     OFF,  WT_START,         -1,               -1,    -1, // LEAD for BLINK
-  }; 
+  };
   // clang-format on
   Machine::begin( state_table, ELSE );
   pin = attached_pin;
@@ -36,7 +36,7 @@ Atm_led& Atm_led::begin( int attached_pin, bool activeLow ) {
 
 Atm_led& Atm_led::pwm( uint16_t width, float freq ) {
 
-    if ( freq > -1 ) {	
+    if ( freq > -1 ) {
 		this->freq = freq;
 	} else {
 		freq = this->freq;
@@ -168,8 +168,8 @@ Atm_led& Atm_led::blink( void ) {
 }
 
 Atm_led& Atm_led::range( int toLow, int toHigh, bool wrap /* = false */ ) {
-  this->toLow = toLow; 
-  this->toHigh = toHigh; 
+  this->toLow = toLow;
+  this->toHigh = toHigh;
   this->wrap = wrap;
   level = toHigh;
   return *this;
@@ -194,7 +194,7 @@ Atm_led& Atm_led::fade( int fade ) {
 Atm_led& Atm_led::lead( uint32_t ms ) {
   lead_timer.set( ms );
   return *this;
-} 
+}
 
 Atm_led& Atm_led::repeat( uint16_t repeat ) {
   counter.set( repeat_count = repeat );
@@ -214,9 +214,9 @@ int Atm_led::brightness( int level /* = -1 */ ) {
 int Atm_led::brighten( int v ) {
   if ( abs( v ) == 1 ) {
     int br = (int)this->level + v;
-    if ( br > toHigh ) 
+    if ( br > toHigh )
       br = wrap ? toLow : toHigh;
-    if ( br < toLow ) 
+    if ( br < toLow )
       br = wrap ? toHigh : toLow;
     brightness( br );
   }

+ 0 - 0
HTequi-firmware/src/Atm_lien/OSC_Atm_TeensyStep.h


+ 62 - 50
HTequi-firmware/src/blobcnc_feeder/main.cpp

@@ -1,8 +1,8 @@
 #include <Arduino.h>
 
 #include <Automaton.h>
-#include "Atm_lien/Atm_stepper.h"
-#include "Atm_lien/Atm_TeensyStep.h"
+//#include "Atm_lien/Atm_stepper.h"
+#include "Atm_Tstepper.h"
 
 #include <SPI.h>
 #include <Ethernet.h>
@@ -10,43 +10,49 @@
 #include <TeensyMAC.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;
-
+// ////////////////    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  ////////////////////////
-const int HIGH_SPEED = 800 ;
-const int HIGH_ACC = 800 ;
-const int LOW_SPEED = 100 ;
-const int LOW_ACC = 1000 ;
+/*move are always meant in full steps on the motor output (after reduction)
+so all motors have 200steps per turn */
+const int BARREL_SPEED = 8000 ;
+const int BARREL_ACC = 800 ;
 const int BARREL_DISTANCE = 10 ; //in full steps
+const int BARREL_REDUCTION_RATIO = 26.85;
+const int BARREL_MICROSTEP = 32;
 
-const int REDUCTION_RATIO = 26.85;
+const int BARREL_THRESHOLD = 1000 ; //for sensor to trig
 
+const int PILL_SPEED = 100 ;
+const int PILL_ACC = 1000 ;
+const int PILL_DISTANCE = 200 ; //in full steps
 const int PILL_MICROSTEP = 32;
-const int BARREL_MICROSTEP = 1;
 
-const int BARREL_THRESHOLD = 950 ;
 
-Atm_TeensyStep barrel_step;
+
+Atm_Tstepper barrel_step;
 Stepper barrel_stepper(3, 2);
 StepControl barrel_controller ;
 
 Atm_analog barrel_sensor;
 
-Atm_TeensyStep pill_step;
+Atm_Tstepper pill_step;
 Stepper pill_stepper(6, 5);
 StepControl pill_controller ;
 
@@ -54,10 +60,7 @@ Atm_analog pill_sensor ;
 
 
 void barrel_homing(){
-  digitalWrite( 13, HIGH );
-  barrel_stepper.setMaxSpeed(LOW_SPEED);
-  barrel_stepper.setAcceleration(LOW_ACC);
-  barrel_step.move(BARREL_DISTANCE*BARREL_MICROSTEP*REDUCTION_RATIO);
+  barrel_step.move(BARREL_DISTANCE*BARREL_MICROSTEP*BARREL_REDUCTION_RATIO);
   Serial.println(barrel_sensor.state());
   // while(barrel_sensor.state()>900 && (barrel_step.state() == barrel_step.RUNNING)){ // &&
   //
@@ -85,20 +88,16 @@ void barrel_homing(){
 
 
 void barrel_move(int stepRel){
-  barrel_stepper.setMaxSpeed(HIGH_SPEED);
-  barrel_stepper.setAcceleration(HIGH_ACC);
+  Serial.println(stepRel);
   barrel_step.move(stepRel);
 }
 
 void pill_move(int stepRel){
-  pill_stepper.setMaxSpeed(HIGH_SPEED);
-  pill_stepper.setAcceleration(HIGH_ACC);
+  Serial.println(stepRel);
   pill_step.move(stepRel);
 }
 
 void pill_next(){
-  pill_stepper.setMaxSpeed(HIGH_SPEED);
-  pill_stepper.setAcceleration(HIGH_ACC);
 
   //make one turn, if nothing was seen by sensor try again up to 5 times
 
@@ -111,12 +110,14 @@ void pill_next(){
 
 char cmd_buffer[80];
 Atm_command cmd;
+char cmd1_buffer[80];
+Atm_command cmd1;
 enum { CMD_TEST, CMD_BARREL_MOVE, CMD_BARREL_HOME, CMD_BARREL_NEXT,
           CMD_PILL, CMD_PILL_MOVE };
 const char cmdlist[] =
     "test barrel_move barrel_home barrel_next pill pill_move";
 void cmd_callback( int idx, int v, int up ) {
-  int pin = atoi( cmd.arg( 1 ) );
+  //int pin = atoi( cmd.arg( 1 ) );
   Serial.print(v);
   Serial.println("  in callback");
   switch ( v ) {
@@ -128,11 +129,12 @@ void cmd_callback( int idx, int v, int up ) {
       barrel_move(atoi( cmd.arg( 1 ) ));
       return;
     case CMD_BARREL_HOME:
-      barrel_homing();
+    barrel_step.homing(0);
+      // barrel_homing();
       return;
     case CMD_BARREL_NEXT:
       barrel_move(BARREL_DISTANCE);
-      if(!barrel_sensor.state()>BARREL_THRESHOLD){barrel_homing();}
+      if((!barrel_sensor.state())<BARREL_THRESHOLD){barrel_homing();}
       return;
     case CMD_PILL:
       pill_next();
@@ -148,7 +150,7 @@ void cmd_callback( int idx, int v, int up ) {
 
 void setup() {
   //Configure and start ethernet module (not needed for feeder)
-  //SPI.setSCK(27);
+ //  SPI.setSCK(27);
  //  Ethernet.init(15);//(10)
  //  teensyMAC(mac);
  //  Ethernet.begin(mac, ip);              // start the Ethernet and UDP:
@@ -157,6 +159,7 @@ void setup() {
 
   //Start serial
   Serial.begin(115200); // higher Baud rate for faster refresh, CHANGE IN SERIAL MONITOR
+  Serial1.begin(115200);
   delay(2000);
   Serial.println("Started");
   cmd.begin( Serial, cmd_buffer, sizeof( cmd_buffer ) )
@@ -164,24 +167,33 @@ void setup() {
     .list( cmdlist )
     .onCommand( cmd_callback );
 
+  cmd1.begin( Serial1, cmd1_buffer, sizeof( cmd1_buffer ) )
+    .trace(Serial)
+    .list( cmdlist )
+    .onCommand( cmd_callback );
   pinMode(13, OUTPUT);
 
-
+  // pinMode(4, OUTPUT);
+  // pinMode(4, LOW);
   barrel_step.trace( Serial );
-  barrel_step.begin(barrel_stepper, barrel_controller);
-  barrel_stepper.setMaxSpeed(LOW_SPEED);
-  barrel_stepper.setAcceleration(HIGH_ACC);
+  barrel_step.begin(barrel_stepper, barrel_controller)
+        .setEnablePin(4).enableReversed(1).enable()
+        .setLimitType(3).setLimitPins(A3).limitThresholds(800, 1000, 0, 100).homing(1);
+  barrel_stepper.setMaxSpeed(BARREL_SPEED);
+  barrel_stepper.setAcceleration(BARREL_ACC);
   barrel_stepper.setInverseRotation(true);
-  barrel_sensor.begin(A1);
+  barrel_sensor.begin(A3);
 
   pill_step.trace( Serial );
-  pill_step.begin(pill_stepper, pill_controller);
-  pill_stepper.setMaxSpeed(HIGH_SPEED);
-  pill_stepper.setAcceleration(HIGH_ACC);
-  pill_sensor.begin(A3);
+  pill_step.begin(pill_stepper, pill_controller)
+        .setEnablePin(7).enableReversed(1).enable();
+  pill_stepper.setMaxSpeed(PILL_SPEED);
+  pill_stepper.setAcceleration(PILL_ACC);
+  pill_sensor.begin(A1);
   //stepper.onOnchange(Machine &machine, optional int event = 0)
   //stepper.cycle(1000);
-  //barrel_step.gotoStep(10000);
+  //barrel_step.move(10000);
+  // pill_step.move(10000);
   //controller.moveAsync(*stepper.motor);
 
 }

+ 33 - 17
HTequi-firmware/src/blobcnc_top/main.cpp

@@ -1,15 +1,12 @@
-// stepper Y 22, 21, 23
-// stepper X 20, 19, 18
-//           St, Di, En
-
 
 #include <Arduino.h>
 
 //Automaton and custom machines
 #include <Automaton.h>
 // #include "Atm_lien/Atm_stepper.h"
-#include "Atm_lien/Atm_TeensyStep.h"
-
+#include "Atm_TeensyStep.h"
+#include "Atm_out.h"
+#include "Atm_Tstepper_OSC.h"
 //osc
 
 
@@ -44,18 +41,26 @@ const int HIGH_ACC = 800 ;
 const int LOW_SPEED = 100 ;
 const int LOW_ACC = 1000 ;
 
-Atm_TeensyStep X_top_step;
+Atm_Tstepper_OSC X_top_OSC;
+Atm_Tstepper X_top_step;
+// 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);
+Stepper Y_top_stepper(6 , 5);
+// Stepper Y_top_stepper(22 , 21);
 StepControl Y_top_controller ;
 
-Atm_fade peristaltic;
+Atm_out peristaltic;
 int peristaltic_pwm_pin = 3;
 int peristaltic_dir_pin = 2;
 
+
+void testCallback(){
+  // printPosition
+}
+
 //////////////  Setup  /////////////////////
 
 void setup() {
@@ -77,12 +82,15 @@ void setup() {
 
   //  STEPPERS
   X_top_step.trace( Serial );
-  X_top_step.begin(X_top_stepper, X_top_controller, Udp, bndl, "/X_top")
-            .setEnablePin(18).enable(1);
+   // X_top_step.begin(X_top_stepper, X_top_controller, Udp, bndl, "/X_top")
+  X_top_step.begin(X_top_stepper, X_top_controller)
+            .setEnablePin(18);//.enableReversed(1);//.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);
+  X_top_OSC.begin(X_top_step, Udp, bndl, "/X_top");
+  // X_top_step.onOnchangeposition();
 
   Y_top_step.trace( Serial );
   Y_top_step.begin(Y_top_stepper, Y_top_controller, Udp, bndl, "/Y_top")
@@ -94,8 +102,12 @@ void setup() {
   Y_top_stepper.setInverseRotation(false);
   //stepper.onOnchange(Machine &machine, optional int event = 0)
   //stepper.cycle(1000);
-  X_top_step.move(-10000);
-  Y_top_step.move(10000);
+  X_top_step.move(-100000);
+  Y_top_step.move(1000);
+  //delay(2000);
+
+  //automaton.delay(5000);
+  //X_top_step.stop();
   //controller.moveAsync(*stepper.motor);
   //pinMode(17, INPUT);
 
@@ -107,8 +119,9 @@ void setup() {
   // analogWrite(peristaltic_pwm_pin, 50);
    // peristaltic.begin(peristaltic_pwm_pin).trigger(peristaltic.EVT_ON);
   // peristaltic.start();
-  peristaltic.begin( peristaltic_pwm_pin ).blink( 2000 ).fade( 50 );
-  peristaltic.start();
+  // peristaltic.begin( peristaltic_pwm_pin, 0, Udp, bndl, "/peristaltic" );
+  // //.brightness( 100 );
+  // peristaltic.blink( 2000 ).start();
 
 
 }
@@ -132,14 +145,17 @@ void loop() {
      if(!msgIn.hasError()){
        Serial.println("got OSC");
        // msgIn.route("/blink", test);
-       X_top_step.onOSC(msgIn);
-       Y_top_step.onOSC(msgIn);
+       X_top_OSC.onOSC(msgIn);
+       // Y_top_step.onOSC(msgIn);
+       // peristaltic.onOSC(msgIn);
      }
 
 
   }
 
 
+
+
   // Serial.print(analogRead(A3));
   // Serial.print("   ");
   // Serial.print(Y_top_step.limitState[0]);

+ 75 - 54
blob-CN/main.pd

@@ -1,26 +1,24 @@
-#N canvas 176 159 1743 541 12;
-#X msg 73 121 disconnect;
-#X obj 329 426 tgl 15 0 empty empty connected 20 7 0 8 -24198 -241291
--1 0 1;
-#X text 25 398 udpsend sends bytes over a udp connection.;
-#X msg 176 224 multicast_interface 192.168.0.88;
-#X msg 151 199 multicast_interface eth1;
-#X text 154 120 <--disconnect before connecting to another address
-;
-#X text 314 150 send to a multicast address;
-#X text 286 175 specify an interface to use with multicast;
-#X msg 128 176 multicast_interface 1;
-#X text 336 198 by index \, name or address;
-#X msg 300 348 multicast_loopback \$1;
-#X obj 300 326 tgl 15 0 empty empty empty 20 7 0 8 -24198 -241291 -1
+#N canvas 57 325 1743 541 12;
+#X msg 73 21 disconnect;
+#X obj 72 426 tgl 15 0 empty empty connected 20 7 0 8 -24198 -241291
+-1 1 1;
+#X msg 176 124 multicast_interface 192.168.0.88;
+#X msg 151 99 multicast_interface eth1;
+#X text 154 20 <--disconnect before connecting to another address;
+#X text 314 50 send to a multicast address;
+#X text 286 75 specify an interface to use with multicast;
+#X msg 128 76 multicast_interface 1;
+#X text 336 98 by index \, name or address;
+#X msg 43 348 multicast_loopback \$1;
+#X obj 43 326 tgl 15 0 empty empty empty 20 7 0 8 -24198 -241291 -1
 0 1;
-#X text 111 324 enable multicast loopback:;
-#X msg 512 310 /lambda;
-#X msg 600 310 /need/reply;
-#X obj 555 215 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+#X text 40 307 enable multicast loopback:;
+#X msg 196 262 /lambda;
+#X msg 284 262 /need/reply;
+#X obj 239 167 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
 1;
-#X msg 552 240 /blink \$1;
-#X msg 569 268 /truc;
+#X msg 236 192 /blink \$1;
+#X msg 253 220 /truc;
 #X floatatom 1309 84 3 0 0 0 - - -;
 #X floatatom 1336 84 3 0 0 0 - - -;
 #X floatatom 1363 84 3 0 0 0 - - -;
@@ -36,47 +34,70 @@
 #X text 1069 60 total bytes received:;
 #X obj 1007 427 spigot;
 #X obj 1046 407 tgl 15 0 empty empty enable_print: -77 8 0 10 -4034
--1 -1 0 1;
+-1 -1 1 1;
 #X obj 1007 452 print received;
 #X obj 1235 33 route received total from multicast;
 #X msg 953 52 port 9998;
 #X obj 943 296 route /analog/0;
-#X obj 330 398 mrpeach/udpsend;
+#X obj 73 398 mrpeach/udpsend;
 #X obj 942 108 mrpeach/unpackOSC;
-#X obj 512 335 mrpeach/packOSC;
-#X msg 103 151 connect 239.200.200.200 9977;
+#X obj 230 380 mrpeach/packOSC;
+#X msg 103 51 connect 239.200.200.200 9977;
 #X obj 942 86 mrpeach/udpreceive 9977 239.200.200.200;
 #X obj 932 356 vsl 15 128 0 1024 0 0 empty empty empty 0 -9 0 10 -262144
 -1 -1 0 1;
-#X connect 0 0 36 0;
-#X connect 3 0 36 0;
-#X connect 4 0 36 0;
-#X connect 8 0 36 0;
-#X connect 10 0 36 0;
-#X connect 11 0 10 0;
-#X connect 13 0 38 0;
-#X connect 14 0 38 0;
-#X connect 15 0 16 0;
-#X connect 16 0 38 0;
-#X connect 17 0 38 0;
-#X connect 23 0 18 0;
-#X connect 23 1 19 0;
-#X connect 23 2 20 0;
-#X connect 23 3 21 0;
-#X connect 23 4 22 0;
-#X connect 24 0 40 0;
-#X connect 30 0 32 0;
-#X connect 31 0 30 1;
-#X connect 33 0 25 0;
-#X connect 33 1 27 0;
-#X connect 33 2 23 0;
-#X connect 33 3 26 0;
+#X obj 230 336 r toOSC;
+#X obj 536 349 s toOSC;
+#X msg 540 224 /X_top/stop;
+#X msg 553 249 /X_top/emergencyStop;
+#X msg 710 227 /Y_top/move 10000;
+#X msg 721 257 /Y_top/stop;
+#X msg 733 282 /Y_top/emergencyStop;
+#X obj 1159 335 list prepend set;
+#X obj 1159 360 list trim;
+#X msg 1159 385 /X_top/move -10000;
+#X msg 563 279 /X_top/home 0;
+#X msg 530 194 /X_top/move -10000;
+#X connect 0 0 35 0;
+#X connect 2 0 35 0;
+#X connect 3 0 35 0;
+#X connect 7 0 35 0;
+#X connect 9 0 35 0;
+#X connect 10 0 9 0;
+#X connect 12 0 37 0;
+#X connect 13 0 37 0;
+#X connect 14 0 15 0;
+#X connect 15 0 37 0;
+#X connect 16 0 37 0;
+#X connect 22 0 17 0;
+#X connect 22 1 18 0;
+#X connect 22 2 19 0;
+#X connect 22 3 20 0;
+#X connect 22 4 21 0;
+#X connect 23 0 39 0;
+#X connect 29 0 31 0;
+#X connect 30 0 29 1;
+#X connect 32 0 24 0;
+#X connect 32 1 26 0;
+#X connect 32 2 22 0;
+#X connect 32 3 25 0;
+#X connect 33 0 39 0;
 #X connect 34 0 40 0;
-#X connect 35 0 41 0;
-#X connect 35 1 30 0;
-#X connect 36 0 1 0;
+#X connect 34 1 29 0;
+#X connect 34 1 48 0;
+#X connect 35 0 1 0;
+#X connect 36 0 34 0;
 #X connect 37 0 35 0;
-#X connect 38 0 36 0;
+#X connect 38 0 35 0;
 #X connect 39 0 36 0;
-#X connect 40 0 37 0;
-#X connect 40 1 33 0;
+#X connect 39 1 32 0;
+#X connect 41 0 37 0;
+#X connect 43 0 42 0;
+#X connect 44 0 42 0;
+#X connect 45 0 42 0;
+#X connect 46 0 42 0;
+#X connect 47 0 42 0;
+#X connect 48 0 49 0;
+#X connect 49 0 50 0;
+#X connect 51 0 42 0;
+#X connect 52 0 42 0;