Skip to content

Commit

Permalink
Merge pull request #1002 from bdring/FixResetCrash
Browse files Browse the repository at this point in the history
CRITICAL: Fix reset crash
  • Loading branch information
MitchBradley authored Aug 17, 2023
2 parents b1f1e8d + 97ce3e0 commit 5492088
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion FluidNC/src/I2SOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ int i2s_out_init(i2s_out_init_t& init_param) {
"I2SOutTask",
4096,
NULL,
2,
3,
nullptr,
CONFIG_ARDUINO_RUNNING_CORE // must run the task on same core
);
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/InputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ void InputFile::stopJob() {
//Report print stopped
_notifyf("File print canceled", "Reset during file job at line: %d", getLineNumber());
log_info("Reset during file job at line: " << getLineNumber());
_progress = "";
allChannels.kill(this);
}

Expand Down
11 changes: 7 additions & 4 deletions FluidNC/src/Kinematics/ParallelDelta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ namespace Kinematics {
const float tan30 = 1.0 / sqrt3;

// the geometry of the delta
float rf; // radius of the fixed side (length of motor cranks)
float re; // radius of end effector side (length of linkages)
float f; // sized of fixed side triangel
float e; // size of end effector side triangle
float rf; // radius of the fixed side (length of motor cranks)
float re; // radius of end effector side (length of linkages)
float f; // sized of fixed side triangel
float e; // size of end effector side triangle

static float last_angle[MAX_N_AXIS] = { 0.0 }; // A place to save the previous motor angles for distance/feed rate calcs
static float last_cartesian[MAX_N_AXIS] = { 0.0 }; // A place to save the previous motor angles for distance/feed rate calcs
Expand Down Expand Up @@ -196,6 +196,9 @@ namespace Kinematics {
float segment_dist = dist / ((float)segment_count); // distance of each segment...will be used for feedrate conversion

for (uint32_t segment = 1; segment <= segment_count; segment++) {
if (sys.abort) {
return true;
}
//log_debug("Segment:" << segment << " of " << segment_count);
// determine this segment's target
seg_target[X_AXIS] = position[X_AXIS] + (dx / float(segment_count) * segment);
Expand Down
3 changes: 3 additions & 0 deletions FluidNC/src/Kinematics/WallPlotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ namespace Kinematics {

// Calculate desired cartesian feedrate distance ratio. Same for each seg.
for (uint32_t segment = 1; segment <= segment_count; segment++) {
if (sys.abort) {
return true;
}
// calculate the cartesian end point of the next segment
for (size_t axis = X_AXIS; axis < n_axis; axis++) {
cartesian_segment_end[axis] += cartesian_segment_components[axis];
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void setup() {
}

void loop() {
vTaskPrioritySet(NULL, 2);
static int tries = 0;
try {
// Start the main loop. Processes program inputs and executes them.
Expand Down
6 changes: 0 additions & 6 deletions FluidNC/src/MotionControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ extern bool probe_succeeded; // Tracks if last probing cycle was successful.
// System motion commands must have a line number of zero.
const int PARKING_MOTION_LINE_NUMBER = 0;

// Execute linear motion in absolute millimeter coordinates. Feed rate given in millimeters/second
// unless invert_feed_rate is true. Then the feed_rate means that the motion should be completed in
// (1 minute)/feed_rate time.
bool cartesian_to_motors(float* target, plan_line_data_t* pl_data, float* position);
void motors_to_cartesian(float* cartesian, float* motors, int n_axis);

// Execute a linear motion in cartesian space.
bool mc_linear(float* target, plan_line_data_t* pl_data, float* position);

Expand Down
29 changes: 16 additions & 13 deletions FluidNC/src/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ void send_line(Channel& channel, const std::string& line) {

void output_loop(void* unused) {
while (true) {
// Block until a message is received
LogMessage message;
if (xQueueReceive(message_queue, &message, 0)) {
if (xQueueReceive(message_queue, &message, portMAX_DELAY)) {
if (message.isString) {
std::string* s = static_cast<std::string*>(message.line);
message.channel->println(s->c_str());
Expand All @@ -167,7 +168,6 @@ void output_loop(void* unused) {
message.channel->println(cp);
}
}
vTaskDelay(0);
}
}

Expand Down Expand Up @@ -222,7 +222,7 @@ void start_polling() {
16000,
// 8192, // size of task stack
0, // parameters
1, // priority
2, // priority
&outputTask, // task handle
SUPPORT_TASK_CORE // core
);
Expand All @@ -239,9 +239,9 @@ static void check_startup_state() {}

const uint32_t heapWarnThreshold = 15000;

uint32_t heapLowWater = UINT_MAX;
uint32_t heapLowWaterReported = UINT_MAX;
int32_t heapLowWaterReportTime = 0;
uint32_t heapLowWater = UINT_MAX;
uint32_t heapLowWaterReported = UINT_MAX;
int32_t heapLowWaterReportTime = 0;
void protocol_main_loop() {
start_polling();

Expand All @@ -259,7 +259,10 @@ void protocol_main_loop() {
Error status_code = execute_line(activeLine, *activeChannel, WebUI::AuthenticationLevel::LEVEL_GUEST);

// Tell the channel that the line has been processed.
activeChannel->ack(status_code);
// If the line was aborted, the channel could be invalid
if (!sys.abort) {
activeChannel->ack(status_code);
}

// Tell the input polling task that the line has been processed,
// so it can give us another one when available
Expand All @@ -270,8 +273,7 @@ void protocol_main_loop() {
protocol_auto_cycle_start();
protocol_execute_realtime(); // Runtime command check point.
if (sys.abort) {
stop_polling();
return; // Bail to main() program loop to reset system.
sys.abort = false;
}

// check to see if we should disable the stepper drivers
Expand All @@ -297,14 +299,14 @@ void protocol_main_loop() {
if (heapLowWater < heapLowWaterReported && heapLowWater < heapWarnThreshold) {
// typecast to uint32_t handles roll-over for this case
uint32_t ticksSinceReported = (getCpuTicks() - heapLowWaterReportTime);
uint32_t tickLimit = usToCpuTicks(200000);
// Report only if it has been a while since the last report or if the memory has
uint32_t tickLimit = usToCpuTicks(200000);
// Report only if it has been a while since the last report or if the memory has
// dropped significantly (2k bytes) since the last report.
// This prevents a cycle where the reporting itself consumes some heap and triggers another
// This prevents a cycle where the reporting itself consumes some heap and triggers another
// report, but the true minimum is reported eventually, and large drops are reported immediately.
if ((heapLowWater < heapLowWaterReported - 2048) || (ticksSinceReported > tickLimit)) {
log_warn("Low memory: " << heapLowWater << " bytes");
heapLowWaterReported = heapLowWater;
heapLowWaterReported = heapLowWater;
heapLowWaterReportTime = getCpuTicks();
}
}
Expand Down Expand Up @@ -809,6 +811,7 @@ static void protocol_do_late_reset() {

// do we need to stop a running file job?
allChannels.stopJob();
sys.abort = true;
}

void protocol_exec_rt_system() {
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Spindles/HuanyangSpindle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ namespace Spindles {
auto huanyang = static_cast<Huanyang*>(vfd);
huanyang->_minFrequency = value;

log_info(huanyang->name() << " PD005,PD011 Freq range (" << (huanyang->_minFrequency / 100) << ","
log_info(huanyang->name() << " PD0011, PD005 Freq range (" << (huanyang->_minFrequency / 100) << ","
<< (huanyang->_maxFrequency / 100) << ") Hz"
<< " (" << (huanyang->_minFrequency / 100 * 60) << "," << (huanyang->_maxFrequency / 100 * 60)
<< ") RPM");
Expand Down
2 changes: 2 additions & 0 deletions FluidNC/src/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ int32_t probe_steps[MAX_N_AXIS]; // Last probe position in steps.
void system_reset() {
// Reset system variables.
State prior_state = sys.state;
bool prior_abort = sys.abort;
memset(&sys, 0, sizeof(system_t)); // Clear system struct variable.
sys.state = prior_state;
sys.abort = prior_abort;
sys.f_override = FeedOverride::Default; // Set to 100%
sys.r_override = RapidOverride::Default; // Set to 100%
sys.spindle_speed_ovr = SpindleSpeedOverride::Default; // Set to 100%
Expand Down

0 comments on commit 5492088

Please sign in to comment.