Bladeren bron

seems to work commit

global behaviour seems correct, ready for a release ?
titi 5 jaren geleden
bovenliggende
commit
35bd2f47b8
8 gewijzigde bestanden met toevoegingen van 130 en 83 verwijderingen
  1. 28 7
      Atm_AccelStepper.cpp
  2. 9 7
      Atm_AccelStepper.h
  3. 4 0
      Atm_Teenstep.cpp
  4. 73 69
      Atm_Teenstep.h
  5. 4 0
      Atm_Teenstep_OSC.cpp
  6. 4 0
      Atm_Teenstep_OSC.h
  7. 4 0
      Atm_out.cpp
  8. 4 0
      Atm_out.h

+ 28 - 7
Atm_AccelStepper.cpp

@@ -24,6 +24,7 @@ Atm_AccelStepper& Atm_AccelStepper::begin(int step_pin, int dir_pin) {
   stepper->setAcceleration(acceleration);
   idle_timer.set(ATM_TIMER_OFF);
   position_timer.set(POSITION_SEND_TIMER);
+
   return *this;
 }
 
@@ -49,8 +50,6 @@ int Atm_AccelStepper::event( int id ) {
     case EVT_ON_LIMIT_LOW:
       switch(_limitLow_Mode) {
         case 0:
-          //
-          Serial.println("no limit");
           return 0;
         case 1: //digital INPUT
           // Serial.println("digital");
@@ -62,6 +61,9 @@ int Atm_AccelStepper::event( int id ) {
           int analogTemp = analogRead(_limitLow_Pin);
           limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
           limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
+          if(limitLow_State){analogTemp = analogRead(_limitLow_Pin);
+          limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
+          limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;}
           return limitLow_State;
       }
     case EVT_ON_LIMIT_HIGH:
@@ -120,6 +122,7 @@ void Atm_AccelStepper::action( int id ) {
     case ENT_RUNNING:
       push(connectors, ON_CHANGESTATE, 0,  state(), 0);
       _isHoming = 0;
+      stepper->moveTo(_targetStep);
       //push(connectors, ON_CHANGEPOSITION, 0,  _currentStep, stepper->speed());
       position_timer.setFromNow(this, POSITION_SEND_TIMER);
       return;
@@ -156,6 +159,9 @@ void Atm_AccelStepper::action( int id ) {
       stepper_update();
       return;
     case EXT_HOMING_LOW:
+      runMode = 0;
+      _isHoming = 0;
+      trigger(EVT_EMERGENCY_STOP);
       if(last_trigger == EVT_ON_LIMIT_LOW) {
         stepper->setCurrentPosition(0);
         _currentStep = 0;
@@ -175,6 +181,9 @@ void Atm_AccelStepper::action( int id ) {
       stepper_update();
       return;
     case EXT_HOMING_HIGH:
+      runMode = 0;
+      _isHoming = 0;
+      trigger(EVT_EMERGENCY_STOP);
       if(last_trigger == EVT_ON_LIMIT_HIGH) {
         _maxStep = stepper->currentPosition();
         _currentStep = _maxStep;
@@ -186,8 +195,8 @@ void Atm_AccelStepper::action( int id ) {
     case ENT_LIMIT_LOW:
       push( connectors, ON_ONLIMITLOW, 0, 0, 0 );
       //stop motor if going down, allow going up
-      if(_limitLow_Hard && (stepper->speed()<0) ) {trigger(EVT_EMERGENCY_STOP);}
-      else{ stepper_update(); _isHoming ? trigger(EVT_ENABLE):trigger(EVT_MOVE);}
+      if(_limitLow_Hard && (stepper->speed()<=0) ) {trigger(EVT_EMERGENCY_STOP);}
+      else{ stepper_update();trigger(EVT_MOVE);} // _isHoming ? trigger(EVT_STOP):
        //   switch(_isHoming) {
        //     case 0 :
        //      trigger(EVT_MOVE);
@@ -203,8 +212,8 @@ void Atm_AccelStepper::action( int id ) {
       return;
     case ENT_LIMIT_HIGH:
       push( connectors, ON_ONLIMITHIGH, 0, 1, 0 );
-      if(_limitHigh_Hard && (stepper->speed()>0)) {trigger(EVT_EMERGENCY_STOP);}
-      else{ stepper_update(); _isHoming ? trigger(EVT_ENABLE):trigger(EVT_MOVE);}
+      if(_limitHigh_Hard && (stepper->speed()>=0)) {trigger(EVT_EMERGENCY_STOP);}
+      else{ stepper_update(); trigger(EVT_MOVE);} //_isHoming ? trigger(EVT_STOP):
        //  stepper_update();
        //   switch(_isHoming) {
        //     case 0 :
@@ -248,6 +257,7 @@ int Atm_AccelStepper::state( void ) {
 
 void Atm_AccelStepper::stepper_update(void) {
   switch (runMode) {
+    Serial.println(stepper->currentPosition());
     case 0: //positional modae
       stepper->run();
       break;
@@ -260,6 +270,7 @@ void Atm_AccelStepper::stepper_update(void) {
     _currentStep =  tempStep;
     if (position_timer.expired(this)){
       push(connectors, ON_CHANGEPOSITION, 0,  _currentStep, stepper->speed());
+      //Serial.println(stepper->currentPosition());
       position_timer.setFromNow(this, POSITION_SEND_TIMER);
     }
   }
@@ -278,10 +289,20 @@ Atm_AccelStepper& Atm_AccelStepper::setHomingSpeed(long int homingSpeed){
 
 Atm_AccelStepper& Atm_AccelStepper::setAcceleration(long int acc){
   acceleration = acc ;
-  stepper->setAcceleration(max_speed);
+  stepper->setAcceleration(acceleration);
   return *this ;
 }
 
+Atm_AccelStepper& Atm_AccelStepper::setPosition(long int position){
+  stepper->setCurrentPosition(position);
+  _currentStep = position ;
+  return *this ;
+}
+
+long int Atm_AccelStepper::getPosition(){
+  return stepper->currentPosition();;
+}
+
 Atm_AccelStepper& Atm_AccelStepper::position_refresh(long int refresh_ms){
   POSITION_SEND_TIMER = refresh_ms ;
   return *this ;

+ 9 - 7
Atm_AccelStepper.h

@@ -43,11 +43,13 @@ class Atm_AccelStepper: public Machine {
   AccelStepper *stepper;
 
   long int homing_speed = 100;
-  long int max_speed = 5000;
+  long int max_speed = 10000;
   long int acceleration = 1000;
-  Atm_AccelStepper& setMaxSpeed( long int maxSpeed = 5000);
-  Atm_AccelStepper& setHomingSpeed( long int homingSpeed = 400);
-  Atm_AccelStepper& setAcceleration( long int acc = 1000);
+  Atm_AccelStepper& setMaxSpeed( long int maxSpeed );
+  Atm_AccelStepper& setHomingSpeed( long int homingSpeed);
+  Atm_AccelStepper& setAcceleration( long int acc);
+  Atm_AccelStepper& setPosition( long int position);
+  long int getPosition();
 
   Atm_AccelStepper& move(long int stepRel );
   Atm_AccelStepper& moveTo(long int stepAbs );
@@ -100,12 +102,12 @@ class Atm_AccelStepper: public Machine {
   int _limitLow_Mode = 0; //0 no limit, 1 digital, 2 analog with thresholds
   bool _limitLow_Reversed ; //invert logic of limit switches
   int _limitLow_Thresholds[2] ; //analog value  range for two analog limits
-  bool _limitLow_Hard = 1;
+  bool _limitLow_Hard = 0;
   int _limitHigh_Pin;
-  int _limitHigh_Mode; //0 no limit, 1 digital, 2 analog with thresholds
+  int _limitHigh_Mode=0; //0 no limit, 1 digital, 2 analog with thresholds
   bool _limitHigh_Reversed ; //invert logic of limit switches
   int _limitHigh_Thresholds[2] ; //analog value  range for two analog limits
-  bool _limitHigh_Hard = 1 ;
+  bool _limitHigh_Hard = 0 ;
   int _isHoming = 0 ;
   void updateLimitSwitch();
 

+ 4 - 0
Atm_Teenstep.cpp

@@ -1,3 +1,5 @@
+#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
+
 #include "Atm_Teenstep.h"
 
 /* Add optional parameters for the state machine to begin()
@@ -410,3 +412,5 @@ Atm_Teenstep& Atm_Teenstep::onLimitlow( atm_cb_push_t callback, int idx ) {
      "TEENSTEP\0EVT_HOMING_LOW\0EVT_HOMING_HIGH\0EVT_MOVE_TIMEOUT\0EVT_LIMIT_HIGH\0EVT_LIMIT_LOW\0EVT_EMERGENCYSTOP\0EVT_STOP\0EVT_ONTARGET\0EVT_MOVE\0EVT_DISABLE\0EVT_ENABLE\0ELSE\0DISABLED\0ENABLED\0RUNNING\0STOPPING\0EMERGENCY_STOP\0HOMING_HIGH\0HOMING_LOW" );
    return *this;
  }
+
+#endif

+ 73 - 69
Atm_Teenstep.h

@@ -1,5 +1,7 @@
 #pragma once
 
+#if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
+
 #include <Automaton.h>
 #include <TeensyStep.h>
 
@@ -86,72 +88,74 @@ class Atm_Teenstep: public Machine {
   void updateLimitSwitch();
 };
 
-/*
-Automaton::ATML::begin - Automaton Markup Language
-
-<?xml version="1.0" encoding="UTF-8"?>
-<machines>
-  <machine name="Atm_Teenstep">
-    <states>
-      <DISABLED index="0" on_enter="ENT_DISABLED">
-        <EVT_ENABLE>ENABLED</EVT_ENABLE>
-      </DISABLED>
-      <ENABLED index="1" on_enter="ENT_ENABLED">
-        <EVT_MOVE>RUNNING</EVT_MOVE>
-        <EVT_DISABLE>DISABLED</EVT_DISABLE>
-      </ENABLED>
-      <RUNNING index="2" on_enter="ENT_RUNNING" on_loop="LP_RUNNING">
-        <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
-        <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
-        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
-        <EVT_STOP>STOPPING</EVT_STOP>
-        <EVT_ONTARGET>ENABLED</EVT_ONTARGET>
-        <EVT_MOVE>RUNNING</EVT_MOVE>
-      </RUNNING>
-      <STOPPING index="3" on_enter="ENT_STOPPING">
-        <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
-        <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
-        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
-        <EVT_MOVE>RUNNING</EVT_MOVE>
-      </STOPPING>
-      <EMERGENCY_STOP index="4" on_enter="ENT_EMERGENCY_STOP">
-        <EVT_MOVE>RUNNING</EVT_MOVE>
-        <EVT_ENABLE>ENABLED</EVT_ENABLE>
-      </EMERGENCY_STOP>
-      <HOMING_HIGH index="5" on_enter="ENT_HOMING_HIGH" on_exit="EXT_HOMING_HIGH">
-        <EVT_LIMIT_HIGH>ENABLED</EVT_LIMIT_HIGH>
-        <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
-        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
-        <EVT_STOP>STOPPING</EVT_STOP>
-      </HOMING_HIGH>
-      <HOMING_LOW index="6" on_enter="ENT_HOMING_LOW" on_exit="EXT_HOMING_LOW">
-        <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
-        <EVT_LIMIT_LOW>ENABLED</EVT_LIMIT_LOW>
-        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
-        <EVT_STOP>STOPPING</EVT_STOP>
-      </HOMING_LOW>
-    </states>
-    <events>
-      <EVT_MOVE_TIMEOUT index="0" access="MIXED"/>
-      <EVT_LIMIT_HIGH index="1" access="MIXED"/>
-      <EVT_LIMIT_LOW index="2" access="MIXED"/>
-      <EVT_EMERGENCYSTOP index="3" access="MIXED"/>
-      <EVT_STOP index="4" access="MIXED"/>
-      <EVT_ONTARGET index="5" access="MIXED"/>
-      <EVT_MOVE index="6" access="MIXED"/>
-      <EVT_DISABLE index="7" access="MIXED"/>
-      <EVT_ENABLE index="8" access="MIXED"/>
-    </events>
-    <connectors>
-      <CHANGE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
-      <CHANGEPOSITION autostore="0" broadcast="0" dir="PUSH" slots="1"/>
-      <LIMITHIGH autostore="0" broadcast="0" dir="PUSH" slots="1"/>
-      <LIMITLOW autostore="0" broadcast="0" dir="PUSH" slots="1"/>
-    </connectors>
-    <methods>
-    </methods>
-  </machine>
-</machines>
-
-Automaton::ATML::end
-*/
+#endif
+
+/*
+Automaton::ATML::begin - Automaton Markup Language
+
+<?xml version="1.0" encoding="UTF-8"?>
+<machines>
+  <machine name="Atm_Teenstep">
+    <states>
+      <DISABLED index="0" on_enter="ENT_DISABLED">
+        <EVT_ENABLE>ENABLED</EVT_ENABLE>
+      </DISABLED>
+      <ENABLED index="1" on_enter="ENT_ENABLED">
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+        <EVT_DISABLE>DISABLED</EVT_DISABLE>
+      </ENABLED>
+      <RUNNING index="2" on_enter="ENT_RUNNING" on_loop="LP_RUNNING">
+        <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
+        <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
+        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
+        <EVT_STOP>STOPPING</EVT_STOP>
+        <EVT_ONTARGET>ENABLED</EVT_ONTARGET>
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+      </RUNNING>
+      <STOPPING index="3" on_enter="ENT_STOPPING">
+        <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
+        <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
+        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+      </STOPPING>
+      <EMERGENCY_STOP index="4" on_enter="ENT_EMERGENCY_STOP">
+        <EVT_MOVE>RUNNING</EVT_MOVE>
+        <EVT_ENABLE>ENABLED</EVT_ENABLE>
+      </EMERGENCY_STOP>
+      <HOMING_HIGH index="5" on_enter="ENT_HOMING_HIGH" on_exit="EXT_HOMING_HIGH">
+        <EVT_LIMIT_HIGH>ENABLED</EVT_LIMIT_HIGH>
+        <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
+        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
+        <EVT_STOP>STOPPING</EVT_STOP>
+      </HOMING_HIGH>
+      <HOMING_LOW index="6" on_enter="ENT_HOMING_LOW" on_exit="EXT_HOMING_LOW">
+        <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
+        <EVT_LIMIT_LOW>ENABLED</EVT_LIMIT_LOW>
+        <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
+        <EVT_STOP>STOPPING</EVT_STOP>
+      </HOMING_LOW>
+    </states>
+    <events>
+      <EVT_MOVE_TIMEOUT index="0" access="MIXED"/>
+      <EVT_LIMIT_HIGH index="1" access="MIXED"/>
+      <EVT_LIMIT_LOW index="2" access="MIXED"/>
+      <EVT_EMERGENCYSTOP index="3" access="MIXED"/>
+      <EVT_STOP index="4" access="MIXED"/>
+      <EVT_ONTARGET index="5" access="MIXED"/>
+      <EVT_MOVE index="6" access="MIXED"/>
+      <EVT_DISABLE index="7" access="MIXED"/>
+      <EVT_ENABLE index="8" access="MIXED"/>
+    </events>
+    <connectors>
+      <CHANGE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <CHANGEPOSITION autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <LIMITHIGH autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+      <LIMITLOW autostore="0" broadcast="0" dir="PUSH" slots="1"/>
+    </connectors>
+    <methods>
+    </methods>
+  </machine>
+</machines>
+
+Automaton::ATML::end
+*/

+ 4 - 0
Atm_Teenstep_OSC.cpp

@@ -1,3 +1,5 @@
+#ifdef ATM_TEENSTEP_OSC_H
+
 #include "Atm_Teenstep_OSC.h"
 
 Atm_Teenstep_OSC& Atm_Teenstep_OSC::begin(Atm_Teenstep& stepperMachineRef, EthernetUDP& udpRef, OSCBundle& bndl, const char* address) {
@@ -34,3 +36,5 @@ Atm_Teenstep_OSC& Atm_Teenstep_OSC::onOSC(OSCMessage& msg ){
 void Atm_Teenstep_OSC::sendPosition(int idx, int v, int up) {
   _bndl->add(_adress).add(v);
 }
+
+#endif

+ 4 - 0
Atm_Teenstep_OSC.h

@@ -1,5 +1,7 @@
 #pragma once
 
+#ifdef ATM_TEENSTEP_OSC_H
+
 #include "Atm_Teenstep.h"
 
 #include <EthernetUdp.h>
@@ -29,3 +31,5 @@ class Atm_Teenstep_OSC {
    OSCBundle* _bndl;
 
 };
+
+#endif

+ 4 - 0
Atm_out.cpp

@@ -1,3 +1,5 @@
+#if not defined(ARDUINO_ARCH_ESP32) 
+
 #include "Atm_out.h"
 
 Atm_out& Atm_out::begin( int attached_pin, bool activeLow,
@@ -258,3 +260,5 @@ Atm_out& Atm_out::trace( Stream& stream ) {
             "IDLE\0ON\0START\0BLINK_OFF\0LOOP\0DONE\0OFF\0WT_ON\0WT_START" );
   return *this;
 }
+
+#endif

+ 4 - 0
Atm_out.h

@@ -1,5 +1,7 @@
 #pragma once
 
+#if not defined(ARDUINO_ARCH_ESP32) 
+
 #include <Automaton.h>
 
 #include <EthernetUdp.h>
@@ -65,3 +67,5 @@ class Atm_out : public Machine {
   int event( int id );
   void action( int id );
 };
+
+#endif