Sprinter.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
  2. // Licence: GPL
  3. //Check Version of Arduino and then include the right libraries
  4. #if defined(ARDUINO) && ARDUINO >= 100
  5. #include "Arduino.h"
  6. #else
  7. #include <WProgram.h>
  8. #endif
  9. #include "fastio.h"
  10. extern "C" void __cxa_pure_virtual();
  11. #define FORCE_INLINE __attribute__((always_inline)) inline
  12. #if X_ENABLE_PIN > -1
  13. #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
  14. #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
  15. #else
  16. #define enable_x() ;
  17. #define disable_x() ;
  18. #endif
  19. #if Y_ENABLE_PIN > -1
  20. #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
  21. #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
  22. #else
  23. #define enable_y() ;
  24. #define disable_y() ;
  25. #endif
  26. #if Z_ENABLE_PIN > -1
  27. #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
  28. #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
  29. #else
  30. #define enable_z() ;
  31. #define disable_z() ;
  32. #endif
  33. #if E_ENABLE_PIN > -1
  34. #define enable_e() WRITE(E_ENABLE_PIN, E_ENABLE_ON)
  35. #define disable_e() WRITE(E_ENABLE_PIN,!E_ENABLE_ON)
  36. #else
  37. #define enable_e() ;
  38. #define disable_e() ;
  39. #endif
  40. #define X_AXIS 0
  41. #define Y_AXIS 1
  42. #define Z_AXIS 2
  43. #define E_AXIS 3
  44. // This struct is used when buffering the setup for each linear movement "nominal" values are as specified in
  45. // the source g-code and may never actually be reached if acceleration management is active.
  46. typedef struct {
  47. // Fields used by the bresenham algorithm for tracing the line
  48. long steps_x, steps_y, steps_z, steps_e; // Step count along each axis
  49. unsigned long step_event_count; // The number of step events required to complete this block
  50. long accelerate_until; // The index of the step event on which to stop acceleration
  51. long decelerate_after; // The index of the step event on which to start decelerating
  52. long acceleration_rate; // The acceleration rate used for acceleration calculation
  53. unsigned char direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
  54. #ifdef ADVANCE
  55. long advance_rate;
  56. volatile long initial_advance;
  57. volatile long final_advance;
  58. float advance;
  59. #endif
  60. // Fields used by the motion planner to manage acceleration
  61. // float speed_x, speed_y, speed_z, speed_e; // Nominal mm/minute for each axis
  62. float nominal_speed; // The nominal speed for this block in mm/min
  63. float entry_speed; // Entry speed at previous-current junction in mm/min
  64. float max_entry_speed; // Maximum allowable junction entry speed in mm/min
  65. float millimeters; // The total travel of this block in mm
  66. float acceleration; // acceleration mm/sec^2
  67. unsigned char recalculate_flag; // Planner flag to recalculate trapezoids on entry junction
  68. unsigned char nominal_length_flag; // Planner flag for nominal speed always reached
  69. // Settings for the trapezoid generator
  70. long nominal_rate; // The nominal step rate for this block in step_events/sec
  71. long initial_rate; // The jerk-adjusted step rate at start of block
  72. long final_rate; // The minimal rate at exit
  73. long acceleration_st; // acceleration steps/sec^2
  74. volatile char busy;
  75. } block_t;
  76. void FlushSerialRequestResend();
  77. void ClearToSend();
  78. void showString (PGM_P s);
  79. void manage_inactivity(byte debug);
  80. void get_command();
  81. void get_coordinates();
  82. void prepare_move();
  83. void prepare_arc_move(char isclockwise);
  84. FORCE_INLINE void process_commands();
  85. #ifdef USE_ARC_FUNCTION
  86. FORCE_INLINE void get_arc_coordinates();
  87. #endif
  88. void kill(byte debug);
  89. void check_axes_activity();
  90. void plan_init();
  91. void st_init();
  92. void tp_init();
  93. void plan_buffer_line(float x, float y, float z, float e, float feed_rate);
  94. void plan_set_position(float x, float y, float z, float e);
  95. void st_wake_up();
  96. void st_synchronize();
  97. void st_set_position(const long &x, const long &y, const long &z, const long &e);
  98. void check_buffer_while_arc();
  99. #ifdef SDSUPPORT
  100. void print_disk_info(void);
  101. #endif //SDSUPPORT
  102. #ifdef DEBUG
  103. void log_message(char* message);
  104. void log_bool(char* message, bool value);
  105. void log_int(char* message, int value);
  106. void log_long(char* message, long value);
  107. void log_float(char* message, float value);
  108. void log_uint(char* message, unsigned int value);
  109. void log_ulong(char* message, unsigned long value);
  110. #endif