Przeglądaj źródła

Just-in-time declaration style in M48

Scott Lahteine 9 lat temu
rodzic
commit
4edf813bde
1 zmienionych plików z 42 dodań i 66 usunięć
  1. 42
    66
      Marlin/Marlin_main.cpp

+ 42
- 66
Marlin/Marlin_main.cpp Wyświetl plik

4201
       return;
4201
       return;
4202
     }
4202
     }
4203
 
4203
 
4204
-    double sum = 0.0, mean = 0.0, sigma = 0.0, sample_set[50];
4205
-    int8_t verbose_level = 1, n_samples = 10, n_legs = 0, schizoid_flag = 0;
4206
-
4207
-    if (code_seen('V')) {
4208
-      verbose_level = code_value_byte();
4209
-      if (verbose_level < 0 || verbose_level > 4) {
4210
-        SERIAL_PROTOCOLPGM("?Verbose Level not plausible (0-4).\n");
4211
-        return;
4212
-      }
4204
+    int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
4205
+    if (verbose_level < 0 || verbose_level > 4) {
4206
+      SERIAL_PROTOCOLPGM("?Verbose Level not plausible (0-4).\n");
4207
+      return;
4213
     }
4208
     }
4214
 
4209
 
4215
     if (verbose_level > 0)
4210
     if (verbose_level > 0)
4216
       SERIAL_PROTOCOLPGM("M48 Z-Probe Repeatability test\n");
4211
       SERIAL_PROTOCOLPGM("M48 Z-Probe Repeatability test\n");
4217
 
4212
 
4218
-    if (code_seen('P')) {
4219
-      n_samples = code_value_byte();
4220
-      if (n_samples < 4 || n_samples > 50) {
4221
-        SERIAL_PROTOCOLPGM("?Sample size not plausible (4-50).\n");
4222
-        return;
4223
-      }
4213
+    int8_t n_samples = code_seen('P') ? code_value_byte() : 10;
4214
+    if (n_samples < 4 || n_samples > 50) {
4215
+      SERIAL_PROTOCOLPGM("?Sample size not plausible (4-50).\n");
4216
+      return;
4224
     }
4217
     }
4225
 
4218
 
4226
     float  X_current = current_position[X_AXIS],
4219
     float  X_current = current_position[X_AXIS],
4227
            Y_current = current_position[Y_AXIS],
4220
            Y_current = current_position[Y_AXIS],
4228
-           Z_current = current_position[Z_AXIS],
4229
-           X_probe_location = X_current + X_PROBE_OFFSET_FROM_EXTRUDER,
4230
-           Y_probe_location = Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER,
4231
-           Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING;
4221
+           Z_start_location = current_position[Z_AXIS] + Z_RAISE_BEFORE_PROBING;
4232
     bool deploy_probe_for_each_reading = code_seen('E');
4222
     bool deploy_probe_for_each_reading = code_seen('E');
4233
 
4223
 
4234
-    if (code_seen('X')) {
4235
-      X_probe_location = code_value_axis_units(X_AXIS);
4236
-      #if DISABLED(DELTA)
4237
-        if (X_probe_location < MIN_PROBE_X || X_probe_location > MAX_PROBE_X) {
4238
-          out_of_range_error(PSTR("X"));
4239
-          return;
4240
-        }
4241
-      #endif
4242
-    }
4243
-
4244
-    if (code_seen('Y')) {
4245
-      Y_probe_location = code_value_axis_units(Y_AXIS);
4246
-      #if DISABLED(DELTA)
4247
-        if (Y_probe_location < MIN_PROBE_Y || Y_probe_location > MAX_PROBE_Y) {
4248
-          out_of_range_error(PSTR("Y"));
4249
-          return;
4250
-        }
4251
-      #endif
4252
-    }
4224
+    float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
4225
+    #if DISABLED(DELTA)
4226
+      if (X_probe_location < MIN_PROBE_X || X_probe_location > MAX_PROBE_X) {
4227
+        out_of_range_error(PSTR("X"));
4228
+        return;
4229
+      }
4230
+    #endif
4253
 
4231
 
4254
-    #if ENABLED(DELTA)
4232
+    float Y_probe_location = code_seen('Y') ? code_value_axis_units(Y_AXIS) : Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER;
4233
+    #if DISABLED(DELTA)
4234
+      if (Y_probe_location < MIN_PROBE_Y || Y_probe_location > MAX_PROBE_Y) {
4235
+        out_of_range_error(PSTR("Y"));
4236
+        return;
4237
+      }
4238
+    #else
4255
       if (sqrt(X_probe_location * X_probe_location + Y_probe_location * Y_probe_location) > DELTA_PROBEABLE_RADIUS) {
4239
       if (sqrt(X_probe_location * X_probe_location + Y_probe_location * Y_probe_location) > DELTA_PROBEABLE_RADIUS) {
4256
         SERIAL_PROTOCOLPGM("? (X,Y) location outside of probeable radius.\n");
4240
         SERIAL_PROTOCOLPGM("? (X,Y) location outside of probeable radius.\n");
4257
         return;
4241
         return;
4259
     #endif
4243
     #endif
4260
 
4244
 
4261
     bool seen_L = code_seen('L');
4245
     bool seen_L = code_seen('L');
4262
-
4263
-    if (seen_L) {
4264
-      n_legs = code_value_byte();
4265
-      if (n_legs < 0 || n_legs > 15) {
4266
-        SERIAL_PROTOCOLPGM("?Number of legs in movement not plausible (0-15).\n");
4267
-        return;
4268
-      }
4269
-      if (n_legs == 1) n_legs = 2;
4246
+    uint8_t n_legs = seen_L ? code_value_byte() : 0;
4247
+    if (n_legs < 0 || n_legs > 15) {
4248
+      SERIAL_PROTOCOLPGM("?Number of legs in movement not plausible (0-15).\n");
4249
+      return;
4270
     }
4250
     }
4251
+    if (n_legs == 1) n_legs = 2;
4271
 
4252
 
4272
-    if (code_seen('S')) {
4273
-      schizoid_flag++;
4274
-      if (!seen_L) n_legs = 7;
4275
-    }
4253
+    bool schizoid_flag = code_seen('S');
4254
+    if (schizoid_flag && !seen_L) n_legs = 7;
4276
 
4255
 
4277
     /**
4256
     /**
4278
      * Now get everything to the specified probe point So we can safely do a
4257
      * Now get everything to the specified probe point So we can safely do a
4307
 
4286
 
4308
     raise_z_after_probing();
4287
     raise_z_after_probing();
4309
 
4288
 
4289
+    randomSeed(millis());
4290
+
4291
+    double mean, sigma, sample_set[n_samples];
4310
     for (uint8_t n = 0; n < n_samples; n++) {
4292
     for (uint8_t n = 0; n < n_samples; n++) {
4311
-      randomSeed(millis());
4312
       delay(500);
4293
       delay(500);
4313
       if (n_legs) {
4294
       if (n_legs) {
4314
-        float radius, angle = random(0.0, 360.0);
4315
         int dir = (random(0, 10) > 5.0) ? -1 : 1;  // clockwise or counter clockwise
4295
         int dir = (random(0, 10) > 5.0) ? -1 : 1;  // clockwise or counter clockwise
4316
-
4317
-        radius = random(
4318
-          #if ENABLED(DELTA)
4319
-            DELTA_PROBEABLE_RADIUS / 8, DELTA_PROBEABLE_RADIUS / 3
4320
-          #else
4321
-            5, X_MAX_LENGTH / 8
4322
-          #endif
4323
-        );
4296
+        float angle = random(0.0, 360.0),
4297
+              radius = random(
4298
+                #if ENABLED(DELTA)
4299
+                  DELTA_PROBEABLE_RADIUS / 8, DELTA_PROBEABLE_RADIUS / 3
4300
+                #else
4301
+                  5, X_MAX_LENGTH / 8
4302
+                #endif
4303
+              );
4324
 
4304
 
4325
         if (verbose_level > 3) {
4305
         if (verbose_level > 3) {
4326
           SERIAL_ECHOPAIR("Starting radius: ", radius);
4306
           SERIAL_ECHOPAIR("Starting radius: ", radius);
4404
       /**
4384
       /**
4405
        * Get the current mean for the data points we have so far
4385
        * Get the current mean for the data points we have so far
4406
        */
4386
        */
4407
-      sum = 0.0;
4387
+      double sum = 0.0;
4408
       for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
4388
       for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
4409
       mean = sum / (n + 1);
4389
       mean = sum / (n + 1);
4410
 
4390
 
4437
       do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
4417
       do_blocking_move_to_z(current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
4438
     }  // End of probe loop code
4418
     }  // End of probe loop code
4439
 
4419
 
4440
-    // raise_z_after_probing();
4441
-
4442
     if (verbose_level > 0) {
4420
     if (verbose_level > 0) {
4443
       SERIAL_PROTOCOLPGM("Mean: ");
4421
       SERIAL_PROTOCOLPGM("Mean: ");
4444
       SERIAL_PROTOCOL_F(mean, 6);
4422
       SERIAL_PROTOCOL_F(mean, 6);
4445
       SERIAL_EOL;
4423
       SERIAL_EOL;
4446
-      delay(25);
4447
     }
4424
     }
4448
 
4425
 
4449
     SERIAL_PROTOCOLPGM("Standard Deviation: ");
4426
     SERIAL_PROTOCOLPGM("Standard Deviation: ");
4450
     SERIAL_PROTOCOL_F(sigma, 6);
4427
     SERIAL_PROTOCOL_F(sigma, 6);
4451
     SERIAL_EOL; SERIAL_EOL;
4428
     SERIAL_EOL; SERIAL_EOL;
4452
-    delay(25);
4453
 
4429
 
4454
     clean_up_after_endstop_move();
4430
     clean_up_after_endstop_move();
4455
 
4431
 

Ładowanie…
Anuluj
Zapisz