Atm_TeensyStep.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include <Automaton.h>
  3. #include <TeensyStep.h>
  4. #include <EthernetUdp.h>
  5. #include <OSCMessage.h>
  6. #include <OSCBundle.h>
  7. // #include <AccelStepper.h>
  8. class Atm_TeensyStep: public Machine {
  9. public:
  10. enum { IDLE, READY, RUNNING, STOPPING }; // STATES
  11. enum { EVT_IDLE_TIMER, EVT_ON_TARGET, EVT_GOTO, ELSE }; // EVENTS
  12. Atm_TeensyStep( void ) : Machine() {};
  13. Atm_TeensyStep& begin( Stepper & motorRef, StepControl & stepControlRef,
  14. EthernetUDP& udpRef, OSCBundle& bndl, const char* address ) ;
  15. Atm_TeensyStep& trace( Stream & stream );
  16. Atm_TeensyStep& trigger( int event );
  17. int state( void );
  18. Atm_TeensyStep& onOnchange( Machine& machine, int event = 0 );
  19. Atm_TeensyStep& onOnchange( atm_cb_push_t callback, int idx = 0 );
  20. int enable_timeout; //in idle mode, how long before sleep (stepper disabled
  21. Atm_TeensyStep& setLimitType( int limitType = 0);
  22. Atm_TeensyStep& setLimitPins( int limitPinLow);
  23. Atm_TeensyStep& setLimitPins( int limitPinLow, int limitPinHigh);
  24. Atm_TeensyStep& limitReversed( bool reversed );
  25. Atm_TeensyStep& limitThresholds( int limitThreshold0, int limitThreshold1,
  26. int limitThreshold2, int limitThreshold3);
  27. Atm_TeensyStep& setEnablePin( int enablePin );
  28. Atm_TeensyStep& enableReversed( bool reverse );
  29. bool enabled ;
  30. Atm_TeensyStep& enable( bool enable );
  31. Atm_TeensyStep& home( bool limit ); // 0(default) for home, 1 for max value
  32. Atm_TeensyStep& move( long int stepRel );
  33. Atm_TeensyStep& moveTo( long int stepAbs );
  34. Atm_TeensyStep& stop();
  35. Atm_TeensyStep& emergencyStop();
  36. Stepper * motor;
  37. StepControl * controller;
  38. bool limitState[2] ; // up to two limits, at least one for homing
  39. bool homed; //stepper has been homed
  40. long int maxStep ;
  41. const char* _adress = "/OSC";
  42. EthernetUDP* _udpRef ;
  43. Atm_TeensyStep& onOSC(OSCMessage& msg );
  44. private:
  45. // AccelStepper _motor;
  46. // Stepper *_motor; // STEP pin: 2, DIR pin: 3
  47. // StepControl _controller;
  48. OSCBundle* _bndl;
  49. enum { ENT_IDLE, EXT_IDLE, ENT_READY, ENT_RUNNING, LP_RUNNING,
  50. ENT_STOPPING, EXT_STOPPING }; // ACTIONS
  51. enum { ON_ONCHANGE, CONN_MAX }; // CONNECTORS
  52. atm_connector connectors[CONN_MAX];
  53. int event( int id );
  54. void action( int id );
  55. long int _currentStep ;
  56. long int _targetStep ;
  57. int _enablePin;
  58. bool _enableReversed ;
  59. int _limitPin[2];
  60. enum { NONE, DIGITAL_1, DIGITAL_2, ANALOG_1 };
  61. int _limitType; //type of limit switch, from list over
  62. bool _limitReversed ; //invert logic of limit switches
  63. int _limitThresholds[4] ; //analog value range for two analog limits
  64. void updateLimitSwitch();
  65. bool _isHoming;
  66. };
  67. /*
  68. Automaton::ATML::begin - Automaton Markup Language
  69. <?xml version="1.0" encoding="UTF-8"?>
  70. <machines>
  71. <machine name="Atm_stepper">
  72. <states>
  73. <IDLE index="0" on_enter="ENT_IDLE">
  74. <EVT_GOTO>RUNNING</EVT_GOTO>
  75. </IDLE>
  76. <READY index="1" on_enter="ENT_READY">
  77. <EVT_IDLE_TIMER>IDLE</EVT_IDLE_TIMER>
  78. <EVT_GOTO>RUNNING</EVT_GOTO>
  79. </READY>
  80. <RUNNING index="2" on_enter="ENT_RUNNING" on_loop="LP_RUNNING">
  81. <EVT_ON_TARGET>STOPPING</EVT_ON_TARGET>
  82. <EVT_GOTO>RUNNING</EVT_GOTO>
  83. </RUNNING>
  84. <STOPPING index="3" on_enter="ENT_STOPPING" on_exit="EXT_STOPPING">
  85. <EVT_ON_TARGET>READY</EVT_ON_TARGET>
  86. </STOPPING>
  87. </states>
  88. <events>
  89. <EVT_IDLE_TIMER index="0" access="PRIVATE"/>
  90. <EVT_ON_TARGET index="1" access="PRIVATE"/>
  91. <EVT_GOTO index="2" access="PUBLIC"/>
  92. </events>
  93. <connectors>
  94. <ONCHANGE autostore="0" broadcast="0" dir="PUSH" slots="1"/>
  95. </connectors>
  96. <methods>
  97. </methods>
  98. </machine>
  99. </machines>
  100. Automaton::ATML::end
  101. */