Browse Source

References are better for array args

Scott Lahteine 6 years ago
parent
commit
73e32925e4

+ 1
- 1
.travis.yml View File

121
   - opt_enable ULTIMAKERCONTROLLER SDSUPPORT
121
   - opt_enable ULTIMAKERCONTROLLER SDSUPPORT
122
   - opt_enable PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE PCA9632 USE_XMAX_PLUG
122
   - opt_enable PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE PCA9632 USE_XMAX_PLUG
123
   - opt_enable_adv BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS
123
   - opt_enable_adv BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS
124
-  - opt_enable_adv ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE LCD_INFO_MENU
124
+  - opt_enable_adv ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE LCD_INFO_MENU M114_DETAIL
125
   - opt_set_adv PWM_MOTOR_CURRENT {1300,1300,1250}
125
   - opt_set_adv PWM_MOTOR_CURRENT {1300,1300,1250}
126
   - opt_set_adv I2C_SLAVE_ADDRESS 63
126
   - opt_set_adv I2C_SLAVE_ADDRESS 63
127
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}
127
   - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM}

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl.h View File

316
     }
316
     }
317
 
317
 
318
     static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
318
     static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
319
-    static void line_to_destination_cartesian(const float &fr, uint8_t e);
319
+    static void line_to_destination_cartesian(const float &fr, const uint8_t e);
320
 
320
 
321
     #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
321
     #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
322
     #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))
322
     #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))

+ 2
- 2
Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp View File

92
 
92
 
93
   }
93
   }
94
 
94
 
95
-  void unified_bed_leveling::line_to_destination_cartesian(const float &feed_rate, uint8_t extruder) {
95
+  void unified_bed_leveling::line_to_destination_cartesian(const float &feed_rate, const uint8_t extruder) {
96
     /**
96
     /**
97
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
97
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
98
      * as possible to determine if this is the case. If this move is within the same cell, we will
98
      * as possible to determine if this is the case. If this move is within the same cell, we will
475
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
475
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
476
     // so we call _buffer_line directly here.  Per-segmented leveling and kinematics performed first.
476
     // so we call _buffer_line directly here.  Per-segmented leveling and kinematics performed first.
477
 
477
 
478
-    inline void _O2 ubl_buffer_segment_raw(const float raw[XYZE], const float &fr) {
478
+    inline void _O2 ubl_buffer_segment_raw(const float (&raw)[XYZE], const float &fr) {
479
 
479
 
480
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
480
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
481
 
481
 

+ 3
- 3
Marlin/src/gcode/bedlevel/G26.cpp View File

261
   set_destination_from_current();
261
   set_destination_from_current();
262
 }
262
 }
263
 
263
 
264
-FORCE_INLINE void move_to(const float where[XYZE], const float &de) { move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); }
264
+FORCE_INLINE void move_to(const float (&where)[XYZE], const float &de) { move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); }
265
 
265
 
266
-void retract_filament(const float where[XYZE]) {
266
+void retract_filament(const float (&where)[XYZE]) {
267
   if (!g26_retracted) { // Only retract if we are not already retracted!
267
   if (!g26_retracted) { // Only retract if we are not already retracted!
268
     g26_retracted = true;
268
     g26_retracted = true;
269
     move_to(where, -1.0 * g26_retraction_multiplier);
269
     move_to(where, -1.0 * g26_retraction_multiplier);
270
   }
270
   }
271
 }
271
 }
272
 
272
 
273
-void recover_filament(const float where[XYZE]) {
273
+void recover_filament(const float (&where)[XYZE]) {
274
   if (g26_retracted) { // Only un-retract if we are retracted.
274
   if (g26_retracted) { // Only un-retract if we are retracted.
275
     move_to(where, 1.2 * g26_retraction_multiplier);
275
     move_to(where, 1.2 * g26_retraction_multiplier);
276
     g26_retracted = false;
276
     g26_retracted = false;

+ 2
- 2
Marlin/src/gcode/host/M114.cpp View File

28
 
28
 
29
 #if ENABLED(M114_DETAIL)
29
 #if ENABLED(M114_DETAIL)
30
 
30
 
31
-  void report_xyze(const float pos[XYZE], const uint8_t n = 4, const uint8_t precision = 3) {
31
+  void report_xyze(const float pos[], const uint8_t n = 4, const uint8_t precision = 3) {
32
     char str[12];
32
     char str[12];
33
     for (uint8_t i = 0; i < n; i++) {
33
     for (uint8_t i = 0; i < n; i++) {
34
       SERIAL_CHAR(' ');
34
       SERIAL_CHAR(' ');
39
     SERIAL_EOL();
39
     SERIAL_EOL();
40
   }
40
   }
41
 
41
 
42
-  inline void report_xyz(const float pos[XYZ]) { report_xyze(pos, 3); }
42
+  inline void report_xyz(const float pos[]) { report_xyze(pos, 3); }
43
 
43
 
44
   void report_current_position_detail() {
44
   void report_current_position_detail() {
45
 
45
 

+ 9
- 9
Marlin/src/gcode/motion/G2_G3.cpp View File

44
  * options for G2/G3 arc generation. In future these options may be GCode tunable.
44
  * options for G2/G3 arc generation. In future these options may be GCode tunable.
45
  */
45
  */
46
 void plan_arc(
46
 void plan_arc(
47
-  float rtarget[XYZE], // Destination position
48
-  float *offset,       // Center of rotation relative to current_position
49
-  uint8_t clockwise    // Clockwise?
47
+  const float (&cart)[XYZE],  // Destination position
48
+  const float (&offset)[2],   // Center of rotation relative to current_position
49
+  const uint8_t clockwise     // Clockwise?
50
 ) {
50
 ) {
51
   #if ENABLED(CNC_WORKSPACE_PLANES)
51
   #if ENABLED(CNC_WORKSPACE_PLANES)
52
     AxisEnum p_axis, q_axis, l_axis;
52
     AxisEnum p_axis, q_axis, l_axis;
66
   const float radius = HYPOT(r_P, r_Q),
66
   const float radius = HYPOT(r_P, r_Q),
67
               center_P = current_position[p_axis] - r_P,
67
               center_P = current_position[p_axis] - r_P,
68
               center_Q = current_position[q_axis] - r_Q,
68
               center_Q = current_position[q_axis] - r_Q,
69
-              rt_X = rtarget[p_axis] - center_P,
70
-              rt_Y = rtarget[q_axis] - center_Q,
71
-              linear_travel = rtarget[l_axis] - current_position[l_axis],
72
-              extruder_travel = rtarget[E_AXIS] - current_position[E_AXIS];
69
+              rt_X = cart[p_axis] - center_P,
70
+              rt_Y = cart[q_axis] - center_Q,
71
+              linear_travel = cart[l_axis] - current_position[l_axis],
72
+              extruder_travel = cart[E_AXIS] - current_position[E_AXIS];
73
 
73
 
74
   // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
74
   // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
75
   float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
75
   float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
77
   if (clockwise) angular_travel -= RADIANS(360);
77
   if (clockwise) angular_travel -= RADIANS(360);
78
 
78
 
79
   // Make a circle if the angular rotation is 0 and the target is current position
79
   // Make a circle if the angular rotation is 0 and the target is current position
80
-  if (angular_travel == 0 && current_position[p_axis] == rtarget[p_axis] && current_position[q_axis] == rtarget[q_axis])
80
+  if (angular_travel == 0 && current_position[p_axis] == cart[p_axis] && current_position[q_axis] == cart[q_axis])
81
     angular_travel = RADIANS(360);
81
     angular_travel = RADIANS(360);
82
 
82
 
83
   const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
83
   const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
177
   }
177
   }
178
 
178
 
179
   // Ensure last segment arrives at target location.
179
   // Ensure last segment arrives at target location.
180
-  planner.buffer_line_kinematic(rtarget, fr_mm_s, active_extruder);
180
+  planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
181
 
181
 
182
   // As far as the parser is concerned, the position is now == target. In reality the
182
   // As far as the parser is concerned, the position is now == target. In reality the
183
   // motion control system might still be processing the action and the real tool position
183
   // motion control system might still be processing the action and the real tool position

+ 2
- 2
Marlin/src/gcode/motion/G5.cpp View File

27
 #include "../../module/motion.h"
27
 #include "../../module/motion.h"
28
 #include "../../module/planner_bezier.h"
28
 #include "../../module/planner_bezier.h"
29
 
29
 
30
-void plan_cubic_move(const float offset[4]) {
30
+void plan_cubic_move(const float (&offset)[4]) {
31
   cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
31
   cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
32
 
32
 
33
   // As far as the parser is concerned, the position is now == destination. In reality the
33
   // As far as the parser is concerned, the position is now == destination. In reality the
62
 
62
 
63
     get_destination_from_command();
63
     get_destination_from_command();
64
 
64
 
65
-    const float offset[] = {
65
+    const float offset[4] = {
66
       parser.linearval('I'),
66
       parser.linearval('I'),
67
       parser.linearval('J'),
67
       parser.linearval('J'),
68
       parser.linearval('P'),
68
       parser.linearval('P'),

+ 7
- 1
Marlin/src/module/motion.cpp View File

517
   /**
517
   /**
518
    * Prepare a linear move in a DELTA or SCARA setup.
518
    * Prepare a linear move in a DELTA or SCARA setup.
519
    *
519
    *
520
+   * Called from prepare_move_to_destination as the
521
+   * default Delta/SCARA segmenter.
522
+   *
520
    * This calls planner.buffer_line several times, adding
523
    * This calls planner.buffer_line several times, adding
521
    * small incremental moves for DELTA or SCARA.
524
    * small incremental moves for DELTA or SCARA.
522
    *
525
    *
523
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
526
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
524
    * the ubl.prepare_segmented_line_to method replaces this.
527
    * the ubl.prepare_segmented_line_to method replaces this.
528
+   *
529
+   * For Auto Bed Leveling (Bilinear) with SEGMENT_LEVELED_MOVES
530
+   * this is replaced by segmented_line_to_destination below.
525
    */
531
    */
526
-  inline bool prepare_kinematic_move_to(float rtarget[XYZE]) {
532
+  inline bool prepare_kinematic_move_to(const float (&rtarget)[XYZE]) {
527
 
533
 
528
     // Get the top feedrate of the move in the XY plane
534
     // Get the top feedrate of the move in the XY plane
529
     const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
535
     const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);

+ 7
- 7
Marlin/src/module/planner.cpp View File

1466
   ZERO(previous_speed);
1466
   ZERO(previous_speed);
1467
 }
1467
 }
1468
 
1468
 
1469
-void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
1469
+void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
1470
   #if PLANNER_LEVELING
1470
   #if PLANNER_LEVELING
1471
-    float lpos[XYZ] = { position[X_AXIS], position[Y_AXIS], position[Z_AXIS] };
1472
-    apply_leveling(lpos);
1471
+    float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
1472
+    apply_leveling(raw);
1473
   #else
1473
   #else
1474
-    const float * const lpos = position;
1474
+    const float (&raw)[XYZE] = cart;
1475
   #endif
1475
   #endif
1476
   #if IS_KINEMATIC
1476
   #if IS_KINEMATIC
1477
-    inverse_kinematics(lpos);
1478
-    _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], position[E_AXIS]);
1477
+    inverse_kinematics(raw);
1478
+    _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS]);
1479
   #else
1479
   #else
1480
-    _set_position_mm(lpos[X_AXIS], lpos[Y_AXIS], lpos[Z_AXIS], position[E_AXIS]);
1480
+    _set_position_mm(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS]);
1481
   #endif
1481
   #endif
1482
 }
1482
 }
1483
 
1483
 

+ 4
- 4
Marlin/src/module/planner.h View File

356
        * as it will be given to the planner and steppers.
356
        * as it will be given to the planner and steppers.
357
        */
357
        */
358
       static void apply_leveling(float &rx, float &ry, float &rz);
358
       static void apply_leveling(float &rx, float &ry, float &rz);
359
-      static void apply_leveling(float raw[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
359
+      static void apply_leveling(float (&raw)[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
360
       static void unapply_leveling(float raw[XYZ]);
360
       static void unapply_leveling(float raw[XYZ]);
361
 
361
 
362
     #else
362
     #else
421
      *  fr_mm_s  - (target) speed of the move (mm/s)
421
      *  fr_mm_s  - (target) speed of the move (mm/s)
422
      *  extruder - target extruder
422
      *  extruder - target extruder
423
      */
423
      */
424
-    FORCE_INLINE static void buffer_line_kinematic(const float cart[XYZE], const float &fr_mm_s, const uint8_t extruder) {
424
+    FORCE_INLINE static void buffer_line_kinematic(const float (&cart)[XYZE], const float &fr_mm_s, const uint8_t extruder) {
425
       #if PLANNER_LEVELING
425
       #if PLANNER_LEVELING
426
         float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
426
         float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
427
         apply_leveling(raw);
427
         apply_leveling(raw);
428
       #else
428
       #else
429
-        const float * const raw = cart;
429
+        const float (&raw)[XYZE] = cart;
430
       #endif
430
       #endif
431
       #if IS_KINEMATIC
431
       #if IS_KINEMATIC
432
         inverse_kinematics(raw);
432
         inverse_kinematics(raw);
451
       #endif
451
       #endif
452
       _set_position_mm(rx, ry, rz, e);
452
       _set_position_mm(rx, ry, rz, e);
453
     }
453
     }
454
-    static void set_position_mm_kinematic(const float position[NUM_AXIS]);
454
+    static void set_position_mm_kinematic(const float (&cart)[XYZE]);
455
     static void set_position_mm(const AxisEnum axis, const float &v);
455
     static void set_position_mm(const AxisEnum axis, const float &v);
456
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
456
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
457
     FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }
457
     FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }

+ 1
- 1
Marlin/src/module/probe.cpp View File

107
 
107
 
108
 #elif ENABLED(Z_PROBE_ALLEN_KEY)
108
 #elif ENABLED(Z_PROBE_ALLEN_KEY)
109
 
109
 
110
-  FORCE_INLINE void do_blocking_move_to(const float raw[XYZ], const float &fr_mm_s) {
110
+  FORCE_INLINE void do_blocking_move_to(const float (&raw)[XYZ], const float &fr_mm_s) {
111
     do_blocking_move_to(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], fr_mm_s);
111
     do_blocking_move_to(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], fr_mm_s);
112
   }
112
   }
113
 
113
 

+ 3
- 3
Marlin/src/module/stepper.cpp View File

1193
 /**
1193
 /**
1194
  * Get a stepper's position in steps.
1194
  * Get a stepper's position in steps.
1195
  */
1195
  */
1196
-long Stepper::position(AxisEnum axis) {
1196
+long Stepper::position(const AxisEnum axis) {
1197
   CRITICAL_SECTION_START;
1197
   CRITICAL_SECTION_START;
1198
   const long count_pos = count_position[axis];
1198
   const long count_pos = count_position[axis];
1199
   CRITICAL_SECTION_END;
1199
   CRITICAL_SECTION_END;
1204
  * Get an axis position according to stepper position(s)
1204
  * Get an axis position according to stepper position(s)
1205
  * For CORE machines apply translation from ABC to XYZ.
1205
  * For CORE machines apply translation from ABC to XYZ.
1206
  */
1206
  */
1207
-float Stepper::get_axis_position_mm(AxisEnum axis) {
1207
+float Stepper::get_axis_position_mm(const AxisEnum axis) {
1208
   float axis_steps;
1208
   float axis_steps;
1209
   #if IS_CORE
1209
   #if IS_CORE
1210
     // Requesting one of the "core" axes?
1210
     // Requesting one of the "core" axes?
1242
   #endif
1242
   #endif
1243
 }
1243
 }
1244
 
1244
 
1245
-void Stepper::endstop_triggered(AxisEnum axis) {
1245
+void Stepper::endstop_triggered(const AxisEnum axis) {
1246
 
1246
 
1247
   #if IS_CORE
1247
   #if IS_CORE
1248
 
1248
 

+ 6
- 6
Marlin/src/module/stepper.h View File

183
     //
183
     //
184
     // Get the position of a stepper, in steps
184
     // Get the position of a stepper, in steps
185
     //
185
     //
186
-    static long position(AxisEnum axis);
186
+    static long position(const AxisEnum axis);
187
 
187
 
188
     //
188
     //
189
     // Report the positions of the steppers, in steps
189
     // Report the positions of the steppers, in steps
193
     //
193
     //
194
     // Get the position (mm) of an axis based on stepper position(s)
194
     // Get the position (mm) of an axis based on stepper position(s)
195
     //
195
     //
196
-    static float get_axis_position_mm(AxisEnum axis);
196
+    static float get_axis_position_mm(const AxisEnum axis);
197
 
197
 
198
     //
198
     //
199
     // SCARA AB axes are in degrees, not mm
199
     // SCARA AB axes are in degrees, not mm
200
     //
200
     //
201
     #if IS_SCARA
201
     #if IS_SCARA
202
-      FORCE_INLINE static float get_axis_position_degrees(AxisEnum axis) { return get_axis_position_mm(axis); }
202
+      FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
203
     #endif
203
     #endif
204
 
204
 
205
     //
205
     //
221
     //
221
     //
222
     // The direction of a single motor
222
     // The direction of a single motor
223
     //
223
     //
224
-    FORCE_INLINE static bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
224
+    FORCE_INLINE static bool motor_direction(const AxisEnum axis) { return TEST(last_direction_bits, axis); }
225
 
225
 
226
     #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
226
     #if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
227
       static void digitalPotWrite(const int16_t address, const int16_t value);
227
       static void digitalPotWrite(const int16_t address, const int16_t value);
263
     //
263
     //
264
     // Handle a triggered endstop
264
     // Handle a triggered endstop
265
     //
265
     //
266
-    static void endstop_triggered(AxisEnum axis);
266
+    static void endstop_triggered(const AxisEnum axis);
267
 
267
 
268
     //
268
     //
269
     // Triggered position of an axis in mm (not core-savvy)
269
     // Triggered position of an axis in mm (not core-savvy)
270
     //
270
     //
271
-    FORCE_INLINE static float triggered_position_mm(AxisEnum axis) {
271
+    FORCE_INLINE static float triggered_position_mm(const AxisEnum axis) {
272
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
272
       return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
273
     }
273
     }
274
 
274
 

Loading…
Cancel
Save