Ver código fonte

Add const to some variables

Scott Lahteine 8 anos atrás
pai
commit
1929502e15
1 arquivos alterados com 24 adições e 24 exclusões
  1. 24
    24
      Marlin/planner.cpp

+ 24
- 24
Marlin/planner.cpp Ver arquivo

141
 #endif
141
 #endif
142
 
142
 
143
 #if ENABLED(LIN_ADVANCE)
143
 #if ENABLED(LIN_ADVANCE)
144
-  float Planner::extruder_advance_k = LIN_ADVANCE_K;
145
-  float Planner::position_float[NUM_AXIS] = { 0 };
144
+  float Planner::extruder_advance_k = LIN_ADVANCE_K,
145
+        Planner::position_float[NUM_AXIS] = { 0 };
146
 #endif
146
 #endif
147
 
147
 
148
 #if ENABLED(ENSURE_SMOOTH_MOVES)
148
 #if ENABLED(ENSURE_SMOOTH_MOVES)
654
   // The target position of the tool in absolute steps
654
   // The target position of the tool in absolute steps
655
   // Calculate target position in absolute steps
655
   // Calculate target position in absolute steps
656
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
656
   //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
657
-  long target[XYZE] = {
657
+  const long target[XYZE] = {
658
     lround(a * axis_steps_per_mm[X_AXIS]),
658
     lround(a * axis_steps_per_mm[X_AXIS]),
659
     lround(b * axis_steps_per_mm[Y_AXIS]),
659
     lround(b * axis_steps_per_mm[Y_AXIS]),
660
     lround(c * axis_steps_per_mm[Z_AXIS]),
660
     lround(c * axis_steps_per_mm[Z_AXIS]),
670
   #endif
670
   #endif
671
 
671
 
672
   #if ENABLED(LIN_ADVANCE)
672
   #if ENABLED(LIN_ADVANCE)
673
-    float target_float[XYZE] = {a, b, c, e};
674
-    float de_float = target_float[E_AXIS] - position_float[E_AXIS];
675
-    float mm_D_float = sqrt(sq(target_float[X_AXIS] - position_float[X_AXIS]) + sq(target_float[Y_AXIS] - position_float[Y_AXIS]));
673
+    const float target_float[XYZE] = { a, b, c, e },
674
+                de_float = target_float[E_AXIS] - position_float[E_AXIS],
675
+                mm_D_float = sqrt(sq(target_float[X_AXIS] - position_float[X_AXIS]) + sq(target_float[Y_AXIS] - position_float[Y_AXIS]));
676
     
676
     
677
     memcpy(position_float, target_float, sizeof(position_float));
677
     memcpy(position_float, target_float, sizeof(position_float));
678
   #endif
678
   #endif
679
 
679
 
680
-  long da = target[X_AXIS] - position[X_AXIS],
681
-       db = target[Y_AXIS] - position[Y_AXIS],
682
-       dc = target[Z_AXIS] - position[Z_AXIS];
680
+  const long da = target[X_AXIS] - position[X_AXIS],
681
+             db = target[Y_AXIS] - position[Y_AXIS],
682
+             dc = target[Z_AXIS] - position[Z_AXIS];
683
 
683
 
684
   /*
684
   /*
685
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
685
   SERIAL_ECHOPAIR("  Planner FR:", fr_mm_s);
755
   #endif
755
   #endif
756
   if (de < 0) SBI(dm, E_AXIS);
756
   if (de < 0) SBI(dm, E_AXIS);
757
 
757
 
758
-  float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
759
-  int32_t esteps = abs(esteps_float) + 0.5;
758
+  const float esteps_float = de * volumetric_multiplier[extruder] * flow_percentage[extruder] * 0.01;
759
+  const int32_t esteps = abs(esteps_float) + 0.5;
760
 
760
 
761
   // Calculate the buffer head after we push this byte
761
   // Calculate the buffer head after we push this byte
762
-  int8_t next_buffer_head = next_block_index(block_buffer_head);
762
+  const uint8_t next_buffer_head = next_block_index(block_buffer_head);
763
 
763
 
764
   // If the buffer is full: good! That means we are well ahead of the robot.
764
   // If the buffer is full: good! That means we are well ahead of the robot.
765
   // Rest here until there is room in the buffer.
765
   // Rest here until there is room in the buffer.
852
 
852
 
853
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
853
     #if ENABLED(DISABLE_INACTIVE_EXTRUDER) // Enable only the selected extruder
854
 
854
 
855
-      for (int8_t i = 0; i < EXTRUDERS; i++)
855
+      for (uint8_t i = 0; i < EXTRUDERS; i++)
856
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
856
         if (g_uc_extruder_last_move[i] > 0) g_uc_extruder_last_move[i]--;
857
 
857
 
858
       switch(extruder) {
858
       switch(extruder) {
980
   // Calculate moves/second for this move. No divide by zero due to previous checks.
980
   // Calculate moves/second for this move. No divide by zero due to previous checks.
981
   float inverse_mm_s = fr_mm_s * inverse_millimeters;
981
   float inverse_mm_s = fr_mm_s * inverse_millimeters;
982
 
982
 
983
-  int moves_queued = movesplanned();
983
+  const uint8_t moves_queued = movesplanned();
984
 
984
 
985
   // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
985
   // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
986
   #if ENABLED(SLOWDOWN)
986
   #if ENABLED(SLOWDOWN)
1037
         // If the index has changed (must have gone forward)...
1037
         // If the index has changed (must have gone forward)...
1038
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1038
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1039
           filwidth_e_count = 0; // Reset the E movement counter
1039
           filwidth_e_count = 0; // Reset the E movement counter
1040
-          int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1040
+          const int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1041
           do {
1041
           do {
1042
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1042
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1043
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
1043
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
1050
   // Calculate and limit speed in mm/sec for each axis
1050
   // Calculate and limit speed in mm/sec for each axis
1051
   float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
1051
   float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
1052
   LOOP_XYZE(i) {
1052
   LOOP_XYZE(i) {
1053
-    float cs = fabs(current_speed[i] = delta_mm[i] * inverse_mm_s);
1053
+    const float cs = fabs(current_speed[i] = delta_mm[i] * inverse_mm_s);
1054
     if (cs > max_feedrate_mm_s[i]) NOMORE(speed_factor, max_feedrate_mm_s[i] / cs);
1054
     if (cs > max_feedrate_mm_s[i]) NOMORE(speed_factor, max_feedrate_mm_s[i] / cs);
1055
   }
1055
   }
1056
 
1056
 
1058
   #ifdef XY_FREQUENCY_LIMIT
1058
   #ifdef XY_FREQUENCY_LIMIT
1059
 
1059
 
1060
     // Check and limit the xy direction change frequency
1060
     // Check and limit the xy direction change frequency
1061
-    unsigned char direction_change = block->direction_bits ^ old_direction_bits;
1061
+    const unsigned char direction_change = block->direction_bits ^ old_direction_bits;
1062
     old_direction_bits = block->direction_bits;
1062
     old_direction_bits = block->direction_bits;
1063
     segment_time = lround((float)segment_time / speed_factor);
1063
     segment_time = lround((float)segment_time / speed_factor);
1064
 
1064
 
1083
     }
1083
     }
1084
     ys0 = axis_segment_time[Y_AXIS][0] = ys0 + segment_time;
1084
     ys0 = axis_segment_time[Y_AXIS][0] = ys0 + segment_time;
1085
 
1085
 
1086
-    long max_x_segment_time = MAX3(xs0, xs1, xs2),
1087
-         max_y_segment_time = MAX3(ys0, ys1, ys2),
1088
-         min_xy_segment_time = min(max_x_segment_time, max_y_segment_time);
1086
+    const long max_x_segment_time = MAX3(xs0, xs1, xs2),
1087
+               max_y_segment_time = MAX3(ys0, ys1, ys2),
1088
+               min_xy_segment_time = min(max_x_segment_time, max_y_segment_time);
1089
     if (min_xy_segment_time < MAX_FREQ_TIME) {
1089
     if (min_xy_segment_time < MAX_FREQ_TIME) {
1090
-      float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME);
1090
+      const float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME);
1091
       NOMORE(speed_factor, low_sf);
1091
       NOMORE(speed_factor, low_sf);
1092
     }
1092
     }
1093
   #endif // XY_FREQUENCY_LIMIT
1093
   #endif // XY_FREQUENCY_LIMIT
1100
   }
1100
   }
1101
 
1101
 
1102
   // Compute and limit the acceleration rate for the trapezoid generator.
1102
   // Compute and limit the acceleration rate for the trapezoid generator.
1103
-  float steps_per_mm = block->step_event_count * inverse_millimeters;
1103
+  const float steps_per_mm = block->step_event_count * inverse_millimeters;
1104
   uint32_t accel;
1104
   uint32_t accel;
1105
   if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
1105
   if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
1106
     // convert to: acceleration steps/sec^2
1106
     // convert to: acceleration steps/sec^2
1256
     if (limited) vmax_junction *= v_factor;
1256
     if (limited) vmax_junction *= v_factor;
1257
     // Now the transition velocity is known, which maximizes the shared exit / entry velocity while
1257
     // Now the transition velocity is known, which maximizes the shared exit / entry velocity while
1258
     // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints.
1258
     // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints.
1259
-    float vmax_junction_threshold = vmax_junction * 0.99f;
1259
+    const float vmax_junction_threshold = vmax_junction * 0.99f;
1260
     if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) {
1260
     if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold) {
1261
       // Not coasting. The machine will stop and start the movements anyway,
1261
       // Not coasting. The machine will stop and start the movements anyway,
1262
       // better to start the segment from start.
1262
       // better to start the segment from start.
1273
   block->max_entry_speed = vmax_junction;
1273
   block->max_entry_speed = vmax_junction;
1274
 
1274
 
1275
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
1275
   // Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
1276
-  float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
1276
+  const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
1277
   block->entry_speed = min(vmax_junction, v_allowable);
1277
   block->entry_speed = min(vmax_junction, v_allowable);
1278
 
1278
 
1279
   // Initialize planner efficiency flags
1279
   // Initialize planner efficiency flags

Carregando…
Cancelar
Salvar