#pragma once #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #ifdef ATM_TEENSTEP_H #include <Automaton.h> #include <TeensyStep.h> class Atm_Teenstep: public Machine { public: enum { DISABLED, ENABLED, RUNNING, STOPPING, EMERGENCY_STOP, HOMING_HIGH, HOMING_LOW }; // STATES enum { EVT_HOMING_LOW, EVT_HOMING_HIGH, EVT_MOVE_TIMEOUT, EVT_LIMIT_HIGH, EVT_LIMIT_LOW, EVT_EMERGENCYSTOP, EVT_STOP, EVT_ONTARGET, EVT_MOVE, EVT_DISABLE, EVT_ENABLE, ELSE }; // EVENTS Atm_Teenstep( void ) : Machine() {}; Atm_Teenstep& begin( Stepper & motorRef, StepControl & stepControlRef ); Atm_Teenstep& trace( Stream & stream ); Atm_Teenstep& trigger( int event ); int state( void ); Atm_Teenstep& onChange( Machine& machine, int event = 0 ); Atm_Teenstep& onChange( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& onChangeposition( Machine& machine, int event = 0 ); Atm_Teenstep& onChangeposition( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& onLimithigh( Machine& machine, int event = 0 ); Atm_Teenstep& onLimithigh( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& onLimitlow( Machine& machine, int event = 0 ); Atm_Teenstep& onLimitlow( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& homing_low( void ); Atm_Teenstep& homing_high( void ); Atm_Teenstep& move_timeout( void ); Atm_Teenstep& limit_high( void ); Atm_Teenstep& limit_low( void ); Atm_Teenstep& emergencystop( void ); Atm_Teenstep& stop( void ); Atm_Teenstep& ontarget( void ); Atm_Teenstep& move( void ); Atm_Teenstep& disable( void ); Atm_Teenstep& enable( void ); Atm_Teenstep& move( long int stepRel ); Atm_Teenstep& moveTo( long int stepAbs ); Atm_Teenstep& homing( bool direction ); Atm_Teenstep& setLimitType( int limitType = 0); Atm_Teenstep& setLimitPins( int limitPinLow); Atm_Teenstep& setLimitPins( int limitPinLow, int limitPinHigh); Atm_Teenstep& limitReversed( bool reversed ); Atm_Teenstep& limitThresholds( int limitThreshold0, int limitThreshold1, int limitThreshold2, int limitThreshold3); bool limitState[2] ; // up to two limits, at least one for homing virtual Atm_Teenstep& onOSC( void ); virtual Atm_Teenstep& sendOSC( void ); Stepper * motor; StepControl * controller; Atm_Teenstep& setEnablePin( int enablePin ); Atm_Teenstep& enableReversed( bool reverse ); bool enabled ; private: enum { ENT_DISABLED, ENT_ENABLED, ENT_RUNNING, LP_RUNNING, ENT_STOPPING, ENT_EMERGENCY_STOP, ENT_HOMING_HIGH, EXT_HOMING_HIGH, ENT_HOMING_LOW, EXT_HOMING_LOW }; // ACTIONS enum { ON_CHANGE, ON_CHANGEPOSITION, ON_LIMITHIGH, ON_LIMITLOW, 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 = 0; long int _targetStep = 0; long int _maxStep ; 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(); }; #endif #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 */