123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #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
- */
|