Bladeren bron

Use array refs where possible

Scott Lahteine 7 jaren geleden
bovenliggende
commit
da2eaa6b09
5 gewijzigde bestanden met toevoegingen van 30 en 30 verwijderingen
  1. 16
    16
      Marlin/Marlin_main.cpp
  2. 7
    7
      Marlin/planner.cpp
  3. 4
    4
      Marlin/planner.h
  4. 1
    1
      Marlin/ubl.h
  5. 2
    2
      Marlin/ubl_motion.cpp

+ 16
- 16
Marlin/Marlin_main.cpp Bestand weergeven

733
 void set_current_from_steppers_for_axis(const AxisEnum axis);
733
 void set_current_from_steppers_for_axis(const AxisEnum axis);
734
 
734
 
735
 #if ENABLED(ARC_SUPPORT)
735
 #if ENABLED(ARC_SUPPORT)
736
-  void plan_arc(float target[XYZE], float* offset, uint8_t clockwise);
736
+  void plan_arc(const float (&cart)[XYZE], const float (&offset)[2], const bool clockwise);
737
 #endif
737
 #endif
738
 
738
 
739
 #if ENABLED(BEZIER_CURVE_SUPPORT)
739
 #if ENABLED(BEZIER_CURVE_SUPPORT)
740
-  void plan_cubic_move(const float offset[4]);
740
+  void plan_cubic_move(const float (&offset)[4]);
741
 #endif
741
 #endif
742
 
742
 
743
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
743
 void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
1808
 
1808
 
1809
 #elif ENABLED(Z_PROBE_ALLEN_KEY)
1809
 #elif ENABLED(Z_PROBE_ALLEN_KEY)
1810
 
1810
 
1811
-  FORCE_INLINE void do_blocking_move_to(const float raw[XYZ], const float &fr_mm_s) {
1811
+  FORCE_INLINE void do_blocking_move_to(const float (&raw)[XYZ], const float &fr_mm_s) {
1812
     do_blocking_move_to(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], fr_mm_s);
1812
     do_blocking_move_to(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], fr_mm_s);
1813
   }
1813
   }
1814
 
1814
 
8326
 
8326
 
8327
 #ifdef M114_DETAIL
8327
 #ifdef M114_DETAIL
8328
 
8328
 
8329
-  void report_xyze(const float pos[XYZE], const uint8_t n = 4, const uint8_t precision = 3) {
8329
+  void report_xyze(const float pos[], const uint8_t n = 4, const uint8_t precision = 3) {
8330
     char str[12];
8330
     char str[12];
8331
     for (uint8_t i = 0; i < n; i++) {
8331
     for (uint8_t i = 0; i < n; i++) {
8332
       SERIAL_CHAR(' ');
8332
       SERIAL_CHAR(' ');
8337
     SERIAL_EOL();
8337
     SERIAL_EOL();
8338
   }
8338
   }
8339
 
8339
 
8340
-  inline void report_xyz(const float pos[XYZ]) { report_xyze(pos, 3); }
8340
+  inline void report_xyz(const float pos[]) { report_xyze(pos, 3); }
8341
 
8341
 
8342
   void report_current_position_detail() {
8342
   void report_current_position_detail() {
8343
 
8343
 
12659
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
12659
    * For Unified Bed Leveling (Delta or Segmented Cartesian)
12660
    * the ubl.prepare_segmented_line_to method replaces this.
12660
    * the ubl.prepare_segmented_line_to method replaces this.
12661
    */
12661
    */
12662
-  inline bool prepare_kinematic_move_to(float rtarget[XYZE]) {
12662
+  inline bool prepare_kinematic_move_to(const float (&rtarget)[XYZE]) {
12663
 
12663
 
12664
     // Get the top feedrate of the move in the XY plane
12664
     // Get the top feedrate of the move in the XY plane
12665
     const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
12665
     const float _feedrate_mm_s = MMS_SCALED(feedrate_mm_s);
12968
    * options for G2/G3 arc generation. In future these options may be GCode tunable.
12968
    * options for G2/G3 arc generation. In future these options may be GCode tunable.
12969
    */
12969
    */
12970
   void plan_arc(
12970
   void plan_arc(
12971
-    float raw[XYZE],     // Destination position
12972
-    float *offset,       // Center of rotation relative to current_position
12973
-    uint8_t clockwise    // Clockwise?
12971
+    const float (&cart)[XYZE], // Destination position
12972
+    const float (&offset)[2], // Center of rotation relative to current_position
12973
+    const bool clockwise      // Clockwise?
12974
   ) {
12974
   ) {
12975
     #if ENABLED(CNC_WORKSPACE_PLANES)
12975
     #if ENABLED(CNC_WORKSPACE_PLANES)
12976
       AxisEnum p_axis, q_axis, l_axis;
12976
       AxisEnum p_axis, q_axis, l_axis;
12990
     const float radius = HYPOT(r_P, r_Q),
12990
     const float radius = HYPOT(r_P, r_Q),
12991
                 center_P = current_position[p_axis] - r_P,
12991
                 center_P = current_position[p_axis] - r_P,
12992
                 center_Q = current_position[q_axis] - r_Q,
12992
                 center_Q = current_position[q_axis] - r_Q,
12993
-                rt_X = raw[p_axis] - center_P,
12994
-                rt_Y = raw[q_axis] - center_Q,
12995
-                linear_travel = raw[l_axis] - current_position[l_axis],
12996
-                extruder_travel = raw[E_AXIS] - current_position[E_AXIS];
12993
+                rt_X = cart[p_axis] - center_P,
12994
+                rt_Y = cart[q_axis] - center_Q,
12995
+                linear_travel = cart[l_axis] - current_position[l_axis],
12996
+                extruder_travel = cart[E_AXIS] - current_position[E_AXIS];
12997
 
12997
 
12998
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
12998
     // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
12999
     float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
12999
     float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
13001
     if (clockwise) angular_travel -= RADIANS(360);
13001
     if (clockwise) angular_travel -= RADIANS(360);
13002
 
13002
 
13003
     // Make a circle if the angular rotation is 0 and the target is current position
13003
     // Make a circle if the angular rotation is 0 and the target is current position
13004
-    if (angular_travel == 0 && current_position[p_axis] == raw[p_axis] && current_position[q_axis] == raw[q_axis])
13004
+    if (angular_travel == 0 && current_position[p_axis] == cart[p_axis] && current_position[q_axis] == cart[q_axis])
13005
       angular_travel = RADIANS(360);
13005
       angular_travel = RADIANS(360);
13006
 
13006
 
13007
     const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
13007
     const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
13101
     }
13101
     }
13102
 
13102
 
13103
     // Ensure last segment arrives at target location.
13103
     // Ensure last segment arrives at target location.
13104
-    planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder);
13104
+    planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
13105
 
13105
 
13106
     // As far as the parser is concerned, the position is now == target. In reality the
13106
     // As far as the parser is concerned, the position is now == target. In reality the
13107
     // motion control system might still be processing the action and the real tool position
13107
     // motion control system might still be processing the action and the real tool position
13113
 
13113
 
13114
 #if ENABLED(BEZIER_CURVE_SUPPORT)
13114
 #if ENABLED(BEZIER_CURVE_SUPPORT)
13115
 
13115
 
13116
-  void plan_cubic_move(const float offset[4]) {
13116
+  void plan_cubic_move(const float (&offset)[4]) {
13117
     cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
13117
     cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
13118
 
13118
 
13119
     // As far as the parser is concerned, the position is now == destination. In reality the
13119
     // As far as the parser is concerned, the position is now == destination. In reality the

+ 7
- 7
Marlin/planner.cpp Bestand weergeven

1455
   ZERO(previous_speed);
1455
   ZERO(previous_speed);
1456
 }
1456
 }
1457
 
1457
 
1458
-void Planner::set_position_mm_kinematic(const float position[NUM_AXIS]) {
1458
+void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
1459
   #if PLANNER_LEVELING
1459
   #if PLANNER_LEVELING
1460
-    float lpos[XYZ] = { position[X_AXIS], position[Y_AXIS], position[Z_AXIS] };
1461
-    apply_leveling(lpos);
1460
+    float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
1461
+    apply_leveling(raw);
1462
   #else
1462
   #else
1463
-    const float * const lpos = position;
1463
+    const float (&raw)[XYZE] = cart;
1464
   #endif
1464
   #endif
1465
   #if IS_KINEMATIC
1465
   #if IS_KINEMATIC
1466
-    inverse_kinematics(lpos);
1467
-    _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], position[E_AXIS]);
1466
+    inverse_kinematics(raw);
1467
+    _set_position_mm(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS]);
1468
   #else
1468
   #else
1469
-    _set_position_mm(lpos[X_AXIS], lpos[Y_AXIS], lpos[Z_AXIS], position[E_AXIS]);
1469
+    _set_position_mm(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS]);
1470
   #endif
1470
   #endif
1471
 }
1471
 }
1472
 
1472
 

+ 4
- 4
Marlin/planner.h Bestand weergeven

352
        * as it will be given to the planner and steppers.
352
        * as it will be given to the planner and steppers.
353
        */
353
        */
354
       static void apply_leveling(float &rx, float &ry, float &rz);
354
       static void apply_leveling(float &rx, float &ry, float &rz);
355
-      static void apply_leveling(float raw[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
355
+      static void apply_leveling(float (&raw)[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
356
       static void unapply_leveling(float raw[XYZ]);
356
       static void unapply_leveling(float raw[XYZ]);
357
 
357
 
358
     #else
358
     #else
417
      *  fr_mm_s  - (target) speed of the move (mm/s)
417
      *  fr_mm_s  - (target) speed of the move (mm/s)
418
      *  extruder - target extruder
418
      *  extruder - target extruder
419
      */
419
      */
420
-    FORCE_INLINE static void buffer_line_kinematic(const float cart[XYZE], const float &fr_mm_s, const uint8_t extruder) {
420
+    FORCE_INLINE static void buffer_line_kinematic(const float (&cart)[XYZE], const float &fr_mm_s, const uint8_t extruder) {
421
       #if PLANNER_LEVELING
421
       #if PLANNER_LEVELING
422
         float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
422
         float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
423
         apply_leveling(raw);
423
         apply_leveling(raw);
424
       #else
424
       #else
425
-        const float * const raw = cart;
425
+        const float (&raw)[XYZE] = cart;
426
       #endif
426
       #endif
427
       #if IS_KINEMATIC
427
       #if IS_KINEMATIC
428
         inverse_kinematics(raw);
428
         inverse_kinematics(raw);
447
       #endif
447
       #endif
448
       _set_position_mm(rx, ry, rz, e);
448
       _set_position_mm(rx, ry, rz, e);
449
     }
449
     }
450
-    static void set_position_mm_kinematic(const float position[NUM_AXIS]);
450
+    static void set_position_mm_kinematic(const float (&cart)[XYZE]);
451
     static void set_position_mm(const AxisEnum axis, const float &v);
451
     static void set_position_mm(const AxisEnum axis, const float &v);
452
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
452
     FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
453
     FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }
453
     FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }

+ 1
- 1
Marlin/ubl.h Bestand weergeven

319
         return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
319
         return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST);
320
       }
320
       }
321
 
321
 
322
-      static bool prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate);
322
+      static bool prepare_segmented_line_to(const float (&rtarget)[XYZE], const float &feedrate);
323
       static void line_to_destination_cartesian(const float &fr, uint8_t e);
323
       static void line_to_destination_cartesian(const float &fr, uint8_t e);
324
 
324
 
325
     #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
325
     #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])

+ 2
- 2
Marlin/ubl_motion.cpp Bestand weergeven

470
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
470
     // We don't want additional apply_leveling() performed by regular buffer_line or buffer_line_kinematic,
471
     // so we call buffer_segment directly here.  Per-segmented leveling and kinematics performed first.
471
     // so we call buffer_segment directly here.  Per-segmented leveling and kinematics performed first.
472
 
472
 
473
-    inline void _O2 ubl_buffer_segment_raw(const float raw[XYZE], const float &fr) {
473
+    inline void _O2 ubl_buffer_segment_raw(const float (&raw)[XYZE], const float &fr) {
474
 
474
 
475
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
475
       #if ENABLED(DELTA)  // apply delta inverse_kinematics
476
 
476
 
515
      * Returns true if did NOT move, false if moved (requires current_position update).
515
      * Returns true if did NOT move, false if moved (requires current_position update).
516
      */
516
      */
517
 
517
 
518
-    bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float rtarget[XYZE], const float &feedrate) {
518
+    bool _O2 unified_bed_leveling::prepare_segmented_line_to(const float (&in_target)[XYZE], const float &feedrate) {
519
 
519
 
520
       if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS]))  // fail if moving outside reachable boundary
520
       if (!position_is_reachable(rtarget[X_AXIS], rtarget[Y_AXIS]))  // fail if moving outside reachable boundary
521
         return true; // did not move, so current_position still accurate
521
         return true; // did not move, so current_position still accurate

Laden…
Annuleren
Opslaan