References are better for array args

This commit is contained in:
Scott Lahteine
2017-12-09 02:10:54 -06:00
parent 125c572d97
commit 73e32925e4
13 changed files with 48 additions and 42 deletions

View File

@ -261,16 +261,16 @@ void move_to(const float &rx, const float &ry, const float &z, const float &e_de
set_destination_from_current();
}
FORCE_INLINE void move_to(const float where[XYZE], const float &de) { move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); }
FORCE_INLINE void move_to(const float (&where)[XYZE], const float &de) { move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); }
void retract_filament(const float where[XYZE]) {
void retract_filament(const float (&where)[XYZE]) {
if (!g26_retracted) { // Only retract if we are not already retracted!
g26_retracted = true;
move_to(where, -1.0 * g26_retraction_multiplier);
}
}
void recover_filament(const float where[XYZE]) {
void recover_filament(const float (&where)[XYZE]) {
if (g26_retracted) { // Only un-retract if we are retracted.
move_to(where, 1.2 * g26_retraction_multiplier);
g26_retracted = false;

View File

@ -28,7 +28,7 @@
#if ENABLED(M114_DETAIL)
void report_xyze(const float pos[XYZE], const uint8_t n = 4, const uint8_t precision = 3) {
void report_xyze(const float pos[], const uint8_t n = 4, const uint8_t precision = 3) {
char str[12];
for (uint8_t i = 0; i < n; i++) {
SERIAL_CHAR(' ');
@ -39,7 +39,7 @@
SERIAL_EOL();
}
inline void report_xyz(const float pos[XYZ]) { report_xyze(pos, 3); }
inline void report_xyz(const float pos[]) { report_xyze(pos, 3); }
void report_current_position_detail() {

View File

@ -44,9 +44,9 @@
* options for G2/G3 arc generation. In future these options may be GCode tunable.
*/
void plan_arc(
float rtarget[XYZE], // Destination position
float *offset, // Center of rotation relative to current_position
uint8_t clockwise // Clockwise?
const float (&cart)[XYZE], // Destination position
const float (&offset)[2], // Center of rotation relative to current_position
const uint8_t clockwise // Clockwise?
) {
#if ENABLED(CNC_WORKSPACE_PLANES)
AxisEnum p_axis, q_axis, l_axis;
@ -66,10 +66,10 @@ void plan_arc(
const float radius = HYPOT(r_P, r_Q),
center_P = current_position[p_axis] - r_P,
center_Q = current_position[q_axis] - r_Q,
rt_X = rtarget[p_axis] - center_P,
rt_Y = rtarget[q_axis] - center_Q,
linear_travel = rtarget[l_axis] - current_position[l_axis],
extruder_travel = rtarget[E_AXIS] - current_position[E_AXIS];
rt_X = cart[p_axis] - center_P,
rt_Y = cart[q_axis] - center_Q,
linear_travel = cart[l_axis] - current_position[l_axis],
extruder_travel = cart[E_AXIS] - current_position[E_AXIS];
// CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
float angular_travel = ATAN2(r_P * rt_Y - r_Q * rt_X, r_P * rt_X + r_Q * rt_Y);
@ -77,7 +77,7 @@ void plan_arc(
if (clockwise) angular_travel -= RADIANS(360);
// Make a circle if the angular rotation is 0 and the target is current position
if (angular_travel == 0 && current_position[p_axis] == rtarget[p_axis] && current_position[q_axis] == rtarget[q_axis])
if (angular_travel == 0 && current_position[p_axis] == cart[p_axis] && current_position[q_axis] == cart[q_axis])
angular_travel = RADIANS(360);
const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
@ -177,7 +177,7 @@ void plan_arc(
}
// Ensure last segment arrives at target location.
planner.buffer_line_kinematic(rtarget, fr_mm_s, active_extruder);
planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
// As far as the parser is concerned, the position is now == target. In reality the
// motion control system might still be processing the action and the real tool position

View File

@ -27,7 +27,7 @@
#include "../../module/motion.h"
#include "../../module/planner_bezier.h"
void plan_cubic_move(const float offset[4]) {
void plan_cubic_move(const float (&offset)[4]) {
cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
// As far as the parser is concerned, the position is now == destination. In reality the
@ -62,7 +62,7 @@ void GcodeSuite::G5() {
get_destination_from_command();
const float offset[] = {
const float offset[4] = {
parser.linearval('I'),
parser.linearval('J'),
parser.linearval('P'),