Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SD card state to idle when file is not found #796

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ __vm/
*.vcxproj.filters
*.suo
Grbl_Esp32.ino.cpp
/packages
12 changes: 1 addition & 11 deletions Grbl_Esp32/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,7 @@ const int DWELL_TIME_STEP = 50; // Integer (1-255) (milliseconds)
// While this is experimental, it is intended to be the future default method after testing
//#define USE_RMT_STEPS

// Creates a delay between the direction pin setting and corresponding step pulse by creating
// another interrupt (Timer2 compare) to manage it. The main Grbl interrupt (Timer1 compare)
// sets the direction pins, and does not immediately set the stepper pins, as it would in
// normal operation. The Timer2 compare fires next to set the stepper pins after the step
// pulse delay time, and Timer2 overflow will complete the step pulse, except now delayed
// by the step pulse time plus the step pulse delay. (Thanks langwadt for the idea!)
// NOTE: Uncomment to enable. The recommended delay must be > 3us, and, when added with the
// user-supplied step pulse time, the total time must not exceed 127us. Reported successful
// values for certain setups have ranged from 5 to 20us.
// must use #define USE_RMT_STEPS for this to work
//#define STEP_PULSE_DELAY 10 // Step pulse delay in microseconds. Default disabled.
// STEP_PULSE_DELAY is now a setting...$Stepper/Direction/Delay

// The number of linear motions in the planner buffer to be planned at any give time. The vast
// majority of RAM that Grbl uses is based on this buffer size. Only increase if there is extra
Expand Down
6 changes: 5 additions & 1 deletion Grbl_Esp32/src/Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
# define DEFAULT_STEP_ENABLE_DELAY 0
#endif

#ifndef STEP_PULSE_DELAY
# define STEP_PULSE_DELAY 0
#endif

#ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME
# define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled)
#endif
Expand Down Expand Up @@ -674,4 +678,4 @@

#ifndef DEFAULT_USER_MACRO3
# define DEFAULT_USER_MACRO3 ""
#endif
#endif
22 changes: 11 additions & 11 deletions Grbl_Esp32/src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ std::map<Error, const char*> ErrorNames = {
{ Error::GcodeG43DynamicAxisError, "Gcode G43 dynamic axis error" },
{ Error::GcodeMaxValueExceeded, "Gcode max value exceeded" },
{ Error::PParamMaxExceeded, "P param max exceeded" },
{ Error::SdFailedMount, "SD failed mount" },
{ Error::SdFailedRead, "SD failed read" },
{ Error::SdFailedOpenDir, "SD failed to open directory" },
{ Error::SdDirNotFound, "SD directory not found" },
{ Error::SdFileEmpty, "SD file empty" },
{ Error::SdFileNotFound, "SD file not found" },
{ Error::SdFailedOpenFile, "SD failed to open file" },
{ Error::SdFailedBusy, "SD is busy" },
{ Error::SdFailedDelDir, "SD failed to delete directory" },
{ Error::SdFailedDelFile, "SD failed to delete file" },
{ Error::FsFailedMount, "Failed to mount device" },
{ Error::FsFailedRead, "Failed to read" },
{ Error::FsFailedOpenDir, "Failed to open directory" },
{ Error::FsDirNotFound, "Directory not found" },
{ Error::FsFileEmpty, "File empty" },
{ Error::FsFileNotFound, "File not found" },
{ Error::FsFailedOpenFile, "Failed to open file" },
{ Error::FsFailedBusy, "Device is busy" },
{ Error::FsFailedDelDir, "Failed to delete directory" },
{ Error::FsFailedDelFile, "Failed to delete file" },
{ Error::BtFailBegin, "Bluetooth failed to start" },
{ Error::WifiFailBegin, "WiFi failed to start" },
{ Error::NumberRange, "Number out of range for setting" },
Expand All @@ -79,5 +79,5 @@ std::map<Error, const char*> ErrorNames = {
{ Error::NvsSetFailed, "Failed to store setting" },
{ Error::NvsGetStatsFailed, "Failed to get setting status" },
{ Error::AuthenticationFailed, "Authentication failed!" },
{ Error::AnotherInterfaceBusy, "Another interface is busy"},
{ Error::AnotherInterfaceBusy, "Another interface is busy" },
};
20 changes: 10 additions & 10 deletions Grbl_Esp32/src/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ enum class Error : uint8_t {
GcodeG43DynamicAxisError = 37,
GcodeMaxValueExceeded = 38,
PParamMaxExceeded = 39,
SdFailedMount = 60, // SD Failed to mount
SdFailedRead = 61, // SD Failed to read file
SdFailedOpenDir = 62, // SD card failed to open directory
SdDirNotFound = 63, // SD Card directory not found
SdFileEmpty = 64, // SD Card directory not found
SdFileNotFound = 65, // SD Card file not found
SdFailedOpenFile = 66, // SD card failed to open file
SdFailedBusy = 67, // SD card is busy
SdFailedDelDir = 68,
SdFailedDelFile = 69,
FsFailedMount = 60, // SD Failed to mount
FsFailedRead = 61, // SD Failed to read file
FsFailedOpenDir = 62, // SD card failed to open directory
FsDirNotFound = 63, // SD Card directory not found
FsFileEmpty = 64, // SD Card directory not found
FsFileNotFound = 65, // SD Card file not found
FsFailedOpenFile = 66, // SD card failed to open file
FsFailedBusy = 67, // SD card is busy
FsFailedDelDir = 68,
FsFailedDelFile = 69,
BtFailBegin = 70, // Bluetooth failed to start
WifiFailBegin = 71, // WiFi failed to start
NumberRange = 80, // Setting number range problem
Expand Down
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ Error gc_execute_line(char* line, uint8_t client) {
#endif
// [10. Dwell ]:
if (gc_block.non_modal_command == NonModal::Dwell) {
mc_dwell(gc_block.values.p);
mc_dwell(int32_t(gc_block.values.p * 1000.0f));
}
// [11. Set active plane ]:
gc_state.modal.plane_select = gc_block.modal.plane_select;
Expand Down
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/Grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// Grbl versioning system
const char* const GRBL_VERSION = "1.3a";
const char* const GRBL_VERSION_BUILD = "20210226";
const char* const GRBL_VERSION_BUILD = "20210306";

//#include <sdkconfig.h>
#include <Arduino.h>
Expand Down
59 changes: 0 additions & 59 deletions Grbl_Esp32/src/Machines/3axis_rs485.h

This file was deleted.

12 changes: 6 additions & 6 deletions Grbl_Esp32/src/MotionControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Copyright (c) 2011-2016 Sungeun K. Jeon for Gnea Research LLC
Copyright (c) 2009-2011 Simen Svale Skogsrud

2018 - Bart Dring This file was modifed for use on the ESP32
CPU. Do not use this with Grbl for atMega328P
2018 - Bart Dring This file was modifed for use on the ESP32
CPU. Do not use this with Grbl for atMega328P

Grbl is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -226,12 +226,12 @@ void mc_arc(float* target,
}

// Execute dwell in seconds.
void mc_dwell(float seconds) {
if (seconds == 0 || sys.state == State::CheckMode) {
return;
bool mc_dwell(int32_t milliseconds) {
if (milliseconds <= 0 || sys.state == State::CheckMode) {
return false;
}
protocol_buffer_synchronize();
delay_sec(seconds, DwellMode::Dwell);
return delay_msec(milliseconds, DwellMode::Dwell);
}

// return true if the mask has exactly one bit set,
Expand Down
2 changes: 1 addition & 1 deletion Grbl_Esp32/src/MotionControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void mc_arc(float* target,
uint8_t is_clockwise_arc);

// Dwell for a specific number of seconds
void mc_dwell(float seconds);
bool mc_dwell(int32_t milliseconds);

// Perform homing cycle to locate machine zero. Requires limit switches.
void mc_homing_cycle(uint8_t cycle_mask);
Expand Down
14 changes: 12 additions & 2 deletions Grbl_Esp32/src/Motors/Motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ uint8_t motors_set_homing_mode(uint8_t homing_mask, bool isHoming) {
return can_home;
}

void motors_step(uint8_t step_mask, uint8_t dir_mask) {
bool motors_direction(uint8_t dir_mask) {
auto n_axis = number_axis->get();
//grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "motors_set_direction_pins:0x%02X", onMask);

Expand All @@ -493,7 +493,17 @@ void motors_step(uint8_t step_mask, uint8_t dir_mask) {
myMotor[axis][0]->set_direction(thisDir);
myMotor[axis][1]->set_direction(thisDir);
}

return true;
} else {
return false;
}
}

void motors_step(uint8_t step_mask) {
auto n_axis = number_axis->get();
//grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "motors_set_direction_pins:0x%02X", onMask);

// Turn on step pulses for motors that are supposed to step now
for (uint8_t axis = X_AXIS; axis < n_axis; axis++) {
if (bitnum_istrue(step_mask, axis)) {
Expand All @@ -513,4 +523,4 @@ void motors_unstep() {
myMotor[axis][0]->unstep();
myMotor[axis][1]->unstep();
}
}
}
3 changes: 2 additions & 1 deletion Grbl_Esp32/src/Motors/Motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void motors_read_settings();
// The return value is a bitmask of axes that can home
uint8_t motors_set_homing_mode(uint8_t homing_mask, bool isHoming);
void motors_set_disable(bool disable, uint8_t mask = B11111111); // default is all axes
void motors_step(uint8_t step_mask, uint8_t dir_mask);
bool motors_direction(uint8_t dir_mask);
void motors_step(uint8_t step_mask);
void motors_unstep();

void servoUpdateTask(void* pvParameters);
25 changes: 10 additions & 15 deletions Grbl_Esp32/src/Motors/RcServo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace Motors {
ledcSetup(_channel_num, SERVO_PULSE_FREQ, SERVO_PULSE_RES_BITS);
ledcAttachPin(_pwm_pin, _channel_num);
_current_pwm_duty = 0;

_disabled = true;
config_message();
startUpdateTask();
}
Expand Down Expand Up @@ -78,10 +78,6 @@ namespace Motors {

// sets the PWM to zero. This allows most servos to be manually moved
void RcServo::set_disable(bool disable) {
if (_disabled == disable) {
return;
}

_disabled = disable;
if (_disabled) {
_write_pwm(0);
Expand All @@ -107,11 +103,6 @@ namespace Motors {
if (_disabled)
return;

if (sys.state == State::Alarm) {
set_disable(true);
return;
}

read_settings();

mpos = system_convert_axis_steps_to_mpos(sys_position, _axis_index); // get the axis machine position in mm
Expand All @@ -127,10 +118,14 @@ namespace Motors {
}

void RcServo::read_settings() {
_pwm_pulse_min = SERVO_MIN_PULSE * rc_servo_cal_min->get();
_pwm_pulse_max = SERVO_MAX_PULSE * rc_servo_cal_max->get();

if (bitnum_istrue(dir_invert_mask->get(), _axis_index)) // normal direction
swap(_pwm_pulse_min, _pwm_pulse_max);
if (bitnum_istrue(dir_invert_mask->get(), _axis_index)) {
// swap the pwm values
_pwm_pulse_min = SERVO_MAX_PULSE * (1.0 + (1.0 - rc_servo_cal_min->get()));
_pwm_pulse_max = SERVO_MIN_PULSE * (1.0 + (1.0 - rc_servo_cal_max->get()));

} else {
_pwm_pulse_min = SERVO_MIN_PULSE * rc_servo_cal_min->get();
_pwm_pulse_max = SERVO_MAX_PULSE * rc_servo_cal_max->get();
}
}
}
20 changes: 10 additions & 10 deletions Grbl_Esp32/src/Motors/StandardStepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ namespace Motors {

StandardStepper::StandardStepper(uint8_t axis_index, uint8_t step_pin, uint8_t dir_pin, uint8_t disable_pin) :
Motor(axis_index), _step_pin(step_pin), _dir_pin(dir_pin), _disable_pin(disable_pin) {
#ifdef USE_RMT_STEPS
_rmt_chan_num = get_next_RMT_chan_num();
#endif
}

void StandardStepper::init() {
read_settings();
config_message();
}

void StandardStepper::read_settings() {
init_step_dir_pins();
}
void StandardStepper::read_settings() { init_step_dir_pins(); }

void StandardStepper::init_step_dir_pins() {
_invert_step_pin = bitnum_istrue(step_invert_mask->get(), _axis_index);
Expand All @@ -68,17 +69,13 @@ namespace Motors {
rmtConfig.tx_config.carrier_level = RMT_CARRIER_LEVEL_LOW;
rmtConfig.tx_config.idle_output_en = true;

# ifdef STEP_PULSE_DELAY
rmtItem[0].duration0 = STEP_PULSE_DELAY * 4;
# else
rmtItem[0].duration0 = 1;
# endif
auto stepPulseDelay = direction_delay_microseconds->get();
rmtItem[0].duration0 = stepPulseDelay < 1 ? 1 : stepPulseDelay * 4;

rmtItem[0].duration1 = 4 * pulse_microseconds->get();
rmtItem[1].duration0 = 0;
rmtItem[1].duration1 = 0;

_rmt_chan_num = get_next_RMT_chan_num();
if (_rmt_chan_num == RMT_CHANNEL_MAX) {
return;
}
Expand Down Expand Up @@ -126,5 +123,8 @@ namespace Motors {

void StandardStepper::set_direction(bool dir) { digitalWrite(_dir_pin, dir ^ _invert_dir_pin); }

void StandardStepper::set_disable(bool disable) { digitalWrite(_disable_pin, disable); }
void StandardStepper::set_disable(bool disable) {
disable ^= step_enable_invert->get();
digitalWrite(_disable_pin, disable);
}
}
13 changes: 9 additions & 4 deletions Grbl_Esp32/src/NutsBolts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,28 @@ void delay_ms(uint16_t ms) {
}

// Non-blocking delay function used for general operation and suspend features.
void delay_sec(float seconds, DwellMode mode) {
uint16_t i = ceil(1000 / DWELL_TIME_STEP * seconds);
bool delay_msec(int32_t milliseconds, DwellMode mode) {
// Note: i must be signed, because of the 'i-- > 0' check below.
int32_t i = milliseconds / DWELL_TIME_STEP;
int32_t remainder = i < 0 ? 0 : (milliseconds - DWELL_TIME_STEP * i);

while (i-- > 0) {
if (sys.abort) {
return;
return false;
}
if (mode == DwellMode::Dwell) {
protocol_execute_realtime();
} else { // DwellMode::SysSuspend
// Execute rt_system() only to avoid nesting suspend loops.
protocol_exec_rt_system();
if (sys.suspend.bit.restartRetract) {
return; // Bail, if safety door reopens.
return false; // Bail, if safety door reopens.
}
}
delay(DWELL_TIME_STEP); // Delay DWELL_TIME_STEP increment
}
delay(remainder);
return true;
}

// Simple hypotenuse computation function.
Expand Down
Loading