From ec926b7cf1cc3f9b684ef76dc83c8e7c23353397 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Mon, 5 Sep 2016 16:09:05 -0700 Subject: [PATCH] More consistent variable naming style --- src/command.c | 8 +-- src/command.h | 4 +- src/config.h | 1 - src/gcode_parser.c | 4 +- src/homing.c | 10 ++-- src/huanyang.c | 6 +-- src/huanyang.h | 2 +- src/machine.c | 64 +++++++++++------------ src/machine.h | 119 +++++++++++++++++++++---------------------- src/motor.c | 16 +++--- src/motor.h | 8 +-- src/plan/arc.c | 18 +++---- src/plan/buffer.c | 62 +++++++++++----------- src/plan/buffer.h | 42 +++++++-------- src/plan/calibrate.c | 10 ++-- src/plan/command.c | 6 +-- src/plan/command.h | 2 +- src/plan/dwell.c | 6 +-- src/plan/exec.c | 26 +++++----- src/plan/exec.h | 2 +- src/plan/jog.c | 31 +++++------ src/plan/line.c | 12 ++--- src/plan/line.h | 2 +- src/plan/planner.c | 22 ++++---- src/plan/planner.h | 12 +++-- src/plan/state.c | 16 +++--- src/plan/state.h | 14 ++--- src/probing.c | 12 ++--- src/pwm_spindle.c | 8 +-- src/pwm_spindle.h | 2 +- src/spindle.c | 10 ++-- src/spindle.h | 4 +- src/stepper.c | 12 ++--- src/stepper.h | 2 +- src/tmc2660.c | 6 +-- src/util.c | 4 +- src/util.h | 2 +- 37 files changed, 294 insertions(+), 293 deletions(-) diff --git a/src/command.c b/src/command.c index 81ddbc3..d618d82 100644 --- a/src/command.c +++ b/src/command.c @@ -133,11 +133,11 @@ int command_exec(int argc, char *argv[]) { int i = command_find(argv[0]); if (i != -1) { - uint8_t minArgs = pgm_read_byte(&commands[i].minArgs); - uint8_t maxArgs = pgm_read_byte(&commands[i].maxArgs); + uint8_t min_args = pgm_read_byte(&commands[i].min_args); + uint8_t max_args = pgm_read_byte(&commands[i].max_args); - if (argc <= minArgs) return STAT_TOO_FEW_ARGUMENTS; - else if (maxArgs < argc - 1) return STAT_TOO_MANY_ARGUMENTS; + if (argc <= min_args) return STAT_TOO_FEW_ARGUMENTS; + else if (max_args < argc - 1) return STAT_TOO_MANY_ARGUMENTS; else { command_cb_t cb = pgm_read_word(&commands[i].cb); return cb(argc, argv); diff --git a/src/command.h b/src/command.h index c5ef5ba..cecc572 100644 --- a/src/command.h +++ b/src/command.h @@ -38,8 +38,8 @@ typedef uint8_t (*command_cb_t)(int argc, char *argv[]); typedef struct { const char *name; command_cb_t cb; - uint8_t minArgs; - uint8_t maxArgs; + uint8_t min_args; + uint8_t max_args; const char *help; } command_t; diff --git a/src/config.h b/src/config.h index 7dc92cf..82b895f 100644 --- a/src/config.h +++ b/src/config.h @@ -157,7 +157,6 @@ typedef enum { // Machine settings #define CHORDAL_TOLERANCE 0.01 // chordal accuracy for arc drawing -#define SOFT_LIMIT_ENABLE false #define JERK_MAX 50 // yes, that's km/min^3 #define JUNCTION_DEVIATION 0.05 // default value, in mm #define JUNCTION_ACCELERATION 100000 // centripetal corner acceleration diff --git a/src/gcode_parser.c b/src/gcode_parser.c index 0ada698..ed239a5 100644 --- a/src/gcode_parser.c +++ b/src/gcode_parser.c @@ -362,8 +362,8 @@ static stat_t _parse_gcode_block(char *buf) { // set initial state for new move memset(modals, 0, sizeof(modals)); // clear all parser values - memset(&mach.gf, 0, sizeof(GCodeState_t)); // clear all next-state flags - memset(&mach.gn, 0, sizeof(GCodeState_t)); // clear all next-state values + memset(&mach.gf, 0, sizeof(gcode_state_t)); // clear all next-state flags + memset(&mach.gn, 0, sizeof(gcode_state_t)); // clear all next-state values // get motion mode from previous block mach.gn.motion_mode = mach_get_motion_mode(); diff --git a/src/homing.c b/src/homing.c index 876dd24..046361d 100644 --- a/src/homing.c +++ b/src/homing.c @@ -51,12 +51,12 @@ typedef enum { HOMING_NOT_HOMED, // machine is not homed HOMING_HOMED, // machine is homed HOMING_WAITING, // machine waiting to be homed -} homingState_t; +} homing_state_t; /// persistent homing runtime variables -struct hmHomingSingleton { - homingState_t state; // homing cycle sub-state machine +typedef struct { + homing_state_t state; // homing cycle sub-state machine bool homed[AXES]; // individual axis homing flags // controls for homing cycle @@ -92,10 +92,10 @@ struct hmHomingSingleton { uint8_t saved_feed_rate_mode; // G93,G94 global setting float saved_feed_rate; // F setting float saved_jerk; // saved and restored for each axis homed -}; +} homing_t; -static struct hmHomingSingleton hm = {0}; +static homing_t hm = {0}; // G28.2 homing cycle diff --git a/src/huanyang.c b/src/huanyang.c index 7c3e518..639b807 100644 --- a/src/huanyang.c +++ b/src/huanyang.c @@ -114,7 +114,7 @@ typedef struct { bool connected; bool changed; bool estop; - machSpindleMode_t mode; + spindle_mode_t mode; float speed; float actual_freq; @@ -450,7 +450,7 @@ void huanyang_init() { } -void huanyang_set(machSpindleMode_t mode, float speed) { +void huanyang_set(spindle_mode_t mode, float speed) { if ((ha.mode != mode || ha.speed != speed) && !ha.estop) { if (ha.debug) STATUS_DEBUG("huanyang: mode=%d, speed=%0.2f", mode, speed); @@ -474,7 +474,7 @@ void huanyang_reset() { // Save settings uint8_t id = ha.id; - machSpindleMode_t mode = ha.mode; + spindle_mode_t mode = ha.mode; float speed = ha.speed; bool debug = ha.debug; diff --git a/src/huanyang.h b/src/huanyang.h index 6defa88..46efeac 100644 --- a/src/huanyang.h +++ b/src/huanyang.h @@ -31,7 +31,7 @@ void huanyang_init(); -void huanyang_set(machSpindleMode_t mode, float speed); +void huanyang_set(spindle_mode_t mode, float speed); void huanyang_reset(); void huanyang_rtc_callback(); void huanyang_estop(); diff --git a/src/machine.c b/src/machine.c index aaff4f7..1c159fc 100644 --- a/src/machine.c +++ b/src/machine.c @@ -194,19 +194,19 @@ machine_t mach = { // Machine State functions uint32_t mach_get_line() {return mach.gm.line;} -machMotionMode_t mach_get_motion_mode() {return mach.gm.motion_mode;} -machCoordSystem_t mach_get_coord_system() {return mach.gm.coord_system;} -machUnitsMode_t mach_get_units_mode() {return mach.gm.units_mode;} -machPlane_t mach_get_select_plane() {return mach.gm.select_plane;} -machPathControlMode_t mach_get_path_control() {return mach.gm.path_control;} -machDistanceMode_t mach_get_distance_mode() {return mach.gm.distance_mode;} -machFeedRateMode_t mach_get_feed_rate_mode() {return mach.gm.feed_rate_mode;} +motion_mode_t mach_get_motion_mode() {return mach.gm.motion_mode;} +coord_system_t mach_get_coord_system() {return mach.gm.coord_system;} +units_mode_t mach_get_units_mode() {return mach.gm.units_mode;} +plane_t mach_get_select_plane() {return mach.gm.select_plane;} +path_mode_t mach_get_path_control() {return mach.gm.path_control;} +distance_mode_t mach_get_distance_mode() {return mach.gm.distance_mode;} +feed_rate_mode_t mach_get_feed_rate_mode() {return mach.gm.feed_rate_mode;} uint8_t mach_get_tool() {return mach.gm.tool;} -machSpindleMode_t mach_get_spindle_mode() {return mach.gm.spindle_mode;} +spindle_mode_t mach_get_spindle_mode() {return mach.gm.spindle_mode;} float mach_get_feed_rate() {return mach.gm.feed_rate;} -PGM_P mp_get_units_mode_pgmstr(machUnitsMode_t mode) { +PGM_P mp_get_units_mode_pgmstr(units_mode_t mode) { switch (mode) { case INCHES: return PSTR("IN"); case MILLIMETERS: return PSTR("MM"); @@ -217,12 +217,12 @@ PGM_P mp_get_units_mode_pgmstr(machUnitsMode_t mode) { } -void mach_set_motion_mode(machMotionMode_t motion_mode) { +void mach_set_motion_mode(motion_mode_t motion_mode) { mach.gm.motion_mode = motion_mode; } -void mach_set_spindle_mode(machSpindleMode_t spindle_mode) { +void mach_set_spindle_mode(spindle_mode_t spindle_mode) { mach.gm.spindle_mode = spindle_mode; } @@ -573,21 +573,19 @@ void mach_set_model_target(float target[], float flag[]) { * be tested w/the other disabled, should that requirement ever arise. */ stat_t mach_test_soft_limits(float target[]) { -#ifdef SOFT_LIMIT_ENABLE - for (int axis = 0; axis < AXES; axis++) { - if (!mach_get_homed(axis)) continue; // don't test axes that arent homed + for (int axis = 0; axis < AXES; axis++) { + if (!mach_get_homed(axis)) continue; // don't test axes that arent homed - if (fp_EQ(mach.a[axis].travel_min, mach.a[axis].travel_max)) continue; + if (fp_EQ(mach.a[axis].travel_min, mach.a[axis].travel_max)) continue; - if (mach.a[axis].travel_min > DISABLE_SOFT_LIMIT && - target[axis] < mach.a[axis].travel_min) - return STAT_SOFT_LIMIT_EXCEEDED; + if (mach.a[axis].travel_min > DISABLE_SOFT_LIMIT && + target[axis] < mach.a[axis].travel_min) + return STAT_SOFT_LIMIT_EXCEEDED; - if (mach.a[axis].travel_max > DISABLE_SOFT_LIMIT && - target[axis] > mach.a[axis].travel_max) - return STAT_SOFT_LIMIT_EXCEEDED; - } -#endif + if (mach.a[axis].travel_max > DISABLE_SOFT_LIMIT && + target[axis] > mach.a[axis].travel_max) + return STAT_SOFT_LIMIT_EXCEEDED; + } return STAT_OK; } @@ -636,15 +634,15 @@ stat_t mach_alarm(const char *location, stat_t code) { // These functions assume input validation occurred upstream. /// G17, G18, G19 select axis plane -void mach_set_plane(machPlane_t plane) {mach.gm.select_plane = plane;} +void mach_set_plane(plane_t plane) {mach.gm.select_plane = plane;} /// G20, G21 -void mach_set_units_mode(machUnitsMode_t mode) {mach.gm.units_mode = mode;} +void mach_set_units_mode(units_mode_t mode) {mach.gm.units_mode = mode;} /// G90, G91 -void mach_set_distance_mode(machDistanceMode_t mode) { +void mach_set_distance_mode(distance_mode_t mode) { mach.gm.distance_mode = mode; } @@ -657,7 +655,7 @@ void mach_set_distance_mode(machDistanceMode_t mode) { * accomplished by calling mach_set_work_offsets() immediately * afterwards. */ -void mach_set_coord_offsets(machCoordSystem_t coord_system, float offset[], +void mach_set_coord_offsets(coord_system_t coord_system, float offset[], float flag[]) { if (coord_system < G54 || MAX_COORDS <= coord_system) return; @@ -668,7 +666,7 @@ void mach_set_coord_offsets(machCoordSystem_t coord_system, float offset[], /// G54-G59 -void mach_set_coord_system(machCoordSystem_t coord_system) { +void mach_set_coord_system(coord_system_t coord_system) { mach.gm.coord_system = coord_system; mach_set_work_offsets(); // set work offsets in the Gcode model } @@ -730,8 +728,8 @@ void mach_set_absolute_origin(float origin[], float flag[]) { for (int axis = 0; axis < AXES; axis++) if (fp_TRUE(flag[axis])) { value[axis] = TO_MILLIMETERS(origin[axis]); - mach.position[axis] = value[axis]; // set model position - mach.ms.target[axis] = value[axis]; // reset model target + mach.position[axis] = value[axis]; // set model position + mach.ms.target[axis] = value[axis]; // reset model target mp_set_planner_position(axis, value[axis]); // set mm position } @@ -854,14 +852,14 @@ void mach_set_feed_rate(float feed_rate) { } -/// G93, G94 See machFeedRateMode -void mach_set_feed_rate_mode(machFeedRateMode_t mode) { +/// G93, G94 +void mach_set_feed_rate_mode(feed_rate_mode_t mode) { mach.gm.feed_rate_mode = mode; } /// G61, G61.1, G64 -void mach_set_path_control(machPathControlMode_t mode) { +void mach_set_path_control(path_mode_t mode) { mach.gm.path_control = mode; } diff --git a/src/machine.h b/src/machine.h index 58a1f1c..50378c7 100644 --- a/src/machine.h +++ b/src/machine.h @@ -41,9 +41,9 @@ #define TO_MILLIMETERS(a) (mach.gm.units_mode == INCHES ? (a) * MM_PER_INCH : a) -/* The difference between machNextAction_t and machMotionMode_ is that - * machNextAction_t is used by the current block, and may carry non-modal - * commands, whereas machMotionMode_t persists across blocks as G modal group 1 +/* The difference between next_action_t and motion_mode_t is that + * next_action_t is used by the current block, and may carry non-modal + * commands, whereas motion_mode_t persists across blocks as G modal group 1 */ /// these are in order to optimized CASE statement @@ -63,7 +63,7 @@ typedef enum { NEXT_ACTION_RESUME_ORIGIN_OFFSETS, // G92.3 NEXT_ACTION_DWELL, // G4 NEXT_ACTION_STRAIGHT_PROBE, // G38.2 -} machNextAction_t; +} next_action_t; typedef enum { // G Modal Group 1 @@ -82,7 +82,7 @@ typedef enum { // G Modal Group 1 MOTION_MODE_CANNED_CYCLE_87, // G87 - back boring MOTION_MODE_CANNED_CYCLE_88, // G88 - boring, spindle stop, manual out MOTION_MODE_CANNED_CYCLE_89, // G89 - boring, dwell, feed out -} machMotionMode_t; +} motion_mode_t; typedef enum { // Used for detecting gcode errors. See NIST section 3.4 @@ -102,7 +102,7 @@ typedef enum { // Used for detecting gcode errors. See NIST section 3.4 MODAL_GROUP_M7, // {M3,M4,M5} spindle turning MODAL_GROUP_M8, // {M7,M8,M9} coolant MODAL_GROUP_M9, // {M48,M49} speed/feed override switches -} machModalGroup_t; +} modal_group_t; #define MODAL_GROUP_COUNT (MODAL_GROUP_M9 + 1) @@ -114,21 +114,21 @@ typedef enum { // plane - translates to: PLANE_XY, // G17 X Y Z PLANE_XZ, // G18 X Z Y PLANE_YZ, // G19 Y Z X -} machPlane_t; +} plane_t; typedef enum { INCHES, // G20 MILLIMETERS, // G21 DEGREES, // ABC axes (this value used for displays only) -} machUnitsMode_t; +} units_mode_t; typedef enum { ABSOLUTE_COORDS, // machine coordinate system G54, G55, G56, G57, G58, G59, MAX_COORDS, -} machCoordSystem_t; +} coord_system_t; /// G Modal Group 13 typedef enum { @@ -136,20 +136,20 @@ typedef enum { PATH_EXACT_PATH, PATH_EXACT_STOP, // G61.1 - stops at all corners PATH_CONTINUOUS, // G64 and typically the default mode -} machPathControlMode_t; +} path_mode_t; typedef enum { ABSOLUTE_MODE, // G90 INCREMENTAL_MODE, // G91 -} machDistanceMode_t; +} distance_mode_t; typedef enum { INVERSE_TIME_MODE, // G93 UNITS_PER_MINUTE_MODE, // G94 UNITS_PER_REVOLUTION_MODE, // G95 (unimplemented) -} machFeedRateMode_t; +} feed_rate_mode_t; typedef enum { @@ -157,7 +157,7 @@ typedef enum { ORIGIN_OFFSET_CANCEL, // G92.1 - zero out origin offsets ORIGIN_OFFSET_SUSPEND, // G92.2 - do not apply offsets, but preserve values ORIGIN_OFFSET_RESUME, // G92.3 - resume application of the suspended offsets -} machOriginOffset_t; +} origin_offset_t; typedef enum { @@ -165,7 +165,7 @@ typedef enum { PROGRAM_OPTIONAL_STOP, PROGRAM_PALLET_CHANGE_STOP, PROGRAM_END, -} machProgramFlow_t; +} program_flow_t; /// spindle state settings @@ -173,7 +173,7 @@ typedef enum { SPINDLE_OFF, SPINDLE_CW, SPINDLE_CCW, -} machSpindleMode_t; +} spindle_mode_t; /// mist and flood coolant states @@ -182,14 +182,14 @@ typedef enum { COOLANT_ON, // request coolant on or indicate both coolants are on COOLANT_MIST, // indicates mist coolant on COOLANT_FLOOD, // indicates flood coolant on -} machCoolantState_t; +} coolant_state_t; /// used for spindle and arc dir typedef enum { DIRECTION_CW, DIRECTION_CCW, -} machDirection_t; +} direction_t; /// axis modes (ordered: see _mach_get_feed_time()) @@ -199,7 +199,7 @@ typedef enum { AXIS_INHIBITED, // axis is computed but not activated AXIS_RADIUS, // rotary axis calibrated to circumference AXIS_MODE_MAX, -} machAxisMode_t; // ordering must be preserved. +} axis_mode_t; // ordering must be preserved. /* Gcode model - The following GCodeModel/GCodeInput structs are used: @@ -228,7 +228,7 @@ typedef struct { float target[AXES]; // XYZABC where the move should go float work_offset[AXES]; // offset from work coordinate system float move_time; // optimal time for move given axis constraints -} MoveState_t; +} move_state_t; /// Gcode model state @@ -239,33 +239,33 @@ typedef struct { uint8_t tool_select; // T - sets this value float feed_rate; // F - in mm/min or inverse time mode - machFeedRateMode_t feed_rate_mode; - float feed_rate_override_factor; // 1.0000 x F feed rate. + feed_rate_mode_t feed_rate_mode; + float feed_rate_override_factor; // 1.0000 x F feed rate bool feed_rate_override_enable; // M48, M49 float traverse_override_factor; // 1.0000 x traverse rate bool traverse_override_enable; float spindle_speed; // in RPM - machSpindleMode_t spindle_mode; + spindle_mode_t spindle_mode; float spindle_override_factor; // 1.0000 x S spindle speed bool spindle_override_enable; // true = override enabled - machMotionMode_t motion_mode; // Group 1 modal motion - machPlane_t select_plane; // G17, G18, G19 - machUnitsMode_t units_mode; // G20, G21 - machCoordSystem_t coord_system; // G54-G59 - select coordinate system 1-9 + motion_mode_t motion_mode; // Group 1 modal motion + plane_t select_plane; // G17, G18, G19 + units_mode_t units_mode; // G20, G21 + coord_system_t coord_system; // G54-G59 - select coordinate system 1-9 bool absolute_override; // G53 true = move in machine coordinates - machPathControlMode_t path_control; // G61 - machDistanceMode_t distance_mode; // G91 - machDistanceMode_t arc_distance_mode; // G91.1 + path_mode_t path_control; // G61 + distance_mode_t distance_mode; // G91 + distance_mode_t arc_distance_mode; // G91.1 bool mist_coolant; // true = mist on (M7), false = off (M9) bool flood_coolant; // true = flood on (M8), false = off (M9) - machNextAction_t next_action; // handles G group 1 moves & non-modals - machProgramFlow_t program_flow; // used only by the gcode_parser + next_action_t next_action; // handles G group 1 moves & non-modals + program_flow_t program_flow; // used only by the gcode_parser - // unimplemented gcode parameters + // TODO unimplemented gcode parameters // float cutter_radius; // D - cutter radius compensation (0 is off) // float cutter_length; // H - cutter length compensation (0 is off) @@ -275,14 +275,13 @@ typedef struct { bool tool_change; // M6 tool change flag float parameter; // P - dwell time in sec, G10 coord select - float arc_radius; // R - radius value in arc radius mode float arc_offset[3]; // IJK - used by arc commands -} GCodeState_t; +} gcode_state_t; typedef struct { - machAxisMode_t axis_mode; + axis_mode_t axis_mode; float feedrate_max; // max velocity in mm/min or deg/min float velocity_max; // max velocity in mm/min or deg/min float travel_max; // max work envelope for soft limits @@ -296,7 +295,7 @@ typedef struct { float latch_velocity; // homing latch velocity float latch_backoff; // backoff from switches prior to homing latch movement float zero_backoff; // backoff from switches for machine zero -} AxisConfig_t; +} axis_config_t; typedef struct { // struct to manage mach globals and cycles @@ -309,11 +308,11 @@ typedef struct { // struct to manage mach globals and cycles float g28_position[AXES]; // stored machine position for G28 float g30_position[AXES]; // stored machine position for G30 - AxisConfig_t a[AXES]; // settings for axes - MoveState_t ms; - GCodeState_t gm; // core gcode model state - GCodeState_t gn; // gcode input values - GCodeState_t gf; // gcode input flags + axis_config_t a[AXES]; // settings for axes + move_state_t ms; + gcode_state_t gm; // core gcode model state + gcode_state_t gn; // gcode input values + gcode_state_t gf; // gcode input flags } machine_t; @@ -322,22 +321,22 @@ extern machine_t mach; // machine controller singleton // Model state getters and setters uint32_t mach_get_line(); -machMotionMode_t mach_get_motion_mode(); -machCoordSystem_t mach_get_coord_system(); -machUnitsMode_t mach_get_units_mode(); -machPlane_t mach_get_select_plane(); -machPathControlMode_t mach_get_path_control(); -machDistanceMode_t mach_get_distance_mode(); -machFeedRateMode_t mach_get_feed_rate_mode(); +motion_mode_t mach_get_motion_mode(); +coord_system_t mach_get_coord_system(); +units_mode_t mach_get_units_mode(); +plane_t mach_get_select_plane(); +path_mode_t mach_get_path_control(); +distance_mode_t mach_get_distance_mode(); +feed_rate_mode_t mach_get_feed_rate_mode(); uint8_t mach_get_tool(); -machSpindleMode_t mach_get_spindle_mode(); +spindle_mode_t mach_get_spindle_mode(); inline float mach_get_spindle_speed() {return mach.gm.spindle_speed;} float mach_get_feed_rate(); -PGM_P mp_get_units_mode_pgmstr(machUnitsMode_t mode); +PGM_P mp_get_units_mode_pgmstr(units_mode_t mode); -void mach_set_motion_mode(machMotionMode_t motion_mode); -void mach_set_spindle_mode(machSpindleMode_t spindle_mode); +void mach_set_motion_mode(motion_mode_t motion_mode); +void mach_set_spindle_mode(spindle_mode_t spindle_mode); void mach_set_spindle_speed_parameter(float speed); void mach_set_tool_number(uint8_t tool); void mach_set_absolute_override(bool absolute_override); @@ -372,16 +371,16 @@ stat_t mach_alarm(const char *location, stat_t status); do {if (!(COND)) CM_ALARM(STAT_INTERNAL_ERROR);} while (0) // Representation (4.3.3) -void mach_set_plane(machPlane_t plane); -void mach_set_units_mode(machUnitsMode_t mode); -void mach_set_distance_mode(machDistanceMode_t mode); -void mach_set_coord_offsets(machCoordSystem_t coord_system, float offset[], - float flag[]); +void mach_set_plane(plane_t plane); +void mach_set_units_mode(units_mode_t mode); +void mach_set_distance_mode(distance_mode_t mode); +void mach_set_coord_offsets(coord_system_t coord_system, float offset[], + float flag[]); void mach_set_position(int axis, float position); void mach_set_absolute_origin(float origin[], float flag[]); -void mach_set_coord_system(machCoordSystem_t coord_system); +void mach_set_coord_system(coord_system_t coord_system); void mach_set_origin_offsets(float offset[], float flag[]); void mach_reset_origin_offsets(); void mach_suspend_origin_offsets(); @@ -396,8 +395,8 @@ stat_t mach_goto_g30_position(float target[], float flags[]); // Machining Attributes (4.3.5) void mach_set_feed_rate(float feed_rate); -void mach_set_feed_rate_mode(machFeedRateMode_t mode); -void mach_set_path_control(machPathControlMode_t mode); +void mach_set_feed_rate_mode(feed_rate_mode_t mode); +void mach_set_path_control(path_mode_t mode); // Machining Functions (4.3.6) stat_t mach_straight_feed(float target[], float flags[]); diff --git a/src/motor.c b/src/motor.c index 47c53e1..e6335d9 100644 --- a/src/motor.c +++ b/src/motor.c @@ -49,18 +49,18 @@ typedef enum { - MOTOR_IDLE, // motor stopped and may be partially energized + MOTOR_IDLE, // motor stopped and may be partially energized MOTOR_ENERGIZING, MOTOR_ACTIVE -} motorPowerState_t; +} motor_power_state_t; typedef struct { // Config uint8_t motor_map; // map motor to axis uint16_t microsteps; // microsteps per full step - machMotorPolarity_t polarity; - machMotorPowerMode_t power_mode; + motor_polarity_t polarity; + motor_power_mode_t power_mode; float step_angle; // degrees per whole step float travel_rev; // mm or deg of travel per motor revolution uint8_t step_pin; @@ -71,9 +71,9 @@ typedef struct { uint8_t dma_trigger; // Runtime state - motorPowerState_t power_state; // state machine for managing motor power + motor_power_state_t power_state; // state machine for managing motor power uint32_t timeout; - machMotorFlags_t flags; + motor_flags_t flags; int32_t encoder; uint16_t steps; uint8_t last_clock; @@ -82,7 +82,7 @@ typedef struct { uint8_t timer_clock; // clock divisor setting or zero for off uint16_t timer_period; // clock period counter bool positive; // step sign - machDirection_t direction; // travel direction corrected for polarity + direction_t direction; // travel direction corrected for polarity // Step error correction int32_t correction_holdoff; // count down segments between corrections @@ -311,7 +311,7 @@ stat_t motor_rtc_callback() { // called by controller void print_status_flags(uint8_t flags); -void motor_error_callback(int motor, machMotorFlags_t errors) { +void motor_error_callback(int motor, motor_flags_t errors) { if (motors[motor].power_state != MOTOR_ACTIVE) return; motors[motor].flags |= errors; diff --git a/src/motor.h b/src/motor.h index ba678e7..123289e 100644 --- a/src/motor.h +++ b/src/motor.h @@ -44,7 +44,7 @@ typedef enum { MOTOR_FLAG_OVERTEMP_WARN_bm | MOTOR_FLAG_OVERTEMP_bm | MOTOR_FLAG_SHORTED_bm) -} machMotorFlags_t; +} motor_flags_t; typedef enum { @@ -54,13 +54,13 @@ typedef enum { // de-powered out of cycle MOTOR_POWERED_ONLY_WHEN_MOVING, // idles shortly after stopped, even in cycle MOTOR_POWER_MODE_MAX_VALUE // for input range checking -} machMotorPowerMode_t; +} motor_power_mode_t; typedef enum { MOTOR_POLARITY_NORMAL, MOTOR_POLARITY_REVERSED -} machMotorPolarity_t; +} motor_polarity_t; void motor_init(); @@ -78,7 +78,7 @@ bool motor_energizing(); void motor_driver_callback(int motor); stat_t motor_rtc_callback(); -void motor_error_callback(int motor, machMotorFlags_t errors); +void motor_error_callback(int motor, motor_flags_t errors); void motor_load_move(int motor); void motor_end_move(int motor); diff --git a/src/plan/arc.c b/src/plan/arc.c index f24b7b8..42b3008 100644 --- a/src/plan/arc.c +++ b/src/plan/arc.c @@ -46,8 +46,8 @@ // See planner.h for MM_PER_ARC_SEGMENT and other arc setting #defines -typedef struct arArcSingleton { // persistent planner and runtime variables - uint8_t run_state; // runtime state machine sequence +typedef struct { + run_state_t run_state; // runtime state machine sequence float position[AXES]; // accumulating runtime position float offset[3]; // IJK offsets @@ -74,7 +74,7 @@ typedef struct arArcSingleton { // persistent planner and runtime variables float center_0; // center of circle at plane axis 0 (e.g. X for G17) float center_1; // center of circle at plane axis 1 (e.g. Y for G17) - MoveState_t ms; + move_state_t ms; } arc_t; arc_t arc = {0}; @@ -437,15 +437,15 @@ stat_t mach_arc_feed(float target[], float flags[], // arc endpoints // now get down to the rest of the work setting up the arc for execution mach.gm.motion_mode = motion_mode; - mach_set_work_offsets(); // Update resolved offsets - mach.ms.line = mach.gm.line; // copy line number - memcpy(&arc.ms, &mach.ms, sizeof(MoveState_t)); // context to arc singleton + mach_set_work_offsets(); // Update resolved offsets + mach.ms.line = mach.gm.line; // copy line number + memcpy(&arc.ms, &mach.ms, sizeof(move_state_t)); // context to arc singleton - copy_vector(arc.position, mach.position); // arc pos from gcode model + copy_vector(arc.position, mach.position); // arc pos from gcode model - arc.radius = TO_MILLIMETERS(radius); // set arc radius or zero + arc.radius = TO_MILLIMETERS(radius); // set arc radius or zero - arc.offset[0] = TO_MILLIMETERS(i); // offsets canonical form (mm) + arc.offset[0] = TO_MILLIMETERS(i); // offsets in mm arc.offset[1] = TO_MILLIMETERS(j); arc.offset[2] = TO_MILLIMETERS(k); diff --git a/src/plan/buffer.c b/src/plan/buffer.c index 0028e4c..8e70599 100644 --- a/src/plan/buffer.c +++ b/src/plan/buffer.c @@ -56,16 +56,16 @@ #include -typedef struct mpBufferPool { // ring buffer for sub-moves - volatile uint8_t buffers_available; // running count of available buffers - mpBuf_t *w; // get_write_buffer pointer - mpBuf_t *q; // queue_write_buffer pointer - mpBuf_t *r; // get/end_run_buffer pointer - mpBuf_t bf[PLANNER_BUFFER_POOL_SIZE]; // buffer storage -} mpBufferPool_t; +typedef struct { // ring buffer for sub-moves + volatile uint8_t buffers_available; // count of available buffers + mp_buffer_t *w; // get_write_buffer pointer + mp_buffer_t *q; // queue_write_buffer pointer + mp_buffer_t *r; // get/end_run_buffer pointer + mp_buffer_t bf[PLANNER_BUFFER_POOL_SIZE]; // buffer storage +} buffer_pool_t; -mpBufferPool_t mb; // move buffer queue +buffer_pool_t mb; // move buffer queue uint8_t mp_get_planner_buffer_room() { @@ -85,7 +85,7 @@ void mp_wait_for_buffer() { /// Initializes or resets buffers void mp_init_buffers() { - mpBuf_t *pv; + mp_buffer_t *pv; memset(&mb, 0, sizeof(mb)); // clear all values, pointers and status @@ -110,13 +110,13 @@ bool mp_queue_empty() {return mb.w == mb.r;} /// Get pointer to next available write buffer /// Returns pointer or 0 if no buffer available. -mpBuf_t *mp_get_write_buffer() { +mp_buffer_t *mp_get_write_buffer() { // get & clear a buffer if (mb.w->buffer_state == MP_BUFFER_EMPTY) { - mpBuf_t *w = mb.w; - mpBuf_t *nx = mb.w->nx; // save linked list pointers - mpBuf_t *pv = mb.w->pv; - memset(mb.w, 0, sizeof(mpBuf_t)); // clear all values + mp_buffer_t *w = mb.w; + mp_buffer_t *nx = mb.w->nx; // save linked list pointers + mp_buffer_t *pv = mb.w->pv; + memset(mb.w, 0, sizeof(mp_buffer_t)); // clear all values w->nx = nx; // restore pointers w->pv = pv; w->buffer_state = MP_BUFFER_LOADING; @@ -139,12 +139,12 @@ mpBuf_t *mp_get_write_buffer() { * buffer once it has been queued. Action may start on the buffer immediately, * invalidating its contents */ -void mp_commit_write_buffer(uint32_t line, moveType_t type) { +void mp_commit_write_buffer(uint32_t line, move_type_t type) { mp_state_running(); mb.q->ms.line = line; mb.q->move_type = type; - mb.q->move_state = MOVE_NEW; + mb.q->run_state = MOVE_NEW; mb.q->buffer_state = MP_BUFFER_QUEUED; mb.q = mb.q->nx; // advance the queued buffer pointer } @@ -156,7 +156,7 @@ void mp_commit_write_buffer(uint32_t line, moveType_t type) { * Returns 0 if no buffer available * The behavior supports continuations (iteration) */ -mpBuf_t *mp_get_run_buffer() { +mp_buffer_t *mp_get_run_buffer() { switch (mb.r->buffer_state) { case MP_BUFFER_QUEUED: // fresh buffer; becomes running if queued or pending mb.r->buffer_state = MP_BUFFER_RUNNING; @@ -182,32 +182,32 @@ void mp_free_run_buffer() { // EMPTY current run buf & adv to next /// Returns pointer to last buffer, i.e. last block (zero) -mpBuf_t *mp_get_last_buffer() { - mpBuf_t *bf = mp_get_run_buffer(); - mpBuf_t *bp; +mp_buffer_t *mp_get_last_buffer() { + mp_buffer_t *bf = mp_get_run_buffer(); + mp_buffer_t *bp; for (bp = bf; bp && bp->nx != bf; bp = mp_get_next_buffer(bp)) - if (bp->nx->move_state == MOVE_OFF) break; + if (bp->nx->run_state == MOVE_OFF) break; return bp; } /// Zeroes the contents of the buffer -void mp_clear_buffer(mpBuf_t *bf) { - mpBuf_t *nx = bf->nx; // save pointers - mpBuf_t *pv = bf->pv; - memset(bf, 0, sizeof(mpBuf_t)); - bf->nx = nx; // restore pointers +void mp_clear_buffer(mp_buffer_t *bf) { + mp_buffer_t *nx = bf->nx; // save pointers + mp_buffer_t *pv = bf->pv; + memset(bf, 0, sizeof(mp_buffer_t)); + bf->nx = nx; // restore pointers bf->pv = pv; } /// Copies the contents of bp into bf - preserves links -void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp) { - mpBuf_t *nx = bf->nx; // save pointers - mpBuf_t *pv = bf->pv; - memcpy(bf, bp, sizeof(mpBuf_t)); - bf->nx = nx; // restore pointers +void mp_copy_buffer(mp_buffer_t *bf, const mp_buffer_t *bp) { + mp_buffer_t *nx = bf->nx; // save pointers + mp_buffer_t *pv = bf->pv; + memcpy(bf, bp, sizeof(mp_buffer_t)); + bf->nx = nx; // restore pointers bf->pv = pv; } diff --git a/src/plan/buffer.h b/src/plan/buffer.h index 0e317ee..cde4784 100644 --- a/src/plan/buffer.h +++ b/src/plan/buffer.h @@ -38,41 +38,41 @@ typedef enum { MOVE_TYPE_ALINE, // acceleration planned line MOVE_TYPE_DWELL, // delay with no movement MOVE_TYPE_COMMAND, // general command -} moveType_t; +} move_type_t; typedef enum { MOVE_OFF, // move inactive (MUST BE ZERO) MOVE_NEW, // initial value MOVE_RUN, // general run state (for non-acceleration moves) -} moveState_t; +} run_state_t; // All the enums that equal zero must be zero. Don't change this -typedef enum { // bf->buffer_state values +typedef enum { MP_BUFFER_EMPTY, // struct is available for use (MUST BE 0) MP_BUFFER_LOADING, // being written ("checked out") MP_BUFFER_QUEUED, // in queue - MP_BUFFER_RUNNING // current running buffer -} bufferState_t; + MP_BUFFER_RUNNING, // current running buffer +} buffer_state_t; // Callbacks typedef void (*mach_exec_t)(float[], float[]); -struct mpBuffer; -typedef stat_t (*bf_func_t)(struct mpBuffer *bf); +struct mp_buffer_t; +typedef stat_t (*bf_func_t)(struct mp_buffer_t *bf); -typedef struct mpBuffer { // See Planning Velocity Notes - struct mpBuffer *pv; // pointer to previous buffer - struct mpBuffer *nx; // pointer to next buffer +typedef struct mp_buffer_t { // See Planning Velocity Notes + struct mp_buffer_t *pv; // pointer to previous buffer + struct mp_buffer_t *nx; // pointer to next buffer bf_func_t bf_func; // callback to buffer exec function mach_exec_t mach_func; // callback to machine - bufferState_t buffer_state; // used to manage queuing/dequeuing - moveType_t move_type; // used to dispatch to run routine - moveState_t move_state; // move state machine sequence + buffer_state_t buffer_state; // used to manage queuing/dequeuing + move_type_t move_type; // used to dispatch to run routine + run_state_t run_state; // run state machine sequence bool replannable; // true if move can be re-planned float unit[AXES]; // unit vector for axis scaling & planning @@ -97,22 +97,22 @@ typedef struct mpBuffer { // See Planning Velocity Notes float recip_jerk; // 1/Jm used for planning (computed & cached) float cbrt_jerk; // cube root of Jm (computed & cached) - MoveState_t ms; -} mpBuf_t; + move_state_t ms; +} mp_buffer_t; uint8_t mp_get_planner_buffer_room(); void mp_wait_for_buffer(); void mp_init_buffers(); bool mp_queue_empty(); -mpBuf_t *mp_get_write_buffer(); -void mp_commit_write_buffer(uint32_t line, moveType_t type); -mpBuf_t *mp_get_run_buffer(); +mp_buffer_t *mp_get_write_buffer(); +void mp_commit_write_buffer(uint32_t line, move_type_t type); +mp_buffer_t *mp_get_run_buffer(); void mp_free_run_buffer(); -mpBuf_t *mp_get_last_buffer(); +mp_buffer_t *mp_get_last_buffer(); /// Returns pointer to prev buffer in linked list #define mp_get_prev_buffer(b) (b->pv) /// Returns pointer to next buffer in linked list #define mp_get_next_buffer(b) (b->nx) -void mp_clear_buffer(mpBuf_t *bf); -void mp_copy_buffer(mpBuf_t *bf, const mpBuf_t *bp); +void mp_clear_buffer(mp_buffer_t *bf); +void mp_copy_buffer(mp_buffer_t *bf, const mp_buffer_t *bp); diff --git a/src/plan/calibrate.c b/src/plan/calibrate.c index 9346b9d..0709f48 100644 --- a/src/plan/calibrate.c +++ b/src/plan/calibrate.c @@ -76,11 +76,11 @@ typedef struct { static calibrate_t cal = {0}; -static stat_t _exec_calibrate(mpBuf_t *bf) { - if (bf->move_state == MOVE_NEW) bf->move_state = MOVE_RUN; +static stat_t _exec_calibrate(mp_buffer_t *bf) { + if (bf->run_state == MOVE_NEW) bf->run_state = MOVE_RUN; const float time = MIN_SEGMENT_TIME; // In minutes - const float maxDeltaV = JOG_ACCELERATION * time; + const float max_delta_v = JOG_ACCELERATION * time; if (rtc_expired(cal.wait)) switch (cal.state) { @@ -102,7 +102,7 @@ static stat_t _exec_calibrate(mpBuf_t *bf) { if (CAL_MIN_VELOCITY < cal.velocity) cal.stall_valid = true; if (cal.velocity < CAL_MIN_VELOCITY || CAL_TARGET_SG < cal.stallguard) - cal.velocity += maxDeltaV; + cal.velocity += max_delta_v; if (cal.stalled) { if (cal.reverse) { @@ -167,7 +167,7 @@ uint8_t command_calibrate(int argc, char *argv[]) { if (mp_get_cycle() != CYCLE_MACHINING || mp_get_state() != STATE_READY) return 0; - mpBuf_t *bf = mp_get_write_buffer(); + mp_buffer_t *bf = mp_get_write_buffer(); if (!bf) { CM_ALARM(STAT_BUFFER_FULL_FATAL); return 0; diff --git a/src/plan/command.c b/src/plan/command.c index b043887..8778f7f 100644 --- a/src/plan/command.c +++ b/src/plan/command.c @@ -53,7 +53,7 @@ /// Callback to execute command -static stat_t _exec_command(mpBuf_t *bf) { +static stat_t _exec_command(mp_buffer_t *bf) { st_prep_command(bf); return STAT_OK; } @@ -61,7 +61,7 @@ static stat_t _exec_command(mpBuf_t *bf) { /// Queue a synchronous Mcode, program control, or other command void mp_queue_command(mach_exec_t mach_exec, float *value, float *flag) { - mpBuf_t *bf = mp_get_write_buffer(); + mp_buffer_t *bf = mp_get_write_buffer(); if (!bf) { CM_ALARM(STAT_BUFFER_FULL_FATAL); @@ -82,7 +82,7 @@ void mp_queue_command(mach_exec_t mach_exec, float *value, float *flag) { } -void mp_command_callback(mpBuf_t *bf) { +void mp_command_callback(mp_buffer_t *bf) { // Use values & flags stored in mp_queue_command() bf->mach_func(bf->ms.target, bf->unit); diff --git a/src/plan/command.h b/src/plan/command.h index a337a30..8395f58 100644 --- a/src/plan/command.h +++ b/src/plan/command.h @@ -30,4 +30,4 @@ #include "plan/buffer.h" void mp_queue_command(mach_exec_t mach_exec, float *value, float *flag); -void mp_command_callback(mpBuf_t *bf); +void mp_command_callback(mp_buffer_t *bf); diff --git a/src/plan/dwell.c b/src/plan/dwell.c index 385f002..8eda647 100644 --- a/src/plan/dwell.c +++ b/src/plan/dwell.c @@ -38,7 +38,7 @@ /// Dwell execution -static stat_t _exec_dwell(mpBuf_t *bf) { +static stat_t _exec_dwell(mp_buffer_t *bf) { st_prep_dwell(bf->ms.move_time); // in seconds // free buffer & perform cycle_end if planner is empty @@ -50,14 +50,14 @@ static stat_t _exec_dwell(mpBuf_t *bf) { /// Queue a dwell stat_t mp_dwell(float seconds, int32_t line) { - mpBuf_t *bf = mp_get_write_buffer(); + mp_buffer_t *bf = mp_get_write_buffer(); // never supposed to fail if (!bf) return CM_ALARM(STAT_BUFFER_FULL_FATAL); bf->bf_func = _exec_dwell; // register callback to dwell start bf->ms.move_time = seconds; // in seconds, not minutes - bf->move_state = MOVE_NEW; + bf->run_state = MOVE_NEW; // must be final operation before exit mp_commit_write_buffer(line, MOVE_TYPE_DWELL); diff --git a/src/plan/exec.c b/src/plan/exec.c index 180c905..648e712 100644 --- a/src/plan/exec.c +++ b/src/plan/exec.c @@ -59,7 +59,7 @@ typedef struct { float segment_time; // actual time increment per aline segment float forward_diff[5]; // forward difference levels bool hold_planned; // true when a feedhold has been planned - moveSection_t section; // what section is the move in? + move_section_t section; // what section is the move in? bool section_new; // true if it's a new section } mp_exec_t; @@ -246,7 +246,7 @@ static stat_t _exec_aline_section(float length, float vin, float vout) { // len / avg. velocity float move_time = 2 * length / (vin + vout); - ex.segments = ceil(uSec(move_time) / NOM_SEGMENT_USEC); + ex.segments = ceil(usec(move_time) / NOM_SEGMENT_USEC); ex.segment_time = move_time / ex.segments; ex.segment_count = (uint32_t)ex.segments; @@ -348,7 +348,7 @@ static float _compute_next_segment_velocity() { * speed. */ static void _plan_hold() { - mpBuf_t *bp = mp_get_run_buffer(); // working buffer pointer + mp_buffer_t *bp = mp_get_run_buffer(); // working buffer pointer if (!bp) return; // Oops! nothing's running // Examine and process current buffer and compute length left for decel @@ -384,7 +384,7 @@ static void _plan_hold() { bp->length = available_length - braking_length; bp->delta_vmax = mp_get_target_velocity(0, bp->length, bp); bp->entry_vmax = 0; // set bp+0 as hold point - bp->move_state = MOVE_NEW; // tell _exec to re-use the bf buffer + bp->run_state = MOVE_NEW; // tell _exec to re-use the bf buffer } else { // Case 2: deceleration exceeds length remaining in buffer // Replan to minimum (but non-zero) exit velocity @@ -396,7 +396,7 @@ static void _plan_hold() { /// Initializes move runtime with a new planner buffer -static stat_t _exec_aline_init(mpBuf_t *bf) { +static stat_t _exec_aline_init(mp_buffer_t *bf) { // Remove zero length lines. Short lines have already been removed. if (fp_ZERO(bf->length)) { mp_runtime_set_busy(false); @@ -407,7 +407,7 @@ static stat_t _exec_aline_init(mpBuf_t *bf) { } // Take control of buffer - bf->move_state = MOVE_RUN; + bf->run_state = MOVE_RUN; bf->replannable = false; // Initialize move @@ -504,13 +504,13 @@ static stat_t _exec_aline_init(mpBuf_t *bf) { * * State transitions - hierarchical state machine: * - * bf->move_state transitions: + * bf->run_state transitions: * * from _NEW to _RUN on first call (sub_state set to _OFF) * from _RUN to _OFF on final call or just remain _OFF */ -stat_t mp_exec_aline(mpBuf_t *bf) { - if (bf->move_state == MOVE_OFF) return STAT_NOOP; // No more moves +stat_t mp_exec_aline(mp_buffer_t *bf) { + if (bf->run_state == MOVE_OFF) return STAT_NOOP; // No more moves stat_t status = STAT_OK; @@ -530,7 +530,7 @@ stat_t mp_exec_aline(mpBuf_t *bf) { // There are 3 things that can happen here depending on return conditions: // - // status bf->move_state Description + // status bf->run_state Description // ----------- -------------- ---------------------------------- // STAT_EAGAIN buffer has more segments to run // STAT_OK MOVE_RUN ex and bf buffers are done @@ -540,9 +540,9 @@ stat_t mp_exec_aline(mpBuf_t *bf) { mp_runtime_set_busy(false); bf->nx->replannable = false; // prevent overplanning (Note 2) if (fp_ZERO(ex.exit_velocity)) ex.segment_velocity = 0; - // Note, _plan_hold() may change bf->move_state to reuse this buffer so it + // Note, _plan_hold() may change bf->run_state to reuse this buffer so it // can plan the deceleration. - if (bf->move_state == MOVE_RUN) mp_free_run_buffer(); + if (bf->run_state == MOVE_RUN) mp_free_run_buffer(); } if (mp_get_state() == STATE_STOPPING && @@ -560,7 +560,7 @@ stat_t mp_exec_move() { if (mp_get_state() == STATE_ESTOPPED) return STAT_MACHINE_ALARMED; if (mp_get_state() == STATE_HOLDING) return STAT_NOOP; - mpBuf_t *bf = mp_get_run_buffer(); + mp_buffer_t *bf = mp_get_run_buffer(); if (!bf) return STAT_NOOP; // nothing running if (!bf->bf_func) return CM_ALARM(STAT_INTERNAL_ERROR); diff --git a/src/plan/exec.h b/src/plan/exec.h index cc9d174..00972b2 100644 --- a/src/plan/exec.h +++ b/src/plan/exec.h @@ -31,4 +31,4 @@ stat_t mp_exec_move(); -stat_t mp_exec_aline(mpBuf_t *bf); +stat_t mp_exec_aline(mp_buffer_t *bf); diff --git a/src/plan/jog.c b/src/plan/jog.c index 57fbfc6..bd29da2 100644 --- a/src/plan/jog.c +++ b/src/plan/jog.c @@ -46,15 +46,15 @@ typedef struct { float next_velocity[AXES]; float target_velocity[AXES]; float current_velocity[AXES]; -} jogRuntime_t; +} jog_runtime_t; -static jogRuntime_t jr; +static jog_runtime_t jr; -static stat_t _exec_jog(mpBuf_t *bf) { - if (bf->move_state == MOVE_OFF) return STAT_NOOP; - if (bf->move_state == MOVE_NEW) bf->move_state = MOVE_RUN; +static stat_t _exec_jog(mp_buffer_t *bf) { + if (bf->run_state == MOVE_OFF) return STAT_NOOP; + if (bf->run_state == MOVE_NEW) bf->run_state = MOVE_RUN; // Load next velocity if (!jr.writing) @@ -64,18 +64,19 @@ static stat_t _exec_jog(mpBuf_t *bf) { // Compute next line segment float target[AXES]; const float time = MIN_SEGMENT_TIME; // In minutes - const float maxDeltaV = JOG_ACCELERATION * time; - float velocitySqr = 0; + const float max_delta_v = JOG_ACCELERATION * time; + float velocity_sqr = 0; bool done = true; // Compute new axis velocities and target for (int axis = 0; axis < AXES; axis++) { - float targetV = jr.target_velocity[axis] * mach.a[axis].velocity_max; - float deltaV = targetV - jr.current_velocity[axis]; - float sign = deltaV < 0 ? -1 : 1; + float target_v = jr.target_velocity[axis] * mach.a[axis].velocity_max; + float delta_v = target_v - jr.current_velocity[axis]; + float sign = delta_v < 0 ? -1 : 1; - if (maxDeltaV < fabs(deltaV)) jr.current_velocity[axis] += maxDeltaV * sign; - else jr.current_velocity[axis] = targetV; + if (max_delta_v < fabs(delta_v)) + jr.current_velocity[axis] += max_delta_v * sign; + else jr.current_velocity[axis] = target_v; if (!fp_ZERO(jr.current_velocity[axis])) done = false; @@ -84,7 +85,7 @@ static stat_t _exec_jog(mpBuf_t *bf) { mp_runtime_get_position(axis) + time * jr.current_velocity[axis]; // Accumulate velocities squared - velocitySqr += square(jr.current_velocity[axis]); + velocity_sqr += square(jr.current_velocity[axis]); } // Check if we are done @@ -101,7 +102,7 @@ static stat_t _exec_jog(mpBuf_t *bf) { return STAT_NOOP; } - return mp_runtime_move_to_target(target, sqrt(velocitySqr), time); + return mp_runtime_move_to_target(target, sqrt(velocity_sqr), time); } @@ -129,7 +130,7 @@ uint8_t command_jog(int argc, char *argv[]) { if (!mp_jog_busy()) { // Should always be at least one free buffer - mpBuf_t *bf = mp_get_write_buffer(); + mp_buffer_t *bf = mp_get_write_buffer(); if (!bf) return STAT_BUFFER_FULL_FATAL; // Start diff --git a/src/plan/line.c b/src/plan/line.c index eccfb46..dc4b5b3 100644 --- a/src/plan/line.c +++ b/src/plan/line.c @@ -49,10 +49,10 @@ typedef struct { float jerk; // jerk values cached from previous block float recip_jerk; float cbrt_jerk; -} mpMoveMaster_t; +} move_master_t; -mpMoveMaster_t mm = {{0}}; // context for line planning +move_master_t mm = {{0}}; // context for line planning /// Set planner position for a single axis @@ -178,7 +178,7 @@ static float _get_junction_vmax(const float a_unit[], const float b_unit[]) { * accumulate and get executed once the accumulated error exceeds * the minimums. */ -stat_t mp_aline(MoveState_t *ms) { +stat_t mp_aline(move_state_t *ms) { // Compute some reusable terms float axis_length[AXES]; float axis_square[AXES]; @@ -220,7 +220,7 @@ stat_t mp_aline(MoveState_t *ms) { float delta_velocity = pow(length, 0.66666666) * mm.cbrt_jerk; float entry_velocity = 0; // pre-set as if no previous block - mpBuf_t *bf = mp_get_run_buffer(); + mp_buffer_t *bf = mp_get_run_buffer(); if (bf) { if (bf->replannable) // not optimally planned entry_velocity = bf->entry_velocity + bf->delta_vmax; @@ -234,7 +234,7 @@ stat_t mp_aline(MoveState_t *ms) { // Get a *cleared* buffer and setup move variables // Note, mp_free_run_buffer() initializes all buffer variables to zero - mpBuf_t *bf = mp_get_write_buffer(); // current move pointer + mp_buffer_t *bf = mp_get_write_buffer(); // current move pointer if (!bf) return CM_ALARM(STAT_BUFFER_FULL_FATAL); // never fails // Register callback to exec function @@ -242,7 +242,7 @@ stat_t mp_aline(MoveState_t *ms) { bf->length = length; // Copy model state into planner buffer - memcpy(&bf->ms, ms, sizeof(MoveState_t)); + memcpy(&bf->ms, ms, sizeof(move_state_t)); // Compute the unit vector and find the right jerk to use (combined // operations) To determine the jerk value to use for the block we diff --git a/src/plan/line.h b/src/plan/line.h index d6b008b..b49d446 100644 --- a/src/plan/line.h +++ b/src/plan/line.h @@ -30,4 +30,4 @@ #include "machine.h" void mp_set_planner_position(int axis, const float position); -stat_t mp_aline(MoveState_t *ms); +stat_t mp_aline(move_state_t *ms); diff --git a/src/plan/planner.c b/src/plan/planner.c index 2fd1cb6..b6090af 100644 --- a/src/plan/planner.c +++ b/src/plan/planner.c @@ -222,7 +222,7 @@ void mp_kinematics(const float travel[], float steps[]) { * of the tests, but it reduces execution time when you need it most - when * tons of pathologically short Gcode blocks are being thrown at you. */ -void mp_calculate_trapezoid(mpBuf_t *bf) { +void mp_calculate_trapezoid(mp_buffer_t *bf) { // RULE #1 of mp_calculate_trapezoid(): Don't change bf->length // // F case: Block is too short - run time < minimum segment time @@ -446,7 +446,7 @@ void mp_calculate_trapezoid(mpBuf_t *bf) { * (effective) first block and the bf. It sets entry, exit and * cruise v's from vmax's then calls trapezoid generation. * - * Variables that must be provided in the mpBuffers that will be processed: + * Variables that must be provided in the mp_buffer_ts that will be processed: * * bf (function arg) - end of block list (last block in time) * bf->replannable - start of block list set by last FALSE value @@ -476,7 +476,7 @@ void mp_calculate_trapezoid(mpBuf_t *bf) { * * Variables that are ignored but here's what you would expect them to be: * - * bf->move_state - NEW for all blocks but the earliest + * bf->run_state - NEW for all blocks but the earliest * bf->ms.target[] - block target position * bf->unit[] - block unit vector * bf->time - gets set later @@ -498,8 +498,8 @@ void mp_calculate_trapezoid(mpBuf_t *bf) { * replannable so the list can be recomputed regardless of * exact stops and previous replanning optimizations. */ -void mp_plan_block_list(mpBuf_t *bf) { - mpBuf_t *bp = bf; +void mp_plan_block_list(mp_buffer_t *bf) { + mp_buffer_t *bp = bf; // Backward planning pass. Find first block and update braking velocities. // By the end bp points to the buffer before the first block. @@ -539,12 +539,12 @@ void mp_plan_block_list(mpBuf_t *bf) { void mp_replan_blocks() { - mpBuf_t *bf = mp_get_run_buffer(); - mpBuf_t *bp = bf; + mp_buffer_t *bf = mp_get_run_buffer(); + mp_buffer_t *bp = bf; // Mark all blocks replanable while (true) { - if (bp->move_state != MOVE_OFF || fp_ZERO(bp->exit_velocity)) break; + if (bp->run_state != MOVE_OFF || fp_ZERO(bp->exit_velocity)) break; bp->replannable = true; bp = mp_get_next_buffer(bp); @@ -600,7 +600,8 @@ void mp_replan_blocks() { * [2] Cannot assume Vf >= Vi due to rounding errors and use of * PLANNER_VELOCITY_TOLERANCE necessitating the introduction of fabs() */ -float mp_get_target_length(const float Vi, const float Vf, const mpBuf_t *bf) { +float mp_get_target_length(const float Vi, const float Vf, + const mp_buffer_t *bf) { return fabs(Vi - Vf) * sqrt(fabs(Vi - Vf) * bf->recip_jerk); } @@ -671,7 +672,8 @@ float mp_get_target_length(const float Vi, const float Vf, const mpBuf_t *bf) { * * J'(x) = (2 * Vi * x - Vi^2 + 3 * x^2) / L^2 */ -float mp_get_target_velocity(const float Vi, const float L, const mpBuf_t *bf) { +float mp_get_target_velocity(const float Vi, const float L, + const mp_buffer_t *bf) { // 0 iterations (a reasonable estimate) float x = pow(L, 0.66666666) * bf->cbrt_jerk + Vi; // First estimate diff --git a/src/plan/planner.h b/src/plan/planner.h index e64308b..e5b620e 100644 --- a/src/plan/planner.h +++ b/src/plan/planner.h @@ -30,7 +30,7 @@ #pragma once -#include "machine.h" // used for GCodeState_t +#include "machine.h" // used for gcode_state_t #include "buffer.h" #include "util.h" @@ -70,13 +70,15 @@ typedef enum { SECTION_HEAD, // acceleration SECTION_BODY, // cruise SECTION_TAIL, // deceleration -} moveSection_t; +} move_section_t; void planner_init(); void mp_flush_planner(); void mp_kinematics(const float travel[], float steps[]); -void mp_plan_block_list(mpBuf_t *bf); +void mp_plan_block_list(mp_buffer_t *bf); void mp_replan_blocks(); -float mp_get_target_length(const float Vi, const float Vf, const mpBuf_t *bf); -float mp_get_target_velocity(const float Vi, const float L, const mpBuf_t *bf); +float mp_get_target_length(const float Vi, const float Vf, + const mp_buffer_t *bf); +float mp_get_target_velocity(const float Vi, const float L, + const mp_buffer_t *bf); diff --git a/src/plan/state.c b/src/plan/state.c index bd160bb..f700b79 100644 --- a/src/plan/state.c +++ b/src/plan/state.c @@ -41,8 +41,8 @@ typedef struct { - plannerState_t state; - plannerCycle_t cycle; + mp_state_t state; + mp_cycle_t cycle; bool hold_requested; bool flush_requested; @@ -54,11 +54,11 @@ typedef struct { static planner_state_t ps = {0}; -plannerState_t mp_get_state() {return ps.state;} -plannerCycle_t mp_get_cycle() {return ps.cycle;} +mp_state_t mp_get_state() {return ps.state;} +mp_cycle_t mp_get_cycle() {return ps.cycle;} -PGM_P mp_get_state_pgmstr(plannerState_t state) { +PGM_P mp_get_state_pgmstr(mp_state_t state) { switch (state) { case STATE_READY: return PSTR("READY"); case STATE_ESTOPPED: return PSTR("ESTOPPED"); @@ -71,7 +71,7 @@ PGM_P mp_get_state_pgmstr(plannerState_t state) { } -PGM_P mp_get_cycle_pgmstr(plannerCycle_t cycle) { +PGM_P mp_get_cycle_pgmstr(mp_cycle_t cycle) { switch (cycle) { case CYCLE_MACHINING: return PSTR("MACHINING"); case CYCLE_HOMING: return PSTR("HOMING"); @@ -84,7 +84,7 @@ PGM_P mp_get_cycle_pgmstr(plannerCycle_t cycle) { } -static void _set_state(plannerState_t state) { +static void _set_state(mp_state_t state) { if (ps.state == state) return; // No change if (ps.state == STATE_ESTOPPED) return; // Can't leave EStop state ps.state = state; @@ -92,7 +92,7 @@ static void _set_state(plannerState_t state) { } -void mp_set_cycle(plannerCycle_t cycle) { +void mp_set_cycle(mp_cycle_t cycle) { if (ps.cycle == cycle) return; // No change if (ps.state != STATE_READY) { diff --git a/src/plan/state.h b/src/plan/state.h index a8ca4a9..5708f1c 100644 --- a/src/plan/state.h +++ b/src/plan/state.h @@ -40,7 +40,7 @@ typedef enum { STATE_RUNNING, STATE_STOPPING, STATE_HOLDING, -} plannerState_t; +} mp_state_t; typedef enum { @@ -49,16 +49,16 @@ typedef enum { CYCLE_PROBING, CYCLE_CALIBRATING, CYCLE_JOGGING, -} plannerCycle_t; +} mp_cycle_t; -plannerState_t mp_get_state(); -plannerCycle_t mp_get_cycle(); +mp_state_t mp_get_state(); +mp_cycle_t mp_get_cycle(); -void mp_set_cycle(plannerCycle_t cycle); +void mp_set_cycle(mp_cycle_t cycle); -PGM_P mp_get_state_pgmstr(plannerState_t state); -PGM_P mp_get_cycle_pgmstr(plannerCycle_t cycle); +PGM_P mp_get_state_pgmstr(mp_state_t state); +PGM_P mp_get_cycle_pgmstr(mp_cycle_t cycle); bool mp_is_flushing(); bool mp_is_resuming(); diff --git a/src/probing.c b/src/probing.c index 69eee2b..3c1dc5a 100644 --- a/src/probing.c +++ b/src/probing.c @@ -50,17 +50,17 @@ typedef enum { PROBE_FAILED, // probe reached endpoint without triggering PROBE_SUCCEEDED, // probe was triggered, pb.results has position PROBE_WAITING, // probe is waiting to be started -} probeState_t; +} probe_state_t; -struct pbProbingSingleton { // persistent probing runtime variables - probeState_t state; +typedef struct { + probe_state_t state; float results[AXES]; // probing results void (*func)(); // binding for callback function state machine // state saved from gcode model - uint8_t saved_distance_mode; // G90,G91 global setting + uint8_t saved_distance_mode; // G90, G91 global setting uint8_t saved_coord_system; // G54 - G59 setting float saved_jerk[AXES]; // saved and restored for each axis @@ -68,10 +68,10 @@ struct pbProbingSingleton { // persistent probing runtime variables float start_position[AXES]; float target[AXES]; float flags[AXES]; -}; +} probing_t; -static struct pbProbingSingleton pb = {0}; +static probing_t pb = {0}; /* Note: When coding a cycle (like this one) you get to perform one diff --git a/src/pwm_spindle.c b/src/pwm_spindle.c index 7960d7a..89fb74a 100644 --- a/src/pwm_spindle.c +++ b/src/pwm_spindle.c @@ -40,10 +40,10 @@ typedef struct { bool reverse; bool enable_invert; bool estop; -} spindle_t; +} pwm_spindle_t; -static spindle_t spindle = { +static pwm_spindle_t spindle = { .freq = SPINDLE_PWM_FREQUENCY, .min_rpm = SPINDLE_MIN_RPM, .max_rpm = SPINDLE_MAX_RPM, @@ -55,7 +55,7 @@ static spindle_t spindle = { }; -static void _spindle_set_pwm(machSpindleMode_t mode, float speed) { +static void _spindle_set_pwm(spindle_mode_t mode, float speed) { if (mode == SPINDLE_OFF || speed < spindle.min_rpm || spindle.estop) { TIMER_PWM.CTRLA = 0; return; @@ -122,7 +122,7 @@ void pwm_spindle_init() { } -void pwm_spindle_set(machSpindleMode_t mode, float speed) { +void pwm_spindle_set(spindle_mode_t mode, float speed) { _spindle_set_dir(mode == SPINDLE_CW); _spindle_set_pwm(mode, speed); _spindle_set_enable(mode != SPINDLE_OFF && TIMER_PWM.CTRLA); diff --git a/src/pwm_spindle.h b/src/pwm_spindle.h index cb3ff68..2177876 100644 --- a/src/pwm_spindle.h +++ b/src/pwm_spindle.h @@ -31,5 +31,5 @@ void pwm_spindle_init(); -void pwm_spindle_set(machSpindleMode_t mode, float speed); +void pwm_spindle_set(spindle_mode_t mode, float speed); void pwm_spindle_estop(); diff --git a/src/spindle.c b/src/spindle.c index 24f8dfc..9209b0b 100644 --- a/src/spindle.c +++ b/src/spindle.c @@ -38,12 +38,12 @@ typedef enum { SPINDLE_TYPE_PWM, SPINDLE_TYPE_HUANYANG, -} spindleType_t; +} spindle_type_t; -static spindleType_t spindle_type = SPINDLE_TYPE; +static spindle_type_t spindle_type = SPINDLE_TYPE; -static void _spindle_set(machSpindleMode_t mode, float speed) { +static void _spindle_set(spindle_mode_t mode, float speed) { switch (spindle_type) { case SPINDLE_TYPE_PWM: pwm_spindle_set(mode, speed); break; case SPINDLE_TYPE_HUANYANG: huanyang_set(mode, speed); break; @@ -53,7 +53,7 @@ static void _spindle_set(machSpindleMode_t mode, float speed) { /// execute the spindle command (called from planner) static void _exec_spindle_control(float *value, float *flag) { - machSpindleMode_t mode = value[0]; + spindle_mode_t mode = value[0]; mach_set_spindle_mode(mode); _spindle_set(mode, mach.gm.spindle_speed); } @@ -74,7 +74,7 @@ void mach_spindle_init() { /// Queue the spindle command to the planner buffer -void mach_spindle_control(machSpindleMode_t mode) { +void mach_spindle_control(spindle_mode_t mode) { float value[AXES] = {mode}; mp_queue_command(_exec_spindle_control, value, value); } diff --git a/src/spindle.h b/src/spindle.h index 2ea2fcd..f4313c7 100644 --- a/src/spindle.h +++ b/src/spindle.h @@ -32,6 +32,6 @@ void mach_spindle_init(); -void mach_set_spindle_speed(float speed); // S parameter -void mach_spindle_control(machSpindleMode_t spindle_mode); // M3, M4, M5 +void mach_set_spindle_speed(float speed); // S parameter +void mach_spindle_control(spindle_mode_t spindle_mode); // M3, M4, M5 void mach_spindle_estop(); diff --git a/src/stepper.c b/src/stepper.c index 15cb871..f4db85b 100644 --- a/src/stepper.c +++ b/src/stepper.c @@ -51,11 +51,11 @@ typedef struct { uint16_t dwell; // Move prep - bool move_ready; // prepped move ready for loader - moveType_t move_type; + bool move_ready; // prepped move ready for loader + move_type_t move_type; uint16_t seg_period; uint32_t prep_dwell; - struct mpBuffer *bf; // used for command moves + mp_buffer_t *bf; // used for command moves } stepper_t; @@ -147,8 +147,8 @@ ISR(STEP_TIMER_ISR) { // We are done with this move st.move_type = MOVE_TYPE_NULL; - st.seg_period = 0; // clear timer - st.prep_dwell = 0; // clear dwell + st.seg_period = 0; // clear timer + st.prep_dwell = 0; // clear dwell st.move_ready = false; // flip the flag back // Request next move if not currently in a dwell. Requesting the next move @@ -198,7 +198,7 @@ stat_t st_prep_line(float travel_steps[], float error[], float seg_time) { /// Stage command to execution -void st_prep_command(mpBuf_t *bf) { +void st_prep_command(mp_buffer_t *bf) { if (st.move_ready) CM_ALARM(STAT_INTERNAL_ERROR); st.move_type = MOVE_TYPE_COMMAND; st.bf = bf; diff --git a/src/stepper.h b/src/stepper.h index ec9c37b..60ff1c9 100644 --- a/src/stepper.h +++ b/src/stepper.h @@ -40,5 +40,5 @@ void st_shutdown(); uint8_t st_is_busy(); stat_t st_prep_line(float travel_steps[], float following_error[], float segment_time); -void st_prep_command(mpBuf_t *bf); +void st_prep_command(mp_buffer_t *bf); void st_prep_dwell(float seconds); diff --git a/src/tmc2660.c b/src/tmc2660.c index 55c2523..59382e6 100644 --- a/src/tmc2660.c +++ b/src/tmc2660.c @@ -215,11 +215,11 @@ static bool _driver_read(int driver) { static void _spi_next() { - bool hasMore = _driver_read(spi.driver); + bool has_move = _driver_read(spi.driver); - //if (!hasMore) drivers[spi.driver].reg_valid = 0; + //if (!has_move) drivers[spi.driver].reg_valid = 0; - if (!hasMore && ++spi.driver == MOTORS) { + if (!has_move && ++spi.driver == MOTORS) { spi.driver = 0; TMC2660_TIMER.CTRLA = TMC2660_TIMER_ENABLE; return; diff --git a/src/util.c b/src/util.c index ad4cea5..a092782 100644 --- a/src/util.c +++ b/src/util.c @@ -105,8 +105,8 @@ float *set_vector_by_axis(float value, uint8_t axis) { * Implementation tip: Order the min and max values from most to least likely * in the calling args * - * (*) Macro min4 is about 20uSec, inline function version is closer to 10 - * uSec (Xmega 32 MHz) + * (*) Macro min4 is about 20usec, inline function version is closer to 10 + * usec (Xmega 32 MHz) * #define min3(a,b,c) (min(min(a,b),c)) * #define min4(a,b,c,d) (min(min(a,b),min(c,d))) * #define max3(a,b,c) (max(max(a,b),c)) diff --git a/src/util.h b/src/util.h index 332642b..d2e164e 100644 --- a/src/util.h +++ b/src/util.h @@ -117,7 +117,7 @@ uint16_t compute_checksum(char const *string, const uint16_t length); #define MM_PER_INCH 25.4 #define INCHES_PER_MM (1 / 25.4) #define MICROSECONDS_PER_MINUTE 60000000.0 -#define uSec(a) ((a) * MICROSECONDS_PER_MINUTE) +#define usec(a) ((a) * MICROSECONDS_PER_MINUTE) #define RADIAN 57.2957795 #ifndef M_SQRT3 -- 2.27.0