la10compat.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "la10compat.h"
  2. #include "Marlin.h"
  3. static LA10C_MODE la10c_mode = LA10C_UNKNOWN; // Current LA compatibility mode
  4. static float la10c_orig_jerk = 0; // Unadjusted/saved e-jerk
  5. LA10C_MODE la10c_mode_get()
  6. {
  7. return la10c_mode;
  8. }
  9. void la10c_mode_change(LA10C_MODE mode)
  10. {
  11. if(mode == la10c_mode) return;
  12. // always restore to the last unadjusted E-jerk value
  13. if(la10c_orig_jerk)
  14. cs.max_jerk[E_AXIS] = la10c_orig_jerk;
  15. SERIAL_ECHOPGM("LA10C: Linear Advance mode: ");
  16. switch(mode)
  17. {
  18. case LA10C_UNKNOWN: SERIAL_ECHOLNPGM("UNKNOWN"); break;
  19. case LA10C_LA15: SERIAL_ECHOLNPGM("1.5"); break;
  20. case LA10C_LA10: SERIAL_ECHOLNPGM("1.0"); break;
  21. }
  22. la10c_mode = mode;
  23. // adjust the E-jerk if needed
  24. cs.max_jerk[E_AXIS] = la10c_jerk(cs.max_jerk[E_AXIS]);
  25. }
  26. // Approximate a LA10 value to a LA15 equivalent.
  27. static float la10c_convert(float k)
  28. {
  29. float new_K = k * 0.004 - 0.05;
  30. return (new_K < 0? 0: new_K);
  31. }
  32. float la10c_value(float k)
  33. {
  34. if(la10c_mode == LA10C_UNKNOWN)
  35. {
  36. // do not autodetect until a valid value is seen
  37. if(k == 0)
  38. return 0;
  39. else if(k < 0)
  40. return -1;
  41. la10c_mode_change(k < 10? LA10C_LA15: LA10C_LA10);
  42. }
  43. if(la10c_mode == LA10C_LA15)
  44. return (k >= 0 && k < 10? k: -1);
  45. else
  46. return (k >= 0? la10c_convert(k): -1);
  47. }
  48. float la10c_jerk(float j)
  49. {
  50. la10c_orig_jerk = j;
  51. if(la10c_mode != LA10C_LA10)
  52. return j;
  53. // check for a compatible range of values prior to convert (be sure that
  54. // a higher E-jerk would still be compatible wrt the E accell range)
  55. if(j < 4.5 && cs.max_acceleration_units_per_sq_second_normal[E_AXIS] < 2000)
  56. return j;
  57. // bring low E-jerk values into equivalent LA 1.5 values by
  58. // flattening the response in the (1-4.5) range using a piecewise
  59. // function. Is it truly worth to preserve the difference between
  60. // 1.5/2.5 E-jerk for LA1.0? Probably not, but we try nonetheless.
  61. j = j < 1.0? j * 3.625:
  62. j < 4.5? j * 0.25 + 3.375:
  63. j;
  64. SERIAL_ECHOPGM("LA10C: Adjusted E-Jerk: ");
  65. SERIAL_ECHOLN(j);
  66. return j;
  67. }