bdring / FluidNC

The next generation of motion control firmware
Other
1.47k stars 362 forks source link

Problem: Servo travel intermittently slow #688

Closed MarkJB closed 1 year ago

MarkJB commented 1 year ago

Controller Board

ESP32_Plotter_Controller (Emerald Dingo RevB)

Machine Description

Wallbot

Input Circuits

No response

Configuration file

name: ESP32_Plotter_Controller_RevB_Emerald_Dingo
board: Emerald Dingo (RevB)

kinematics:
  WallPlotter:
    left_axis: 0
    left_anchor_x: -326.500
    left_anchor_y: 120.000
    right_axis: 1
    right_anchor_x: 326.000
    right_anchor_y: 120.000
    segment_length: 10.000

stepping:
  engine: RMT
  idle_ms: 255
  dir_delay_us: 0
  pulse_us: 3
  disable_delay_us: 0

axes:
  shared_stepper_disable_pin: gpio.2
  x:
    # Pully = 100mm circumference
    # Steppers are 1.8deg or 200 divs per rev * 16 micro steps = 3200 steps per rev / 100m = 32 steps per mm
    steps_per_mm: 32.000
    max_rate_mm_per_min: 5000.000
    acceleration_mm_per_sec2: 200.000
    max_travel_mm: 300.000
    soft_limits: false
    homing:
      cycle: 2
      mpos_mm: 0.000
      positive_direction: true
      settle_ms: 250.000
      seek_mm_per_min: 2000.000
      feed_mm_per_min: 200.000
      seek_scaler: 1.100
      feed_scaler: 5.000
    motor0:
      limit_all_pin: NO_PIN
      hard_limits: false
      tmc_2130:
        toff_disable: 1
        direction_pin: gpio.26
        step_pin: gpio.25
        run_amps: 0.350
        hold_amps: 0.25
        microsteps: 16
        stallguard: 16
        stallguard_debug: false
        run_mode: StealthChop
        homing_mode: StealthChop
        use_enable: false
        r_sense_ohms: 0.110
        cs_pin: gpio.17
    motor1:
      null_motor:
  y:
    steps_per_mm: 32.000
    max_rate_mm_per_min: 5000.000
    acceleration_mm_per_sec2: 200.000
    max_travel_mm: 300.000
    soft_limits: false
    homing:
      cycle: 2
      mpos_mm: 0.000
      positive_direction: false
      settle_ms: 250.000
      seek_mm_per_min: 2000.000
      feed_mm_per_min: 200.000
      seek_scaler: 1.100
      feed_scaler: 5.000
    motor0:
      limit_all_pin: NO_PIN
      hard_limits: false
      tmc_2130:
        toff_disable: 1
        direction_pin: gpio.33
        step_pin: gpio.32
        run_amps: 0.350
        hold_amps: 0.25
        microsteps: 16
        stallguard: 16
        stallguard_debug: false
        run_mode: StealthChop
        homing_mode: StealthChop
        use_enable: false
        r_sense_ohms: 0.110
        cs_pin: gpio.16
    motor1:
      null_motor:
  z:
    steps_per_mm: 100
    max_rate_mm_per_min: 5000
    acceleration_mm_per_sec2: 100
    max_travel_mm: 5
    homing:
      cycle: 1
      mpos_mm: 0
      positive_direction: true

    motor0:
      rc_servo:
        pwm_hz: 50
        output_pin: gpio.27
        min_pulse_us: 900
        max_pulse_us: 1465

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

sdcard:
  cs_pin: gpio.5

control:
  reset_pin: gpio.0:low:pu

coolant:
  delay_ms: 1000.000

probe:
  check_mode_start: false

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

start:
  must_home: true
  check_limits: true
  deactivate_parking: false

user_outputs:

arc_tolerance_mm: 0.002
junction_deviation_mm: 0.010
verbose_errors: false
report_inches: false
enable_parking_override_control: false
use_line_numbers: false

Startup Messages

[MSG:INFO: FluidNC v3.6.4]
[MSG:INFO: Compiled with ESP32 SDK:v4.4.1-1-gb8050b365e]
[MSG:INFO: Local filesystem type is spiffs]
[MSG:INFO: Configuration file:config.yaml]
[MSG:INFO: Machine ESP32_Plotter_Controller_RevB_Emerald_Dingo]
[MSG:INFO: Board Emerald Dingo (RevB)]
[MSG:INFO: SPI SCK:gpio.18 MOSI:gpio.23 MISO:gpio.19]
[MSG:INFO: SD Card cs_pin:gpio.5 detect:NO_PIN]
[MSG:INFO: Stepping:RMT Pulse:3us Dsbl Delay:0us Dir Delay:0us Idle Delay:255ms]
[MSG:INFO: Axis count 3]
[MSG:INFO: Shared stepper disable gpio.2]
[MSG:INFO: Axis X (-300.000,0.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     tmc_2130 Step:gpio.25 Dir:gpio.26 CS:gpio.17 Disable:NO_PIN Index:-1 R:0.110]
[MSG:INFO:   Motor1]
[MSG:INFO: Axis Y (0.000,300.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     tmc_2130 Step:gpio.32 Dir:gpio.33 CS:gpio.16 Disable:NO_PIN Index:-1 R:0.110]
[MSG:INFO:   Motor1]
[MSG:INFO: Axis Z (-5.000,0.000)]
[MSG:INFO:   Motor0]
[MSG:INFO:     rc_servo Pin:gpio.27 Pulse Len(900,1465 period:1048575)]
[MSG:INFO: X Axis driver test passed]
[MSG:INFO: Y Axis driver test passed]
[MSG:INFO: reset_pin gpio.0:low:pu]
[MSG:INFO: Kinematic system: WallPlotter]
[MSG:INFO: Using spindle NoSpindle]
[MSG:INFO: Connecting to STA SSID:*****]
[MSG:INFO: Connecting.]
[MSG:INFO: Connected - IP is 192.168.0.115]
[MSG:INFO: WiFi on]
[MSG:INFO: Start mDNS with hostname:http://fluidnc.local/]
[MSG:INFO: SSDP Started]
[MSG:INFO: HTTP started on port 80]
[MSG:INFO: Telnet started on port 23]

User Interface Software

Processing sketch

What happened?

I'm attempting to live plot visualizations of the data from a MindFlex headset over the serial port.

The problem I am seeing is that the servo (pen down) randomly becomes painfully slow (taking ~15 seconds to drop the pen). You can see its pretty random from the blotches in the photo and a video if you want to see it happening.

image

I appreciate this may not be a fluidnc problem, but the gcode send script, while basic, is something I've used on and off over the years and not seen this problem with grbl or grblesp.

For some more context:

The processing sketch gets the data from the headset, converts that to a set of coordinates the represent a shape and plots the shape on screen and also sends the coordinates as gcode over the serial port, one line at a time (it waits to receive the 'ok' string so I guess its filling the buffer and blocking until it can send a new gcode command). Originally, I was checking the serial port every 50ms for new characters, but slowed it to 1sec, thinking that maybe I was sending data too fast, but I'm still seeing the problem.

My intial thought was filling the buffer might be causing it, but I just ran it again and on the first move, the servo was slow. At that point I had only sent 3 gcode commands. You can see the servo moving slowly (as part of debugging I added a status command output).

The first move, is G0 X9.000 Y13.000 Z-5 F1500.000 followed by the first draw G1 X9.000 Y13.000 Z5 F1500.000 which is where the servo starts to move really slowly. While debugging I've slowed down the poll for the 'ok' received from fluidnc to 1000ms and each subsequent gcode command sent will also get the status. From the status outputs you can see the servo moving really slowly (and x and y not changing as expected). I guess its taking around ~12seconds when normally it takes less than a second. But there is also a few seconds after the servo stops moving before it starts the next move.


rawEvent() method not defined. 
Sending init command: G10 L2 P2 X-140 Y-550
Waiting for grbl
<Idle|MPos:0.000,-0.000,0.000|FS:0,0>

G10 L2 P2 X-140 Y-550
Waiting for grbl
Init command received ok
Waiting for grbl
<Idle|MPos:0.000,-0.000,0.000|FS:0,0>

G55 Z-5
Waiting for grbl
Command received: ok

Waiting for grbl
<Idle|MPos:0.000,-0.000,-5.000|FS:0,0|WCO:-140.000,-550.000,0.000>

G55 X0 Y0 F1500
Waiting for grbl
Command received: ok

col count:15 col spacing:19
row count:25 row spacing:16
Check every 10 secs
We have 0 mindflex data points
Check every 10 secs
We have 1 mindflex data points
Waiting for grbl
<Idle|MPos:-140.008,-550.009,-5.000|FS:0,0>

G0 X9.000 Y13.000 Z-5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.191,-537.261,-5.000|FS:0,0|WCO:-140.000,-550.000,0.000>

G1 X9.000 Y13.000 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-4.810|FS:1,0>

G1 X16.939 Y17.045 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-4.430|FS:1,0>

G1 X18.755 Y14.545 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-4.040|FS:1,0|Ov:100,100,100>

G1 X13.755 Y6.455 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-3.650|FS:1,0>

G1 X16.939 Y8.955 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-3.270|FS:1,0>

G1 X14.000 Y8.000 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-2.890|FS:1,0>

G1 X6.061 Y3.955 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-2.490|FS:1,0|WCO:-140.000,-550.000,0.000>

G1 X9.245 Y11.455 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-2.110|FS:1,0>

G1 X9.245 Y14.545 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-1.720|FS:1,0>

G1 X7.061 Y13.045 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-1.340|FS:1,0|Ov:100,100,100>

G1 X9.000 Y13.000 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-0.960|FS:1,0>

G0 X9.000 Y13.000 Z-5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-0.570|FS:1,0>

G0 X28.000 Y13.000 Z-5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,-0.190|FS:1,0>

G1 X31.000 Y16.000 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,0.200|FS:1,0>

G1 X35.939 Y17.045 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,0.590|FS:1,0|WCO:-140.000,-550.000,0.000>

G1 X32.755 Y9.545 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-130.725,-536.862,5.000|FS:1346,0>

G1 X37.755 Y11.455 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-125.865,-542.939,5.000|FS:545,0>

G1 X30.939 Y3.955 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-133.701,-545.521,5.000|FS:1872,0>

G1 X32.000 Y7.000 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-131.004,-537.010,3.340|FS:1731,0>

G1 X30.061 Y8.955 Z5 F1500.000
Waiting for grbl
Command received: ok

Waiting for grbl
<Run|MPos:-111.643,-536.660,-3.880|FS:1618,0|WCO:-140.000,-550.000,0.000>

G1 X23.245 Y6.455 Z5 F1500.000
Waiting for grbl```

### Other Information

_No response_
MarkJB commented 1 year ago

Doesn't seem to be related to acceleration settings or work offsets...

MarkJB commented 1 year ago

Seems the serial port is a red herring.

I wrote the gcode to a file (attached), uploaded it and ran it from the webui and am seeing the same issue. mind-glyphs.txt

Note: If the z moves look different between this file and the original console output, its because I added /axes/z/homing/mpos_mm 5 and now I have Z5 = pen up and Z0 = pen down.

bdring commented 1 year ago

I can replicate the problem. It looks like a feed rate compensation problem.

bdring commented 1 year ago

It was the feed rate compensation. There is a new branch you can compile and test. We would love some feedback on the fix.

https://github.com/bdring/FluidNC/tree/WallPlotterMultiAxis

MarkJB commented 1 year ago

So far so good.

I have a few longer running plots to try and I'll report back.

MarkJB commented 1 year ago

Not seen the servo move slowly in a couple of hours, but the next move is happening before the servo finishes its travel. Is there a setting to control the settle time? (Was looking for something like /axes/z/homing/settle_ms but for moves rather than homing).

MarkJB commented 1 year ago

Something odd happened while I was attempting to speed up the servo. After cranking up the z_axis feedrate and acceleration, I was manually sending G0 Z0 & G0 Z5 to test and the machine went off in a random direction and nan shows in the console.

I'm not able to reproduce it yet, but if I can, I'll open another issue.


<Idle|MPos:-93.937,-544.058,0.000|FS:0,0>
G0 Z5
ok
G0 Z0
ok
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0>
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0>
G0 Z5
ok
<Idle|MPos:-93.937,-544.058,5.000|FS:0,0>
G0 Z0
ok
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0>
G0 Z5
ok
<Idle|MPos:-93.937,-544.058,5.000|FS:0,0|WCO:0.000,-0.000,0.001>
G0 Z5
ok
<Run|MPos:19.352,-449.975,5.000|FS:5175,0|Ov:100,100,100>
<Run|MPos:155.031,-237.756,5.000|FS:5175,0>
G0 Z0
ok
<Run|MPos:201.193,43.803,5.000|FS:5175,0>
<Run|MPos:158.648,nan,5.000|FS:5175,0>
<Run|MPos:167.553,nan,4.380|FS:5175,0>
<Run|MPos:200.435,-1.909,3.110|FS:5175,0>
<Run|MPos:144.513,-263.240,1.840|FS:5175,0>
<Run|MPos:-0.411,-469.699,0.570|FS:5175,0>
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0>
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0|WCO:0.000,-0.000,0.001>
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0|Ov:100,100,100>
G0 Z0
<Idle|MPos:-93.937,-544.058,0.000|FS:0,0>
ok
<Run|MPos:65.364,-396.611,0.000|FS:5175,0>
<Run|MPos:176.207,-173.108,0.000|FS:5175,0>
<Run|MPos:198.476,nan,0.000|FS:5175,0>
<Run|MPos:131.678,nan,0.000|FS:5155,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0|WCO:0.000,-0.000,0.001>
<Idle|MPos:119.671,nan,0.000|FS:0,0|Ov:100,100,100>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0|WCO:0.000,-0.000,0.001>
<Idle|MPos:119.671,nan,0.000|FS:0,0|Ov:100,100,100>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
<Idle|MPos:119.671,nan,0.000|FS:0,0>
MarkJB commented 1 year ago

Off the back of tweaking the feeds and speeds for the z-axis, I've noticed the servo is slower going from Z5 -> Z0, than it is the other way.

This was after setting the acceleration to 1000mm/s/s.

bdring commented 1 year ago

The nan means something is wrong. The wallbot kinematics was contributed by someone not on the development team. We are trying to patch it up without a machine to test with. It could be moving into a bad area. The 119 is close to the Y position of the anchor. We can add code to warn you if you are getting out of the valid area of motion.

kinematics:
  WallPlotter:
    left_axis: 0
    left_anchor_x: -326.500
    left_anchor_y: 120.000
    right_axis: 1
    right_anchor_x: 326.000
    right_anchor_y: 120.000
    segment_length: 10.000

I noticed your servo range is this.

[MSG:INFO: Axis Z (-5.000,0.000)]

Do you have a G54 offset?

MarkJB commented 1 year ago

Yes, I am using this offset G10 L2 P2 X-140 Y-550 Z5

MarkJB commented 1 year ago

The servo range should be 0.000,5.000.

The -5.000,0.000 might have been from before I added mpos_mm: 5 to the config.

bdring commented 1 year ago

I noticed you don't have limit switches.

Can you sent a link to the hardware you are using, exactly how you start a job and why you set that offset?

The range is in machine space. If you want 0 to 5mm, you need to set the homing mpos_mm to 5, because you home positive on Z

MarkJB commented 1 year ago

The controller board is one of my own design, but pin compatible with one of yours.

The rest of the machine is a self build.

The offset is to make working with the machines coordinate system easier. The semi-circle at the top is 'home' and the processing sketch starts at the 0,0 bottom left of the page, hence the offset.

IMG_20221031_214949658

MarkJB commented 1 year ago

Sorry - forgot to say I start a job by homing (if the gondola isn't at the home position when the machine thinks it is the plot will be skewed) then applying the offset, either manually or as part of the gcode (the processing sketch will send the offset and activate it), then it starts streaming the gcode.

But for the recent tests, I've been starting the gcode files from the webui with the play button.

bdring commented 1 year ago

(edited) I am not sure, but I assume you manually move the gondola to the center of X and 120 below the "anchors" and then start the controller.

MarkJB commented 1 year ago

(edited) I am not sure, but I assume you manually move the gondola to the center of X and 120 below the "anchors" and then start the controller.

Yes, that's correct.

MitchBradley commented 1 year ago

I pushed a change to that branch that probably fixes the problem. The trigger for the problem was a move that went nowhere, in this case G0 Z5 right after G0 Z5.

MarkJB commented 1 year ago

So far so good. Been plotting on and off for 24hrs and not seen nan or crazy moves.

When this plot is finished I'll try and force some crazy moves and see what happens.

R.e. the issue with the next move starting before the servo reaches its expected position, is this expected? Is there a setting to delay until the servo has likely finished moving? Or should I raise a separate issue for it?

bdring commented 1 year ago

The servo is not closed loop (with FluidNC) . It is just doing its best to track the position. If you set the speed and acceleration higher than the servo can go, the next move will start before the servo completes it motion.

Try lowering the max_rate_mm_per_min for the Z axis.

Most servos can do a full move in a little less than a second. For a 5mm Z move, I would try a rate in the 200-400 range. You can tune that value live by sending...

$axes/z/max_rate_mm_per_min=300

Once you like the performance you need to save your config file with that value so it reads it a start up.