Skip to content

Commit

Permalink
Merge branch 'bugfix-2.0.x' of https://github.com/MarlinFirmware/Marlin
Browse files Browse the repository at this point in the history
… into bugfix-2.0.x-bltouch
  • Loading branch information
crysxd committed Jun 11, 2020
2 parents 6d2fcf0 + bbe8400 commit 4aa031b
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 51 deletions.
32 changes: 31 additions & 1 deletion Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,37 @@
// Enable additional compensation using hotend temperature
// Note: this values cannot be calibrated automatically but have to be set manually
//#define USE_TEMP_EXT_COMPENSATION

// Probe temperature calibration generates a table of values starting at PTC_SAMPLE_START
// (e.g. 30), in steps of PTC_SAMPLE_RES (e.g. 5) with PTC_SAMPLE_COUNT (e.g. 10) samples.

// #define PTC_SAMPLE_START 30.0f
// #define PTC_SAMPLE_RES 5.0f
// #define PTC_SAMPLE_COUNT 10U

// Bed temperature calibration builds a similar table.

// #define BTC_SAMPLE_START 60.0f
// #define BTC_SAMPLE_RES 5.0f
// #define BTC_SAMPLE_COUNT 10U

// The temperature the probe should be at while taking measurements during bed temperature
// calibration.
// #define BTC_PROBE_TEMP 30.0f

// Height above Z=0.0f to raise the nozzle. Lowering this can help the probe to heat faster.
// Note: the Z=0.0f offset is determined by the probe offset which can be set using M851.
// #define PTC_PROBE_HEATING_OFFSET 0.5f

// Height to raise the Z-probe between heating and taking the next measurement. Some probes
// may fail to untrigger if they have been triggered for a long time, which can be solved by
// increasing the height the probe is raised to.
// #define PTC_PROBE_RAISE 15U

// If the probe is outside of the defined range, use linear extrapolation using the closest
// point and the PTC_LINEAR_EXTRAPOLATION'th next point. E.g. if set to 4 it will use data[0]
// and data[4] to perform linear extrapolation for values below PTC_SAMPLE_START.
// #define PTC_LINEAR_EXTRAPOLATION 4
#endif
#endif

Expand Down Expand Up @@ -2667,7 +2698,6 @@

// Turn off the laser on G28 homing.
//#define LASER_MOVE_G28_OFF

#endif

/**
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/core/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@
#define BOARD_MKS_ROBIN_E3 4027 // MKS Robin E3 (STM32F103RCT6)
#define BOARD_MALYAN_M300 4028 // STM32F070-based delta
#define BOARD_CCROBOT_MEEB_3DP 4029 // ccrobot-online.com MEEB_3DP (STM32F103RC)
#define BOARD_CHITU3D_V5 4030 // Chitu3D TronXY X5SA V5 Board
#define BOARD_CHITU3D_V6 4031 // Chitu3D TronXY X5SA V5 Board

//
// ARM Cortex-M4F
Expand Down
43 changes: 28 additions & 15 deletions Marlin/src/feature/probe_temp_comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,28 +165,41 @@ void ProbeTempComp::compensate_measurement(const TempSensorID tsi, const float &
}

float ProbeTempComp::get_offset_for_temperature(const TempSensorID tsi, const float &temp) {

const uint8_t measurements = cali_info[tsi].measurements;
const float start_temp = cali_info[tsi].start_temp,
end_temp = cali_info[tsi].end_temp,
res_temp = cali_info[tsi].temp_res;
const int16_t * const data = sensor_z_offsets[tsi];

if (temp <= start_temp) return 0.0f;
if (temp >= end_temp) return static_cast<float>(data[measurements - 1]) / 1000.0f;
auto point = [&](uint8_t i) {
return xy_float_t({start_temp + i*res_temp, static_cast<float>(data[i])});
};

auto linear_interp = [](float x, xy_float_t p1, xy_float_t p2) {
return (p2.y - p1.y) / (p2.x - p2.y) * (x - p1.x) + p1.y;
};

// Linear interpolation
int16_t val1 = 0, val2 = data[0];
uint8_t idx = 0;
float meas_temp = start_temp + res_temp;
while (meas_temp < temp) {
if (++idx >= measurements) return static_cast<float>(val2) / 1000.0f;
meas_temp += res_temp;
val1 = val2;
val2 = data[idx];
}
const float factor = (meas_temp - temp) / static_cast<float>(res_temp);
return (static_cast<float>(val2) - static_cast<float>(val2 - val1) * factor) / 1000.0f;
uint8_t idx = static_cast<uint8_t>(temp - start_temp / res_temp);

// offset in um
float offset = 0.0f;

#if !defined(PTC_LINEAR_EXTRAPOLATION) || PTC_LINEAR_EXTRAPOLATION <= 0
if (idx < 0)
offset = 0.0f;
else if (idx > measurements - 2)
offset = static_cast<float>(data[measurements - 1]);
#else
if (idx < 0)
offset = linear_interp(temp, point(0), point(PTC_LINEAR_EXTRAPOLATION));
else if (idx > measurements - 2)
offset = linear_interp(temp, point(measurements - PTC_LINEAR_EXTRAPOLATION - 1), point(measurements - 1));
#endif
else
offset = linear_interp(temp, point(idx), point(idx + 1));

// return offset in mm
return offset / 1000.0f;
}

bool ProbeTempComp::linear_regression(const TempSensorID tsi, float &k, float &d) {
Expand Down
41 changes: 38 additions & 3 deletions Marlin/src/feature/probe_temp_comp.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,44 @@ typedef struct {
* measurement errors/shifts due to changed temperature.
*/

// Probe temperature calibration constants
#ifndef PTC_SAMPLE_COUNT
#define PTC_SAMPLE_COUNT 10U
#endif
#ifndef PTC_SAMPLE_RES
#define PTC_SAMPLE_RES 5.0f
#endif
#ifndef PTC_SAMPLE_START
#define PTC_SAMPLE_START 30.0f
#endif
#define PTC_SAMPLE_END ((PTC_SAMPLE_START) + (PTC_SAMPLE_COUNT) * (PTC_SAMPLE_RES))

// Bed temperature calibration constants
#ifndef BTC_PROBE_TEMP
#define BTC_PROBE_TEMP 30.0f
#endif
#ifndef BTC_SAMPLE_COUNT
#define BTC_SAMPLE_COUNT 10U
#endif
#ifndef BTC_SAMPLE_STEP
#define BTC_SAMPLE_RES 5.0f
#endif
#ifndef BTC_SAMPLE_START
#define BTC_SAMPLE_START 60.0f
#endif
#define BTC_SAMPLE_END ((BTC_SAMPLE_START) + (BTC_SAMPLE_COUNT) * (BTC_SAMPLE_RES))

#ifndef PTC_PROBE_HEATING_OFFSET
#define PTC_PROBE_HEATING_OFFSET 0.5f
#endif

#ifndef PTC_PROBE_RAISE
#define PTC_PROBE_RAISE 10.0f
#endif

static constexpr temp_calib_t cali_info_init[TSI_COUNT] = {
{ 10, 5, 30, 30 + 10 * 5 }, // Probe
{ 10, 5, 60, 60 + 10 * 5 }, // Bed
{ PTC_SAMPLE_COUNT, PTC_SAMPLE_RES, PTC_SAMPLE_START, PTC_SAMPLE_END }, // Probe
{ BTC_SAMPLE_COUNT, BTC_SAMPLE_RES, BTC_SAMPLE_START, BTC_SAMPLE_END }, // Bed
#if ENABLED(USE_TEMP_EXT_COMPENSATION)
{ 20, 5, 180, 180 + 5 * 20 } // Extruder
#endif
Expand All @@ -66,7 +101,7 @@ class ProbeTempComp {
//measure_point = { 12.0f, 7.3f }; // Coordinates for the MK52 magnetic heatbed

static constexpr int probe_calib_bed_temp = BED_MAX_TARGET, // Bed temperature while calibrating probe
bed_calib_probe_temp = 30; // Probe temperature while calibrating bed
bed_calib_probe_temp = BTC_PROBE_TEMP; // Probe temperature while calibrating bed

static int16_t *sensor_z_offsets[TSI_COUNT],
z_offsets_probe[cali_info_init[TSI_PROBE].measurements], // (µm)
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/calibrate/G76_M871.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void GcodeSuite::G76() {

auto g76_probe = [](const TempSensorID sid, uint16_t &targ, const xy_pos_t &nozpos) {
do_blocking_move_to_z(5.0); // Raise nozzle before probing
const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_NONE, 0, false); // verbose=0, probe_relative=false
const float measured_z = probe.probe_at_point(nozpos, PROBE_PT_STOW, 0, false); // verbose=0, probe_relative=false
if (isnan(measured_z))
SERIAL_ECHOLNPGM("!Received NAN. Aborting.");
else {
Expand All @@ -132,8 +132,8 @@ void GcodeSuite::G76() {
planner.synchronize();

const xyz_pos_t parkpos = temp_comp.park_point,
probe_pos_xyz = temp_comp.measure_point + xyz_pos_t({ 0.0f, 0.0f, 0.5f }),
noz_pos_xyz = probe_pos_xyz - probe.offset_xy; // Nozzle position based on probe position
probe_pos_xyz = xyz_pos_t(temp_comp.measure_point) + xyz_pos_t({ 0.0f, 0.0f, PTC_PROBE_HEATING_OFFSET }),
noz_pos_xyz = probe_pos_xyz - xy_pos_t(probe.offset_xy); // Nozzle position based on probe position

if (do_bed_cal || do_probe_cal) {
// Ensure park position is reachable
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* version was tagged.
*/
#ifndef STRING_DISTRIBUTION_DATE
#define STRING_DISTRIBUTION_DATE "2020-06-10"
#define STRING_DISTRIBUTION_DATE "2020-06-11"
#endif

/**
Expand Down
20 changes: 11 additions & 9 deletions Marlin/src/lcd/lcdprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,25 @@
* lcd_put_u8str_ind_P
* Print a string with an index substituted within it
*/
lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const uint8_t ind, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, const lcd_uint_t maxlen/*=LCD_WIDTH*/) {
uint8_t *p = (uint8_t*)pstr;
lcd_uint_t n = maxlen;
for (; n; n--) {
wchar_t ch;
p = get_utf8_value_cb(p, read_byte_rom, &ch);
if (!ch) break;
if (ch == '=' || ch == '~' || ch == '*') {
if (ch == '*') { lcd_put_wchar('E'); n--; }
// lcd_put_int(ind); n--; if (ind >= 10) n--;
// if (ind >= 0)
{
lcd_put_wchar(ind + ((ch == '=') ? '0' : LCD_FIRST_TOOL));
n--;
}
// else if (ind == -1) { PGM_P const b = GET_TEXT(MSG_BED); lcd_put_u8str_P(b); n -= utf8_strlen_P(b); }
// else if (ind == -2) { PGM_P const c = GET_TEXT(MSG_CHAMBER); lcd_put_u8str_P(c); n -= utf8_strlen_P(c); }
if (ind >= 0) {
if (ch == '*') { lcd_put_wchar('E'); n--; }
lcd_put_wchar(ind + ((ch == '=') ? '0' : LCD_FIRST_TOOL));
n--;
}
else {
PGM_P const b = ind == -2 ? GET_TEXT(MSG_CHAMBER) : GET_TEXT(MSG_BED);
lcd_put_u8str_P(b);
n -= utf8_strlen_P(b);
}
if (n) n -= lcd_put_u8str_max_P((PGM_P)p, n);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/lcdprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ inline int lcd_put_u8str_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P con
return lcd_put_u8str_P(pstr);
}

lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const uint8_t ind, const lcd_uint_t maxlen=LCD_WIDTH);
inline lcd_uint_t lcd_put_u8str_ind_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const pstr, const uint8_t ind, const lcd_uint_t maxlen=LCD_WIDTH) {
lcd_uint_t lcd_put_u8str_ind_P(PGM_P const pstr, const int8_t ind, const lcd_uint_t maxlen=LCD_WIDTH);
inline lcd_uint_t lcd_put_u8str_ind_P(const lcd_uint_t col, const lcd_uint_t row, PGM_P const pstr, const int8_t ind, const lcd_uint_t maxlen=LCD_WIDTH) {
lcd_moveto(col, row);
return lcd_put_u8str_ind_P(pstr, ind, maxlen);
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct {
menuPosition screen_history[6];
uint8_t screen_history_depth = 0;

uint8_t MenuItemBase::itemIndex; // Index number for draw and action
int8_t MenuItemBase::itemIndex; // Index number for draw and action
chimera_t editable; // Value Editing

// Menu Edit Items
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class MenuItemBase {
public:
// An index to interject in the item label and for
// use by the action
static uint8_t itemIndex;
static int8_t itemIndex;

// Store the index of the item ahead of use by indexed items
FORCE_INLINE static void init(const uint8_t ind) { itemIndex = ind; }
FORCE_INLINE static void init(const int8_t ind) { itemIndex = ind; }

// Draw an item either selected (pre_char) or not (space) with post_char
static void _draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char);
Expand Down
20 changes: 17 additions & 3 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ void menu_cancelobject();

#if ENABLED(PID_EDIT_MENU)
#define __PID_BASE_MENU_ITEMS(N) \
raw_Ki = unscalePID_i(PID_PARAM(Ki, N)); \
raw_Kd = unscalePID_d(PID_PARAM(Kd, N)); \
EDIT_ITEM_N(float52sign, N, MSG_PID_P_E, &PID_PARAM(Kp, N), 1, 9990); \
raw_Ki = unscalePID_i(TERN(PID_BED_MENU_SECTION, thermalManager.temp_bed.pid.Ki, PID_PARAM(Ki, N))); \
raw_Kd = unscalePID_d(TERN(PID_BED_MENU_SECTION, thermalManager.temp_bed.pid.Kd, PID_PARAM(Kd, N))); \
EDIT_ITEM_N(float52sign, N, MSG_PID_P_E, &TERN(PID_BED_MENU_SECTION, thermalManager.temp_bed.pid.Kp, PID_PARAM(Kp, N)), 1, 9990); \
EDIT_ITEM_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \
EDIT_ITEM_N(float52sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); })

Expand Down Expand Up @@ -312,6 +312,20 @@ void menu_cancelobject();
REPEAT_S(1, HOTENDS, PID_EDIT_MENU_ITEMS)
#endif

#if ENABLED(PIDTEMPBED)
#if ENABLED(PID_EDIT_MENU)
#define PID_BED_MENU_SECTION
__PID_BASE_MENU_ITEMS(-1);
#undef PID_BED_MENU_SECTION
#endif
#if ENABLED(PID_AUTOTUNE_MENU)
#ifndef BED_OVERSHOOT
#define BED_OVERSHOOT 5
#endif
EDIT_ITEM_FAST_N(int3, -1, MSG_PID_AUTOTUNE_E, &autotune_temp_bed, 70, BED_MAXTEMP - BED_OVERSHOOT, []{ _lcd_autotune(-1); });
#endif
#endif

END_MENU();
}

Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/pins/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@
#include "stm32f1/pins_MKS_ROBIN_E3.h" // STM32F1 env:mks_robin_e3
#elif MB(CCROBOT_MEEB_3DP)
#include "stm32f1/pins_CCROBOT_MEEB_3DP.h" // STM32F1 env:STM32F103RC_meeb
#elif MB(CHITU3D_V5)
#include "stm32f1/pins_CHITU3D_V5.h" // STM32F1 env:chitu_f103
#elif MB(CHITU3D_V6)
#include "stm32f1/pins_CHITU3D_V6.h" // STM32F1 env:chitu_f103

//
// ARM Cortex-M4F
Expand Down
13 changes: 13 additions & 0 deletions Marlin/src/pins/sanguino/pins_MELZI_CREALITY.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* electronic components to write the bootloader.
*
* See http://www.instructables.com/id/Burn-Arduino-Bootloader-with-Arduino-MEGA/
*
* Schematic: https://bit.ly/2XOnsWb
*/

#define BOARD_INFO_NAME "Melzi (Creality)"
Expand Down Expand Up @@ -116,3 +118,14 @@
PIN: 30 Port: A1 LCD_PINS_D4 Output = 1
PIN: 31 Port: A0 SDSS Output = 1
*/

/**
* EXP1 Connector EXP1 as CR10 STOCKDISPLAY
* _____ _____
* PA4 | 6 5 | PC0 BEEPER_PIN | 6 5 | BTN_ENC
* PD3 | 7 4 | RESET BTN_EN1 | 7 4 | RESET
* PD2 8 3 | PA1 BTN_EN2 8 3 | LCD_PINS_D4 (ST9720 CLK)
* PA3 | 9 2 | PC1 (ST9720 CS) LCD_PINS_RS | 9 2 | LCD_PINS_ENABLE (ST9720 DAT)
* GND |10 1 | 5V GND |10 1 | 5V
* ----- -----
*/
Loading

0 comments on commit 4aa031b

Please sign in to comment.