Atm_Teenstep.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #pragma once
  2. #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
  3. #ifdef TEENSYSTEP_H
  4. #include <Automaton.h>
  5. #include <TeensyStep.h>
  6. class Atm_Teenstep: public Machine {
  7. public:
  8. enum { DISABLED, ENABLED, RUNNING, STOPPING, EMERGENCY_STOP, HOMING_HIGH, HOMING_LOW }; // STATES
  9. 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
  10. Atm_Teenstep( void ) : Machine() {};
  11. Atm_Teenstep& begin( Stepper & motorRef, StepControl & stepControlRef );
  12. Atm_Teenstep& trace( Stream & stream );
  13. Atm_Teenstep& trigger( int event );
  14. int state( void );
  15. Atm_Teenstep& onChange( Machine& machine, int event = 0 );
  16. Atm_Teenstep& onChange( atm_cb_push_t callback, int idx = 0 );
  17. Atm_Teenstep& onChangeposition( Machine& machine, int event = 0 );
  18. Atm_Teenstep& onChangeposition( atm_cb_push_t callback, int idx = 0 );
  19. Atm_Teenstep& onLimithigh( Machine& machine, int event = 0 );
  20. Atm_Teenstep& onLimithigh( atm_cb_push_t callback, int idx = 0 );
  21. Atm_Teenstep& onLimitlow( Machine& machine, int event = 0 );
  22. Atm_Teenstep& onLimitlow( atm_cb_push_t callback, int idx = 0 );
  23. Atm_Teenstep& homing_low( void );
  24. Atm_Teenstep& homing_high( void );
  25. Atm_Teenstep& move_timeout( void );
  26. Atm_Teenstep& limit_high( void );
  27. Atm_Teenstep& limit_low( void );
  28. Atm_Teenstep& emergencystop( void );
  29. Atm_Teenstep& stop( void );
  30. Atm_Teenstep& ontarget( void );
  31. Atm_Teenstep& move( void );
  32. Atm_Teenstep& disable( void );
  33. Atm_Teenstep& enable( void );
  34. Atm_Teenstep& move( long int stepRel );
  35. Atm_Teenstep& moveTo( long int stepAbs );
  36. Atm_Teenstep& homing( bool direction );
  37. Atm_Teenstep& setLimitType( int limitType = 0);
  38. Atm_Teenstep& setLimitPins( int limitPinLow);
  39. Atm_Teenstep& setLimitPins( int limitPinLow, int limitPinHigh);
  40. Atm_Teenstep& limitReversed( bool reversed );
  41. Atm_Teenstep& limitThresholds( int limitThreshold0, int limitThreshold1,
  42. int limitThreshold2, int limitThreshold3);
  43. bool limitState[2] ; // up to two limits, at least one for homing
  44. virtual Atm_Teenstep& onOSC( void );
  45. virtual Atm_Teenstep& sendOSC( void );
  46. Stepper * motor;
  47. StepControl * controller;
  48. Atm_Teenstep& setEnablePin( int enablePin );
  49. Atm_Teenstep& enableReversed( bool reverse );
  50. bool enabled ;
  51. private:
  52. 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
  53. enum { ON_CHANGE, ON_CHANGEPOSITION, ON_LIMITHIGH, ON_LIMITLOW, CONN_MAX }; // CONNECTORS
  54. atm_connector connectors[CONN_MAX];
  55. int event( int id );
  56. void action( int id );
  57. atm_timer_millis idle_timer ;
  58. int IDLE_TIMEOUT_DURATION = 500000 ;
  59. atm_timer_millis moving_timer ;
  60. int MOVING_TIMEOUT_DURATION = 12000000 ;
  61. atm_counter homing_counterout ;
  62. long int _currentStep = 0;
  63. long int _targetStep = 0;
  64. long int _maxStep ;
  65. int _enablePin = -1;
  66. bool _enableReversed = 0 ;
  67. int _limitPin[2];
  68. enum { NONE, DIGITAL_1, DIGITAL_2, ANALOG_1 };
  69. int _limitType; //type of limit switch, from list over
  70. bool _limitReversed ; //invert logic of limit switches
  71. int _limitThresholds[4] ; //analog value range for two analog limits
  72. void updateLimitSwitch();
  73. };
  74. #endif
  75. #endif
  76. /*
  77. Automaton::ATML::begin - Automaton Markup Language
  78. <?xml version="1.0" encoding="UTF-8"?>
  79. <machines>
  80. <machine name="Atm_Teenstep">
  81. <states>
  82. <DISABLED index="0" on_enter="ENT_DISABLED">
  83. <EVT_ENABLE>ENABLED</EVT_ENABLE>
  84. </DISABLED>
  85. <ENABLED index="1" on_enter="ENT_ENABLED">
  86. <EVT_MOVE>RUNNING</EVT_MOVE>
  87. <EVT_DISABLE>DISABLED</EVT_DISABLE>
  88. </ENABLED>
  89. <RUNNING index="2" on_enter="ENT_RUNNING" on_loop="LP_RUNNING">
  90. <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
  91. <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
  92. <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
  93. <EVT_STOP>STOPPING</EVT_STOP>
  94. <EVT_ONTARGET>ENABLED</EVT_ONTARGET>
  95. <EVT_MOVE>RUNNING</EVT_MOVE>
  96. </RUNNING>
  97. <STOPPING index="3" on_enter="ENT_STOPPING">
  98. <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
  99. <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
  100. <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
  101. <EVT_MOVE>RUNNING</EVT_MOVE>
  102. </STOPPING>
  103. <EMERGENCY_STOP index="4" on_enter="ENT_EMERGENCY_STOP">
  104. <EVT_MOVE>RUNNING</EVT_MOVE>
  105. <EVT_ENABLE>ENABLED</EVT_ENABLE>
  106. </EMERGENCY_STOP>
  107. <HOMING_HIGH index="5" on_enter="ENT_HOMING_HIGH" on_exit="EXT_HOMING_HIGH">
  108. <EVT_LIMIT_HIGH>ENABLED</EVT_LIMIT_HIGH>
  109. <EVT_LIMIT_LOW>EMERGENCY_STOP</EVT_LIMIT_LOW>
  110. <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
  111. <EVT_STOP>STOPPING</EVT_STOP>
  112. </HOMING_HIGH>
  113. <HOMING_LOW index="6" on_enter="ENT_HOMING_LOW" on_exit="EXT_HOMING_LOW">
  114. <EVT_LIMIT_HIGH>EMERGENCY_STOP</EVT_LIMIT_HIGH>
  115. <EVT_LIMIT_LOW>ENABLED</EVT_LIMIT_LOW>
  116. <EVT_EMERGENCYSTOP>EMERGENCY_STOP</EVT_EMERGENCYSTOP>
  117. <EVT_STOP>STOPPING</EVT_STOP>
  118. </HOMING_LOW>
  119. </states>
  120. <events>
  121. <EVT_MOVE_TIMEOUT index="0" access="MIXED"/>
  122. <EVT_LIMIT_HIGH index="1" access="MIXED"/>
  123. <EVT_LIMIT_LOW index="2" access="MIXED"/>
  124. <EVT_EMERGENCYSTOP index="3" access="MIXED"/>
  125. <EVT_STOP index="4" access="MIXED"/>
  126. <EVT_ONTARGET index="5" access="MIXED"/>
  127. <EVT_MOVE index="6" access="MIXED"/>
  128. <EVT_DISABLE index="7" access="MIXED"/>
  129. <EVT_ENABLE index="8" access="MIXED"/>
  130. </events>
  131. <connectors>
  132. <CHANGE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
  133. <CHANGEPOSITION autostore="0" broadcast="0" dir="PUSH" slots="1"/>
  134. <LIMITHIGH autostore="0" broadcast="0" dir="PUSH" slots="1"/>
  135. <LIMITLOW autostore="0" broadcast="0" dir="PUSH" slots="1"/>
  136. </connectors>
  137. <methods>
  138. </methods>
  139. </machine>
  140. </machines>
  141. Automaton::ATML::end
  142. */