bdring / FluidNC

The next generation of motion control firmware
Other
1.59k stars 383 forks source link

Bad position report in OLED display #891

Closed Avataar120 closed 1 year ago

Avataar120 commented 1 year ago

Controller Board

Own design

image

Machine Description

K40 with Z bed

Input Circuits

Trigger Schmitt for X&Y + RC debouncing for all inputs

Configuration file

$cd
board: 4_Ava_Shield_8.1_XYZA_OLED
name: K40_AvaShield
meta:
stepping:
  engine: I2S_static
  idle_ms: 255
  pulse_us: 4
  dir_delay_us: 1
  disable_delay_us: 0
  segments: 12

i2so:
  bck_pin: gpio.22
  data_pin: gpio.21
  ws_pin: gpio.17

i2c0:
  sda_pin: gpio.25
  scl_pin: gpio.33
  frequency: 100000

spi:
  miso_pin: gpio.19
  mosi_pin: gpio.23
  sck_pin: gpio.18

sdcard:
  cs_pin: gpio.5
  card_detect_pin: NO_PIN
  frequency_hz: 8000000

kinematics:
  Cartesian:

axes:
  shared_stepper_disable_pin: NO_PIN
  shared_stepper_reset_pin: NO_PIN
  x:
    steps_per_mm: 78.739998
    max_rate_mm_per_min: 20000.000000
    acceleration_mm_per_sec2: 2000.000000
    max_travel_mm: 310.000000
    soft_limits: true
    homing:
      cycle: 1
      allow_single_axis: true
      positive_direction: false
      mpos_mm: 0.000000
      feed_mm_per_min: 200.000000
      seek_mm_per_min: 2500.000000
      settle_ms: 250
      seek_scaler: 1.500000
      feed_scaler: 5.000000

    motor0:
      limit_neg_pin: gpio.39:low
      limit_pos_pin: NO_PIN
      limit_all_pin: NO_PIN
      hard_limits: true
      pulloff_mm: 5.000000
      stepstick:
        step_pin: I2SO.2
        direction_pin: I2SO.1
        disable_pin: I2SO.0
        ms1_pin: NO_PIN
        ms2_pin: NO_PIN
        ms3_pin: I2SO.3
        reset_pin: NO_PIN

  y:
    steps_per_mm: 78.739998
    max_rate_mm_per_min: 20000.000000
    acceleration_mm_per_sec2: 2000.000000
    max_travel_mm: 210.000000
    soft_limits: true
    homing:
      cycle: 1
      allow_single_axis: true
      positive_direction: false
      mpos_mm: 0.000000
      feed_mm_per_min: 200.000000
      seek_mm_per_min: 2500.000000
      settle_ms: 250
      seek_scaler: 1.500000
      feed_scaler: 5.000000

    motor0:
      limit_neg_pin: gpio.34:low
      limit_pos_pin: NO_PIN
      limit_all_pin: NO_PIN
      hard_limits: true
      pulloff_mm: 5.000000
      stepstick:
        step_pin: I2SO.6
        direction_pin: I2SO.5:low
        disable_pin: I2SO.4
        ms1_pin: NO_PIN
        ms2_pin: NO_PIN
        ms3_pin: I2SO.7
        reset_pin: NO_PIN

  z:
    steps_per_mm: 1000.000000
    max_rate_mm_per_min: 200.000000
    acceleration_mm_per_sec2: 1000.000000
    max_travel_mm: 20.000000
    soft_limits: false
    homing:
      cycle: 2
      allow_single_axis: true
      positive_direction: true
      mpos_mm: 9.500000
      feed_mm_per_min: 100.000000
      seek_mm_per_min: 100.000000
      settle_ms: 250
      seek_scaler: 1.500000
      feed_scaler: 5.000000

    motor0:
      limit_neg_pin: gpio.35:low
      limit_pos_pin: NO_PIN
      limit_all_pin: NO_PIN
      hard_limits: true
      pulloff_mm: 9.500000
      stepstick:
        step_pin: I2SO.10
        direction_pin: I2SO.9:low
        disable_pin: I2SO.8
        ms1_pin: NO_PIN
        ms2_pin: NO_PIN
        ms3_pin: I2SO.11
        reset_pin: NO_PIN

  a:
    steps_per_mm: 2.778000
    max_rate_mm_per_min: 53200.000000
    acceleration_mm_per_sec2: 100000.000000
    max_travel_mm: 360.000000
    soft_limits: false
    homing:
      cycle: 0
      allow_single_axis: true
      positive_direction: true
      mpos_mm: 0.000000
      feed_mm_per_min: 100.000000
      seek_mm_per_min: 100.000000
      settle_ms: 250
      seek_scaler: 1.500000
      feed_scaler: 5.000000

    motor0:
      limit_neg_pin: gpio.32:low:pu
      limit_pos_pin: NO_PIN
      limit_all_pin: NO_PIN
      hard_limits: false
      pulloff_mm: 0.100000
      stepstick:
        step_pin: I2SO.14
        direction_pin: I2SO.13
        disable_pin: I2SO.12
        ms1_pin: NO_PIN
        ms2_pin: NO_PIN
        ms3_pin: I2SO.15
        reset_pin: NO_PIN

control:
  safety_door_pin: gpio.27:low:pu
  reset_pin: gpio.12:low:pu
  feed_hold_pin: gpio.14:low:pu
  cycle_start_pin: gpio.13:low:pu
  macro0_pin: NO_PIN
  macro1_pin: NO_PIN
  macro2_pin: NO_PIN
  macro3_pin: NO_PIN

coolant:
  flood_pin: NO_PIN
  mist_pin: gpio.4
  delay_ms: 50

probe:
  pin: gpio.36:low
  check_mode_start: false

macros:
  startup_line0:
  startup_line1:
  macro0:
  macro1:
  macro2:
  macro3:

start:
  must_home: true
  deactivate_parking: false
  check_limits: true

parking:
  enable: false
  axis: Z
  target_mpos_mm: -5.000000
  rate_mm_per_min: 800.000000
  pullout_distance_mm: 5.000000
  pullout_rate_mm_per_min: 250.000000

user_outputs:
  analog0_pin: NO_PIN
  analog1_pin: NO_PIN
  analog2_pin: NO_PIN
  analog3_pin: NO_PIN
  analog0_hz: 5000
  analog1_hz: 5000
  analog2_hz: 5000
  analog3_hz: 5000
  digital0_pin: NO_PIN
  digital1_pin: NO_PIN
  digital2_pin: NO_PIN
  digital3_pin: NO_PIN

oled:
  i2c_num: 0
  i2c_address: 60
  width: 128
  height: 64
  radio_delay_ms: 1000

Laser:
  pwm_hz: 15000
  output_pin: gpio.15
  enable_pin: gpio.16:low
  disable_with_s0: false
  s0_with_disable: false
  tool_num: 0
  speed_map: 0=0.000000% 1000=100.000000%
  off_on_alarm: false

arc_tolerance_mm: 0.002000
junction_deviation_mm: 0.010000
verbose_errors: false
report_inches: false
enable_parking_override_control: false
use_line_numbers: false
planner_blocks: 16
ok

Startup Messages

$ss
[MSG:INFO: FluidNC v3.7.0]
[MSG:INFO: Compiled with ESP32 SDK:v4.4.4]
[MSG:INFO: Local filesystem type is littlefs]
[MSG:INFO: Configuration file:config.yaml]
[MSG:WARN: pulloff_mm value 0.000 constrained to range (0.100,100000.000)]
[MSG:INFO: Machine K40_AvaShield]
[MSG:INFO: Board 4_Ava_Shield_8.1_XYZA_OLED]
[MSG:INFO: I2SO BCK:gpio.22 WS:gpio.17 DATA:gpio.21]
[MSG:INFO: SPI SCK:gpio.18 MOSI:gpio.23 MISO:gpio.19]
[MSG:INFO: SD Card cs_pin:gpio.5 detect:NO_PIN freq:8000000]
[MSG:INFO: I2C SDA: gpio.25, SCL: gpio.33, Freq: 100000, Bus #: 0]
[MSG:INFO: OLED I2C address:0x3c width: 128 height: 64]
[MSG:INFO: Stepping:I2S_static Pulse:4us Dsbl Delay:0us Dir Delay:1us Idle Delay:255ms]
[MSG:INFO: Axis count 4]
[MSG:INFO: Axis X (0.000,310.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     stepstick Step:I2SO.2 Dir:I2SO.1 Disable:I2SO.0]
[MSG:INFO:  X Neg Limit gpio.39:low]
[MSG:INFO: Axis Y (0.000,210.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     stepstick Step:I2SO.6 Dir:I2SO.5:low Disable:I2SO.4]
[MSG:INFO:  Y Neg Limit gpio.34:low]
[MSG:INFO: Axis Z (-10.500,9.500)]
[MSG:INFO:   Motor0]
[MSG:INFO:     stepstick Step:I2SO.10 Dir:I2SO.9:low Disable:I2SO.8]
[MSG:INFO:  Z Neg Limit gpio.35:low]
[MSG:INFO: Axis A (-360.000,0.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     stepstick Step:I2SO.14 Dir:I2SO.13 Disable:I2SO.12]
[MSG:INFO:  A Neg Limit gpio.32:low:pu]
[MSG:INFO: safety_door_pin gpio.27:low:pu]
[MSG:INFO: reset_pin gpio.12:low:pu]
[MSG:INFO: feed_hold_pin gpio.14:low:pu]
[MSG:INFO: cycle_start_pin gpio.13:low:pu]
[MSG:INFO: Kinematic system: Cartesian]
[MSG:INFO: Laser Ena:gpio.16:low Out:gpio.15 Freq:15000Hz Period:4095]
[MSG:INFO: Using spindle Laser]
[MSG:INFO: Mist coolant gpio.4]
[MSG:INFO: Probe Pin: gpio.36:low]
[MSG:INFO: STA SSID is not set]
[MSG:INFO: AP SSID FluidNC IP 192.168.0.1 mask 255.255.255.0 channel 1]
[MSG:INFO: AP started]
[MSG:INFO: WiFi on]
[MSG:INFO: Captive Portal Started]
[MSG:INFO: HTTP started on port 80]
[MSG:INFO: Telnet started on port 23]

User Interface Software

Fluidterm or Lightburn

What happened?

After a HOME procedure, I move the head by entering G0 X3, G0 X6, G0 X9, ... Sometimes, position is correctly reported on the OLED display But most of the time, display is showing the good position then goes back to X = 0, Y= 0, Z = 0, A = 0 or only one axis is correct all the others are at 0 (see the little video attached) Note : when 0 0 0 0 is displayed, if I enter ? command, position is correctly reported

In addition, when a hard swicth is hit (see end of the video), system goes to Alarm then goes back to Idle (this time consistent with ? result) I was expecting to stay in Alarm until ESP32 reset

https://github.com/bdring/FluidNC/assets/12379002/9e8d3e35-7d71-4936-b076-ada38e31eaab

Other Information

No response

Avataar120 commented 1 year ago

Few more infos : If I make a G1 move, the display shows correctly the position of the head in MPos, sometimes not.

As soon as I send a M2 command, display goes back to 0, 0, Z (which are exactly the values in WCO) However ? command reports correctly the position of the machine in MPos

It seems that sometimes, display is showing WCO position ... But not due to OLED.cpp code ...

For M2 command, it's 100% reproductable due to gc_wco_changed(); in GCODE.cpp

This is an issue with Lightburn as it sends a M2 command after each jog / manual move

Avataar120 commented 1 year ago

Other evidence of MPos / WCO ... During a homing sequence (that I limit to XY with $H=XY for instance), MPOS Z=7.50, WCO Z=4.2 You can see on the video that very briefly, Z value is switching from 7.5 to 4.2 when limit switch is hit

image

https://github.com/bdring/FluidNC/assets/12379002/e4a4b887-3b54-458e-8b77-219c8b9e96b5

MitchBradley commented 1 year ago

I think I have found the bug.

Avataar120 commented 1 year ago

If you want me to try an hotfix, you can just give me the modif and I test it right away !

MitchBradley commented 1 year ago

Oops, there is a bug in the above

MitchBradley commented 1 year ago
diff --git a/FluidNC/src/OLED.cpp b/FluidNC/src/OLED.cpp
index ec7c9a50..aa2d377d 100644
--- a/FluidNC/src/OLED.cpp
+++ b/FluidNC/src/OLED.cpp
@@ -205,9 +205,7 @@ void OLED::parse_numbers(std::string s, float* nums, int maxnums) {
     } while (nextpos != std::string::npos);
 }

-float* OLED::parse_axes(std::string s) {
-    static float axes[MAX_N_AXIS];
-
+void OLED::parse_axes(std::string s, float* axes) {
     size_t pos     = 0;
     size_t nextpos = -1;
     size_t axis    = 0;
@@ -219,7 +217,6 @@ float* OLED::parse_axes(std::string s) {
         }
         pos = nextpos + 1;
     } while (nextpos != std::string::npos);
-    return axes;
 }

 void OLED::parse_status_report() {
@@ -234,9 +231,9 @@ void OLED::parse_status_report() {
     bool probe              = false;
     bool limits[MAX_N_AXIS] = { false };

-    float* axes;
-    bool   isMpos = false;
-    _filename     = "";
+    float axes[MAX_N_AXIS];
+    bool  isMpos = false;
+    _filename    = "";

     // ... handle it
     while (nextpos != std::string::npos) {
@@ -249,13 +246,13 @@ void OLED::parse_status_report() {
         auto value = field.substr(colon + 1);
         if (tag == "MPos") {
             // x,y,z,...
-            axes   = parse_axes(value);
+            parse_axes(value, axes);
             isMpos = true;
             continue;
         }
         if (tag == "WPos") {
             // x,y,z...
-            axes   = parse_axes(value);
+            parse_axes(value, axes);
             isMpos = false;
             continue;
         }
@@ -305,7 +302,10 @@ void OLED::parse_status_report() {
         }
         if (tag == "WCO") {
             // x,y,z,...
-            auto wcos = parse_axes(value);
+            // We do not use the WCO values because the DROs show whichever
+            // position is in the status report
+            // float wcos[MAX_N_AXIS];
+            // auto  wcos = parse_axes(value, wcos);
             continue;
         }
         if (tag == "Ov") {
diff --git a/FluidNC/src/OLED.h b/FluidNC/src/OLED.h
index c9937ba8..25e59969 100644
--- a/FluidNC/src/OLED.h
+++ b/FluidNC/src/OLED.h
@@ -53,8 +53,8 @@ private:
     void parse_AP();
     void parse_BT();

-    float* parse_axes(std::string s);
-    void   parse_numbers(std::string s, float* nums, int maxnums);
+    void parse_axes(std::string s, float* axes);
+    void parse_numbers(std::string s, float* nums, int maxnums);

     void show_limits(bool probe, const bool* limits);
     void show_state();
MitchBradley commented 1 year ago

I deleted the bad patch and added a good one.

Avataar120 commented 1 year ago

Working like a charm ! You are the best :)