瀏覽代碼

Fix JD LUT math & bugs (#18175)

XDA-Bam 4 年之前
父節點
當前提交
a0b27e6702
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 16 行新增15 行删除
  1. 16
    15
      Marlin/src/module/planner.cpp

+ 16
- 15
Marlin/src/module/planner.cpp 查看文件

@@ -2319,16 +2319,15 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2319 2319
 
2320 2320
             /**
2321 2321
              *  // Generate the JD Lookup Table
2322
-             *  constexpr float c = 1.00751317f; // Correction factor to center error around 0
2322
+             *  constexpr float c = 1.00751495f; // Correction factor to center error around 0
2323 2323
              *  for (int i = 0; i < jd_lut_count - 1; ++i) {
2324 2324
              *    const float x0 = (sq(i) - 1) / sq(i),
2325
-             *                y0 = acos(x0) * (i ? c : 1),
2326
-             *                x1 = 0.5 * x0 + 0.5,
2327
-             *                y1 = acos(x1) * c;
2325
+             *                y0 = acos(x0) * (i == 0 ? 1 : c),
2326
+             *                x1 = i < jd_lut_count - 1 ?  0.5 * x0 + 0.5 : 0.999999f,
2327
+             *                y1 = acos(x1) * (i < jd_lut_count - 1 ? c : 1);
2328 2328
              *    jd_lut_k[i] = (y0 - y1) / (x0 - x1);
2329 2329
              *    jd_lut_b[i] = (y1 * x0 - y0 * x1) / (x0 - x1);
2330 2330
              *  }
2331
-             *  jd_lut_k[jd_lut_count - 1] = jd_lut_b[jd_lut_count - 1] = 0;
2332 2331
              *
2333 2332
              *  // Compute correction factor (Set c to 1.0f first!)
2334 2333
              *  float min = INFINITY, max = -min;
@@ -2341,22 +2340,24 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2341 2340
              *  }
2342 2341
              *  fprintf(stderr, "%.9gf, ", (min + max) / 2);
2343 2342
              */
2344
-            static constexpr int16_t  jd_lut_count = 15;
2345
-            static constexpr uint16_t jd_lut_tll   = 1 << jd_lut_count;
2346
-            static constexpr int16_t  jd_lut_tll0  = __builtin_clz(jd_lut_tll) + 1; // i.e., 16 - jd_lut_count
2343
+            static constexpr int16_t  jd_lut_count = 16;
2344
+            static constexpr uint16_t jd_lut_tll   = _BV(jd_lut_count - 1);
2345
+            static constexpr int16_t  jd_lut_tll0  = __builtin_clz(jd_lut_tll) + 1; // i.e., 16 - jd_lut_count + 1
2347 2346
             static constexpr float jd_lut_k[jd_lut_count] PROGMEM = {
2348
-              -1.03146219f, -1.30760407f, -1.75205469f, -2.41705418f, -3.37768555f,
2349
-              -4.74888229f, -6.69648552f, -9.45659828f, -13.3640289f, -18.8927879f,
2350
-              -26.7136307f, -37.7754059f, -53.4200745f, -75.5457306f,   0.0f };
2347
+              -1.03145837f, -1.30760646f, -1.75205851f, -2.41705704f,
2348
+              -3.37769222f, -4.74888992f, -6.69649887f, -9.45661736f,
2349
+              -13.3640480f, -18.8928222f, -26.7136841f, -37.7754593f,
2350
+              -53.4201813f, -75.5458374f, -106.836761f, -218.532821f };
2351 2351
             static constexpr float jd_lut_b[jd_lut_count] PROGMEM = {
2352
-              1.57079637f, 1.70886743f, 2.04220533f, 2.62408018f, 3.52467203f,
2353
-              4.85301876f, 6.77019119f, 9.50873947f, 13.4009094f, 18.9188652f,
2354
-              26.7320709f, 37.7884521f, 53.4292908f, 75.5522461f,  0.0f };
2352
+               1.57079637f,  1.70887053f,  2.04220939f,  2.62408352f,
2353
+               3.52467871f,  4.85302639f,  6.77020454f,  9.50875854f,
2354
+               13.4009285f,  18.9188995f,  26.7321243f,  37.7885055f,
2355
+               53.4293975f,  75.5523529f,  106.841369f,  218.534011f };
2355 2356
 
2356 2357
             const float neg = junction_cos_theta < 0 ? -1 : 1,
2357 2358
                         t = neg * junction_cos_theta;
2358 2359
 
2359
-            const int16_t idx = (t == 0.0f) ? 0 : __builtin_clz(uint16_t((1.0f - t) * jd_lut_tll)) - jd_lut_tll0;
2360
+            const int16_t idx = (t < 0.00000003f) ? 0 : __builtin_clz(uint16_t((1.0f - t) * jd_lut_tll)) - jd_lut_tll0;
2360 2361
 
2361 2362
             float junction_theta = t * pgm_read_float(&jd_lut_k[idx]) + pgm_read_float(&jd_lut_b[idx]);
2362 2363
             if (neg > 0) junction_theta = RADIANS(180) - junction_theta; // acos(-t)

Loading…
取消
儲存