Skip to content

Commit

Permalink
Make a lot of stuff static
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Oct 3, 2024
1 parent c04d38b commit c65c1d9
Show file tree
Hide file tree
Showing 33 changed files with 205 additions and 175 deletions.
4 changes: 2 additions & 2 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Error gc_execute_line(char* line) {
bool nonmodalG38 = false; // Used for G38.6-9
bool isWaitOnInputDigital = false;

auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
float coord_data[MAX_N_AXIS]; // Used by WCO-related commands
uint8_t pValue; // Integer value of P word

Expand Down Expand Up @@ -1602,7 +1602,7 @@ Error gc_execute_line(char* line) {
// NOTE: Pass zero spindle speed for all restricted laser motions.
if (!disableLaser) {
pl_data->spindle_speed = gc_state.spindle_speed; // Record data for planner use.
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
// [5. Select tool ]: NOT SUPPORTED. Only tracks tool value.
// gc_state.tool = gc_block.values.t;
// [M6. Change tool ]:
Expand Down
6 changes: 3 additions & 3 deletions FluidNC/src/Kinematics/Cartesian.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Kinematics {

// Initialize the machine position
void Cartesian::init_position() {
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (size_t axis = 0; axis < n_axis; axis++) {
set_motor_steps(axis, 0); // Set to zeros
}
Expand Down Expand Up @@ -178,7 +178,7 @@ namespace Kinematics {

void Cartesian::constrain_jog(float* target, plan_line_data_t* pl_data, float* position) {
auto axes = config->_axes;
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;

float* current_position = get_mpos();
MotorMask lim_pin_state = limits_get_state();
Expand Down Expand Up @@ -237,7 +237,7 @@ namespace Kinematics {

bool Cartesian::invalid_line(float* cartesian) {
auto axes = config->_axes;
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;

for (int axis = 0; axis < n_axis; axis++) {
float coordinate = cartesian[axis];
Expand Down
8 changes: 4 additions & 4 deletions FluidNC/src/Kinematics/CoreXY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace Kinematics {
log_info("Kinematic system: " << name());

// A limit switch on either axis stops both motors
config->_axes->_axis[X_AXIS]->_motors[0]->limitOtherAxis(Y_AXIS);
config->_axes->_axis[Y_AXIS]->_motors[0]->limitOtherAxis(X_AXIS);
Axes::_axis[X_AXIS]->_motors[0]->limitOtherAxis(Y_AXIS);
Axes::_axis[Y_AXIS]->_motors[0]->limitOtherAxis(X_AXIS);
}

bool CoreXY::canHome(AxisMask axisMask) {
Expand Down Expand Up @@ -93,7 +93,7 @@ namespace Kinematics {
bool CoreXY::cartesian_to_motors(float* target, plan_line_data_t* pl_data, float* position) {
// log_debug("cartesian_to_motors position (" << position[X_AXIS] << "," << position[Y_AXIS] << ") target (" << target[X_AXIS] << "," << target[Y_AXIS] << ")");

auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;

float motors[n_axis];
transform_cartesian_to_motors(motors, target);
Expand Down Expand Up @@ -136,7 +136,7 @@ namespace Kinematics {
motors[X_AXIS] = (_x_scaler * cartesian[X_AXIS]) + cartesian[Y_AXIS];
motors[Y_AXIS] = (_x_scaler * cartesian[X_AXIS]) - cartesian[Y_AXIS];

auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (size_t axis = Z_AXIS; axis < n_axis; axis++) {
motors[axis] = cartesian[axis];
}
Expand Down
4 changes: 2 additions & 2 deletions FluidNC/src/Kinematics/ParallelDelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace Kinematics {
log_info("Kinematic system:" << name() << " soft_limits:" << _softLimits);

auto axes = config->_axes;
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;

// warn about axis soft limits
for (int axis = 0; axis < n_axis; axis++) {
Expand Down Expand Up @@ -293,7 +293,7 @@ namespace Kinematics {
auto axes = config->_axes;
auto n_axis = axes->_numberAxis;

config->_axes->set_disable(false);
Axes::set_disable(false);

// TODO deal with non kinematic axes above Z
for (int axis = 0; axis < 3; axis++) {
Expand Down
6 changes: 3 additions & 3 deletions FluidNC/src/Kinematics/WallPlotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Kinematics {
xy_to_lengths(0, 0, zero_left, zero_right);
last_motor_segment_end[0] = zero_left;
last_motor_segment_end[1] = zero_right;
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (size_t axis = Z_AXIS; axis < n_axis; axis++) {
last_motor_segment_end[axis] = 0.0;
}
Expand All @@ -36,7 +36,7 @@ namespace Kinematics {

// Initialize the machine position
void WallPlotter::init_position() {
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (size_t axis = 0; axis < n_axis; axis++) {
set_motor_steps(axis, 0); // Set to zeros
}
Expand Down Expand Up @@ -66,7 +66,7 @@ namespace Kinematics {
float dx, dy, dz; // segment distances in each cartesian axis
uint32_t segment_count; // number of segments the move will be broken in to.

auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;

float total_cartesian_distance = vector_distance(position, target, n_axis);
if (total_cartesian_distance == 0) {
Expand Down
10 changes: 5 additions & 5 deletions FluidNC/src/Limits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ MotorMask limits_get_state() {
bool limits_startup_check() { // return true if there is a hard limit error.
MotorMask lim_pin_state = limits_get_state();
if (lim_pin_state) {
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (size_t axis = 0; axis < n_axis; axis++) {
for (size_t motor = 0; motor < 2; motor++) {
if (bitnum_is_true(lim_pin_state, Machine::Axes::motor_bit(axis, motor))) {
log_warn("Active limit switch on " << config->_axes->axisName(axis) << " axis motor " << motor);
log_warn("Active limit switch on " << Axes::axisName(axis) << " axis motor " << motor);
}
}
}
}
return (config->_start->_checkLimits && (config->_axes->hardLimitMask() & lim_pin_state));
return (config->_start->_checkLimits && (Axes::hardLimitMask() & lim_pin_state));
}

// Called only from Kinematics canHome() methods, hence from states allowing homing
Expand Down Expand Up @@ -99,7 +99,7 @@ void limit_error() {
}

float limitsMaxPosition(size_t axis) {
auto axisConfig = config->_axes->_axis[axis];
auto axisConfig = Axes::_axis[axis];
auto homing = axisConfig->_homing;
auto mpos = homing ? homing->_mpos : 0;
auto maxtravel = axisConfig->_maxTravel;
Expand All @@ -108,7 +108,7 @@ float limitsMaxPosition(size_t axis) {
}

float limitsMinPosition(size_t axis) {
auto axisConfig = config->_axes->_axis[axis];
auto axisConfig = Axes::_axis[axis];
auto homing = axisConfig->_homing;
auto mpos = homing ? homing->_mpos : 0;
auto maxtravel = axisConfig->_maxTravel;
Expand Down
25 changes: 15 additions & 10 deletions FluidNC/src/Machine/Axes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ namespace Machine {

bool Axes::disabled = false;

Axes::Axes() : _axis() {
for (int i = 0; i < MAX_N_AXIS; ++i) {
_axis[i] = nullptr;
}
}
Pin Axes::_sharedStepperDisable;
Pin Axes::_sharedStepperReset;

uint32_t Axes::_homing_runs = 2; // Number of Approach/Pulloff cycles

int Axes::_numberAxis = 0;

Axis* Axes::_axis[MAX_N_AXIS] = { nullptr };

Axes::Axes() {}

void Axes::init() {
log_info("Axis count " << config->_axes->_numberAxis);
log_info("Axis count " << Axes::_numberAxis);

if (_sharedStepperDisable.defined()) {
_sharedStepperDisable.setAttr(Pin::Attr::Output);
Expand Down Expand Up @@ -72,8 +77,8 @@ namespace Machine {

if (!disable && disabled) {
disabled = false;
if (config->_stepping->_disableDelayUsecs) { // wait for the enable delay
delay_us(config->_stepping->_disableDelayUsecs);
if (Stepping::_disableDelayUsecs) { // wait for the enable delay
delay_us(Stepping::_disableDelayUsecs);
}
}
}
Expand Down Expand Up @@ -167,7 +172,7 @@ namespace Machine {

// Some small helpers to find the axis index and axis motor index for a given motor. This
// is helpful for some motors that need this info, as well as debug information.
size_t Axes::findAxisIndex(const MotorDrivers::MotorDriver* const driver) const {
size_t Axes::findAxisIndex(const MotorDrivers::MotorDriver* const driver) {
for (int i = 0; i < _numberAxis; ++i) {
for (int j = 0; j < Axis::MAX_MOTORS_PER_AXIS; ++j) {
if (_axis[i] != nullptr && _axis[i]->hasMotor(driver)) {
Expand All @@ -180,7 +185,7 @@ namespace Machine {
return SIZE_MAX;
}

size_t Axes::findAxisMotor(const MotorDrivers::MotorDriver* const driver) const {
size_t Axes::findAxisMotor(const MotorDrivers::MotorDriver* const driver) {
for (int i = 0; i < _numberAxis; ++i) {
if (_axis[i] != nullptr && _axis[i]->hasMotor(driver)) {
for (int j = 0; j < Axis::MAX_MOTORS_PER_AXIS; ++j) {
Expand Down
38 changes: 19 additions & 19 deletions FluidNC/src/Machine/Axes.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ namespace Machine {

static bool disabled;

Pin _sharedStepperDisable;
Pin _sharedStepperReset;
static Pin _sharedStepperDisable;
static Pin _sharedStepperReset;

uint32_t _homing_runs = 2; // Number of Approach/Pulloff cycles
static uint32_t _homing_runs; // Number of Approach/Pulloff cycles

inline char axisName(int index) { return index < MAX_N_AXIS ? _names[index] : '?'; } // returns axis letter
static inline char axisName(int index) { return index < MAX_N_AXIS ? _names[index] : '?'; } // returns axis letter

static inline size_t motor_bit(size_t axis, size_t motor) { return motor ? axis + 16 : axis; }
static inline AxisMask motors_to_axes(MotorMask motors) { return (motors & 0xffff) | (motors >> 16); }
static inline MotorMask axes_to_motors(AxisMask axes) { return axes | (axes << 16); }

int _numberAxis = 0;
Axis* _axis[MAX_N_AXIS];
static int _numberAxis;
static Axis* _axis[MAX_N_AXIS];

// Some small helpers to find the axis index and axis motor number for a given motor. This
// is helpful for some motors that need this info, as well as debug information.
size_t findAxisIndex(const MotorDrivers::MotorDriver* const motor) const;
size_t findAxisMotor(const MotorDrivers::MotorDriver* const motor) const;
static size_t findAxisIndex(const MotorDrivers::MotorDriver* const motor);
static size_t findAxisMotor(const MotorDrivers::MotorDriver* const motor);

MotorMask hardLimitMask();
static MotorMask hardLimitMask();

inline bool hasHardLimits() const {
for (int axis = 0; axis < _numberAxis; ++axis) {
Expand All @@ -66,23 +66,23 @@ namespace Machine {
return false;
}

void init();
static void init();

// These are used during homing cycles.
// The return value is a bitmask of axes that can home
MotorMask set_homing_mode(AxisMask homing_mask, bool isHoming);
static MotorMask set_homing_mode(AxisMask homing_mask, bool isHoming);

void set_disable(int axis, bool disable);
void set_disable(bool disable);
void step(uint8_t step_mask, uint8_t dir_mask);
void unstep();
void config_motors();
static void set_disable(int axis, bool disable);
static void set_disable(bool disable);
static void step(uint8_t step_mask, uint8_t dir_mask);
static void unstep();
static void config_motors();

std::string maskToNames(AxisMask mask);
static std::string maskToNames(AxisMask mask);

bool namesToMask(const char* names, AxisMask& mask);
static bool namesToMask(const char* names, AxisMask& mask);

std::string motorMaskToNames(MotorMask mask);
static std::string motorMaskToNames(MotorMask mask);

// Configuration helpers:
void group(Configuration::HandlerBase& handler) override;
Expand Down
26 changes: 13 additions & 13 deletions FluidNC/src/Machine/Homing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Machine {

void Homing::startMove(AxisMask axisMask, MotorMask motors, Phase phase, uint32_t& settle_ms) {
float rate;
float target[config->_axes->_numberAxis];
float target[Axes::_numberAxis];
axisVector(_phaseAxes, _phaseMotors, _phase, target, rate, _settling_ms);

plan_line_data_t plan_data = {};
Expand Down Expand Up @@ -318,7 +318,7 @@ namespace Machine {
return;
}

log_debug("Homing limited" << config->_axes->motorMaskToNames(limited));
log_debug("Homing limited" << Axes::motorMaskToNames(limited));

bool stop = config->_kinematics->limitReached(_phaseAxes, _phaseMotors, limited);

Expand All @@ -329,7 +329,7 @@ namespace Machine {
Stepper::reset(); // Stop moving

if (_phaseAxes) {
log_debug("Homing replan with " << config->_axes->maskToNames(_phaseAxes));
log_debug("Homing replan with " << Axes::maskToNames(_phaseAxes));

config->_kinematics->releaseMotors(_phaseAxes, _phaseMotors);

Expand Down Expand Up @@ -380,21 +380,21 @@ namespace Machine {
_cycleAxes = _remainingCycles.front();
_remainingCycles.pop();

log_debug("Homing Cycle " << config->_axes->maskToNames(_cycleAxes));
log_debug("Homing Cycle " << Axes::maskToNames(_cycleAxes));

_cycleAxes &= Machine::Axes::homingMask;
_cycleMotors = config->_axes->set_homing_mode(_cycleAxes, true);
_cycleMotors = Axes::set_homing_mode(_cycleAxes, true);

_phase = Phase::PrePulloff;
_runs = config->_axes->_homing_runs;
_runs = Axes::_homing_runs;
runPhase();
}

void Homing::fail(ExecAlarm alarm) {
Stepper::reset(); // Stop moving
send_alarm(alarm);
config->_axes->set_homing_mode(_cycleAxes, false); // tell motors homing is done...failed
config->_axes->set_disable(config->_stepping->_idleMsecs != 255);
Axes::set_homing_mode(_cycleAxes, false); // tell motors homing is done...failed
Axes::set_disable(Stepping::_idleMsecs != 255);
}

bool Homing::needsPulloff2(MotorMask motors) {
Expand Down Expand Up @@ -453,7 +453,7 @@ namespace Machine {
#if 0
static std::string axisNames(AxisMask axisMask) {
std::string retval = "";
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (size_t axis = 0; axis < n_axis; axis++) {
if (bitnum_is_true(axisMask, axis)) {
retval += Machine::Axes::_names[axis];
Expand All @@ -479,9 +479,9 @@ namespace Machine {
}

// Find any cycles that set the m_pos without motion
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (int axis = X_AXIS; axis < n_axis; axis++) {
auto homing = config->_axes->_axis[axis]->_homing;
auto homing = Axes::_axis[axis]->_homing;
if (homing && homing->_cycle == set_mpos_only) {
if (axisMask == 0 || axisMask & 1 << axis) {
float* mpos = get_mpos();
Expand Down Expand Up @@ -529,9 +529,9 @@ namespace Machine {

AxisMask Homing::axis_mask_from_cycle(int cycle) {
AxisMask axisMask = 0;
auto n_axis = config->_axes->_numberAxis;
auto n_axis = Axes::_numberAxis;
for (int axis = 0; axis < n_axis; axis++) {
auto axisConfig = config->_axes->_axis[axis];
auto axisConfig = Axes::_axis[axis];
auto homing = axisConfig->_homing;
if (homing && homing->_cycle == cycle) {
set_bitnum(axisMask, axis);
Expand Down
10 changes: 7 additions & 3 deletions FluidNC/src/Machine/LimitPin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Machine {
// Set a bitmap with bits to represent the axis and which motors are affected
// The bitmap looks like CBAZYX..cbazyx where motor0 motors are in the lower bits
_bitmask = 1 << Axes::motor_bit(axis, motor);
_legend = config->_axes->motorMaskToNames(_bitmask);
_legend = Axes::motorMaskToNames(_bitmask);
_legend += " ";
_legend += sDir;
_legend += " Limit";
Expand Down Expand Up @@ -87,7 +87,11 @@ namespace Machine {
// Make this switch act like an axis level switch. Both motors will report the same
// This should be called from a higher level object, that has the logic to figure out
// if this belongs to a dual motor, single switch axis
void LimitPin::makeDualMask() { _bitmask = Axes::axes_to_motors(Axes::motors_to_axes(_bitmask)); }
void LimitPin::makeDualMask() {
_bitmask = Axes::axes_to_motors(Axes::motors_to_axes(_bitmask));
}

void LimitPin::setExtraMotorLimit(int axis, int motorNum) { _pExtraLimited = &config->_axes->_axis[axis]->_motors[motorNum]->_limited; }
void LimitPin::setExtraMotorLimit(int axis, int motorNum) {
_pExtraLimited = &config->_axes->_axis[axis]->_motors[motorNum]->_limited;
}
}
Loading

0 comments on commit c65c1d9

Please sign in to comment.