#pragma once #include //#include #include 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 ENABLED DISABLED RUNNING DISABLED MOVE_TIMEOUT EMERGENCY EMERGENCY EMERGENCY STOPPING ENABLED RUNNING EMERGENCY EMERGENCY EMERGENCY RUNNING MOVE_TIMEOUT ENABLED ENABLED EMERGENCY STOPPING MOVE_TIMEOUT MOVE_TIMEOUT Automaton::ATML::end */