Skip to content

Commit

Permalink
Merge pull request bdring#279 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Feb 6, 2022
2 parents 019d370 + 868f462 commit 343dcf6
Show file tree
Hide file tree
Showing 29 changed files with 1,541 additions and 961 deletions.
Binary file modified FluidNC/data/index.html.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions FluidNC/src/ControlPin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void ControlPin::init() {
attr = attr | Pin::Attr::PullUp;
}
_pin.setAttr(attr);
_pin.attachInterrupt<ControlPin, &ControlPin::handleISR>(this, CHANGE);
_pin.attachInterrupt(ISRHandler, CHANGE, this);
_rtVariable = false;
_value = _pin.read();
_value = _pin.read();
// Control pins must start in inactive state
if (_value) {
log_error(_legend << " pin is active at startup");
Expand Down
4 changes: 3 additions & 1 deletion FluidNC/src/ControlPin.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "Pin.h"
#include <esp_attr.h> // IRAM_ATTR

class ControlPin {
private:
Expand All @@ -9,7 +10,8 @@ class ControlPin {
volatile bool& _rtVariable;
const char* _legend;

void handleISR();
void IRAM_ATTR handleISR();
CreateISRHandlerFor(ControlPin, handleISR);

public:
ControlPin(volatile bool& rtVariable, const char* legend, char letter) :
Expand Down
3 changes: 3 additions & 0 deletions FluidNC/src/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ FileStream::FileStream(const char* filename, const char* mode, const char* defau
}
_fd = fopen(_path.c_str(), mode);
if (!_fd) {
if (_isSD) {
config->_sdCard->end();
}
throw strcmp(mode, "w") ? Error::FsFailedOpenFile : Error::FsFailedCreateFile;
}
}
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" {
}

class FileStream : public Channel {
bool _isSD;
bool _isSD = false;
FILE* _fd;
String _path;

Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Machine/LimitPin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace Machine {
attr = attr | Pin::Attr::PullUp;
}
_pin.setAttr(attr);
_pin.attachInterrupt<LimitPin, &LimitPin::handleISR>(this, CHANGE);
_pin.attachInterrupt(ISRHandler, CHANGE, this);

read();
}
Expand Down
4 changes: 3 additions & 1 deletion FluidNC/src/Machine/LimitPin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Machine {

void IRAM_ATTR handleISR();

CreateISRHandlerFor(LimitPin, handleISR);

void read();

public:
Expand All @@ -33,7 +35,7 @@ namespace Machine {

void init();
bool get() { return _value; }
void makeDualMask(); // makes this a mask for motor0 and motor1
void makeDualMask(); // makes this a mask for motor0 and motor1

~LimitPin();
};
Expand Down
24 changes: 14 additions & 10 deletions FluidNC/src/MotionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,11 @@ void mc_arc(float* target,
float rt_axis0 = target[axis_0] - center_axis0;
float rt_axis1 = target[axis_1] - center_axis1;

float previous_position[MAX_N_AXIS] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

uint16_t n;
auto n_axis = config->_axes->_numberAxis;
for (n = 0; n < n_axis; n++) {
previous_position[n] = position[n];

float previous_position[n_axis] = { 0.0 };
for (size_t i = 0; i < n_axis; i++) {
previous_position[i] = position[i];
}

// CCW angle between position and target from circle center. Only one atan2() trig computation required.
Expand All @@ -157,14 +156,12 @@ void mc_arc(float* target,
}
}

auto mconfig = config;

// NOTE: Segment end points are on the arc, which can lead to the arc diameter being smaller by up to
// (2x) arc_tolerance. For 99% of users, this is just fine. If a different arc segment fit
// is desired, i.e. least-squares, midpoint on arc, just change the mm_per_arc_segment calculation.
// For most uses, this value should not exceed 2000.
uint16_t segments =
uint16_t(floor(fabs(0.5 * angular_travel * radius) / sqrt(mconfig->_arcTolerance * (2 * radius - mconfig->_arcTolerance))));
uint16_t(floor(fabs(0.5 * angular_travel * radius) / sqrt(config->_arcTolerance * (2 * radius - config->_arcTolerance))));
if (segments) {
// Multiply inverse feed_rate to compensate for the fact that this movement is approximated
// by a number of discrete segments. The inverse feed_rate should be correct for the sum of
Expand All @@ -174,7 +171,11 @@ void mc_arc(float* target,
pl_data->motion.inverseTime = 0; // Force as feed absolute mode over arc segments.
}
float theta_per_segment = angular_travel / segments;
float linear_per_segment = (target[axis_linear] - position[axis_linear]) / segments;
float linear_per_segment[n_axis];
linear_per_segment[axis_linear] = (target[axis_linear] - position[axis_linear]) / segments;
for (size_t i = A_AXIS; i < n_axis; i++) {
linear_per_segment[i] = (target[i] - position[i]) / segments;
}
/* Vector rotation by transformation matrix: r is the original vector, r_T is the rotated vector,
and phi is the angle of rotation. Solution approach by Jens Geisler.
r_T = [cos(phi) -sin(phi);
Expand Down Expand Up @@ -229,7 +230,10 @@ void mc_arc(float* target,
// Update arc_target location
position[axis_0] = center_axis0 + r_axis0;
position[axis_1] = center_axis1 + r_axis1;
position[axis_linear] += linear_per_segment;
position[axis_linear] += linear_per_segment[axis_linear];
for (size_t i = A_AXIS; i < n_axis; i++) {
position[i] += linear_per_segment[i];
}
pl_data->feed_rate = original_feedrate; // This restores the feedrate kinematics may have altered
mc_linear(position, pl_data, previous_position);
previous_position[axis_0] = position[axis_0];
Expand Down
Loading

0 comments on commit 343dcf6

Please sign in to comment.