Welcome! Log In Create A New Profile

Advanced

Step Motor Speed

Posted by Veysel 
Step Motor Speed
January 27, 2023 03:40AM
Hi, I am using MKS Robin Nano v3.0 card

I am controlling Step Motor (Nema 17 0.47 Nm)

Here is the simple python code that to move step motor and wait for its finish

device.serial.write("G91\n\r".encode())
while 1:
    data = device.serial.readline()
    if data == b"ok\n":
        break

s=time.perf_counter()
for i in range(25):

    device.serial.write(b"G1 Z0.001\r\n") # move up 1 micrometer (0.001 mm)
    device.serial.write(b"M400\r\n")      # wait for current move finish
    c = 0
    while 1:
        data = device.serial.readline()
        print(data)
        if data== b'ok\n':
            c += 1
        if c == 2:  # "ok" message will return after "G1 Z0.001" and "M400" command
            break
print(time.perf_counter()-s)


output: 2.56 seconds. Total time is 2.56 second for 25 step (25 micrometer)

Problem : I think step motor is very slow, I am not expert driving step motor, I change some parameter via software but total time is very long time, how can I reduce this time ?


Here the other scenario ( I only added time.sleep(0.1) before the next command ):

device.serial.write("G91\n\r".encode())
while 1:
    data = device.serial.readline()
    if data == b"ok\n":
        break

s=time.perf_counter()
for i in range(25):

    device.serial.write(b"G1 Z0.001\r\n")
    device.serial.write(b"M400\r\n")
    c = 0
    while 1:
        data = device.serial.readline()
        #print(data)
        if data== b'ok\n':
            c += 1
        if c == 2:
            break
        
    time.sleep(0.1)    
print(time.perf_counter()-s)

Now total time is 2.77 seconds but I expect 25*0.1 + 2.56 = 5,06 seconds

Where I am wrong ?

Step motor input voltage 24V

Thse are current settings:

>>> M503
SENDING:M503
echo:; Linear Units:
echo:  G21 ; (mm)
echo:; Temperature Units:
echo:  M149 C ; Units in Celsius
echo:; Steps per unit:
echo:  M92 X400.00 Y400.00 Z25600.00
echo:; Max feedrates (units/s):
echo:  M203 X15.00 Y15.00 Z1000.00
echo:; Max Acceleration (units/s2):
echo:  M201 X180.00 Y180.00 Z1000.00
echo:; Acceleration (units/s2) (P R T):
echo:  M204 P180.00 R180.00 T180.00
echo:; Advanced (B S T X Y Z):
echo:  M205 B20000.00 S0.00 T0.00 X10.00 Y10.00 Z1000.00
echo:; Home offset:
echo:  M206 X0.00 Y0.00 Z0.00
echo:; Stepper driver current:
echo:  M906 X800 Y800 Z800
echo:  M906 I1 X800 Y800
echo:; Hybrid Threshold:
echo:  M913 X104 Y104 Z123
echo:  M913 I2 X104 Y104
echo:; Driver stepping mode:
echo:  M569 S1 X Y Z
echo:  M569 S1 I1 X Y


Also config files attached.
Attachments:
open | download - Configuration.h (109 KB)
open | download - Configuration_adv.h (167 KB)
Re: Step Motor Speed
January 27, 2023 04:42AM
You don't specify a feedrate in your gcode anywhere

Try
device.serial.write(b"G1 Z0.001 F1000\n")

You also don't need Carriage Return, only the newline

Edited 1 time(s). Last edit at 01/27/2023 04:44AM by Dust.
Re: Step Motor Speed
January 27, 2023 05:23AM
Hi, Dust thank you.

Sorry I forget to specify feedrate but if I do
device.serial.write(b"G1 Z0.001 F1000\n")
or
device.serial.write(b"G1 Z0.001 F10\n")
total time is 2.56 (approximately) seconds,

Also this is M906 output:

>>> M906
SENDING:M906
X driver current: 800
X2 driver current: 800
Y driver current: 800
Y2 driver current: 800
Z driver current: 800

I changed Z driver current to 1200, but time is still same
Re: Step Motor Speed
January 27, 2023 11:22AM
Why do you think 2.56 seconds is too long?

I'm curious as to why you wrote the python scripts. I'm guessing that there is a bigger goal/issue and that this is just a step in that direction. If we know the bigger goal/issue then maybe we could offer an alternative solution.
Re: Step Motor Speed
January 27, 2023 12:14PM
I just sent those commands via a Repetier Host script and got an elapsed time of about 1.5 seconds.

Here's the log:


11:12:16.687 : N109 M114*47
11:12:16.687 : N110 G91*17
11:12:16.687 : N111 G1 Z0.01*76
11:12:16.687 : N112 M400*37
11:12:16.687 : N113 G1 Z0.01*78
11:12:16.687 : N114 M400*35
11:12:16.687 : N115 G1 Z0.01*72
11:12:16.687 : N116 M400*33
11:12:16.688 : X:0.00 Y:0.00 Z:45.00 E:0.00 Count X:0 Y:0 Z:18000
11:12:16.688 : ok
11:12:16.688 : ok
11:12:16.688 : ok
11:12:16.688 : N117 G1 Z0.01*74
11:12:16.688 : N118 M400*47
11:12:16.688 : ok
11:12:16.688 : ok
11:12:16.688 : N119 G1 Z0.01*68
11:12:16.688 : N120 M400*36
11:12:16.808 : ok
11:12:16.808 : ok
11:12:16.808 : ok
11:12:16.808 : ok
11:12:16.808 : N121 G1 Z0.01*79
11:12:16.808 : N122 M400*38
11:12:16.809 : N123 G1 Z0.01*77
11:12:16.809 : N124 M400*32
11:12:16.929 : ok
11:12:16.929 : ok
11:12:16.929 : ok
11:12:16.929 : ok
11:12:16.929 : N125 G1 Z0.01*75
11:12:16.929 : N126 M400*34
11:12:16.929 : N127 G1 Z0.01*73
11:12:16.929 : N128 M400*44
11:12:17.049 : ok
11:12:17.049 : ok
11:12:17.049 : ok
11:12:17.049 : N129 G1 Z0.01*71
11:12:17.049 : ok
11:12:17.049 : N130 M400*37
11:12:17.049 : N131 G1 Z0.01*78
11:12:17.049 : N132 M400*39
11:12:17.171 : ok
11:12:17.171 : ok
11:12:17.171 : ok
11:12:17.171 : ok
11:12:17.171 : N133 G1 Z0.01*76
11:12:17.171 : N134 M400*33
11:12:17.171 : N135 G1 Z0.01*74
11:12:17.171 : N136 M400*35
11:12:17.291 : ok
11:12:17.291 : ok
11:12:17.291 : ok
11:12:17.291 : N137 G1 Z0.01*72
11:12:17.291 : N138 M400*45
11:12:17.291 : ok
11:12:17.291 : N139 G1 Z0.01*70
11:12:17.291 : N140 M400*34
11:12:17.411 : ok
11:12:17.411 : ok
11:12:17.411 : ok
11:12:17.411 : ok
11:12:17.412 : N141 G1 Z0.01*73
11:12:17.412 : N142 M400*32
11:12:17.412 : N143 G1 Z0.01*75
11:12:17.412 : N144 M400*38
11:12:17.532 : ok
11:12:17.532 : ok
11:12:17.532 : ok
11:12:17.532 : ok
11:12:17.532 : N145 G1 Z0.01*77
11:12:17.532 : N146 M400*36
11:12:17.532 : N147 G1 Z0.01*79
11:12:17.532 : N148 M400*42
11:12:17.652 : ok
11:12:17.652 : ok
11:12:17.652 : ok
11:12:17.652 : ok
11:12:17.652 : N149 G1 Z0.01*65
11:12:17.652 : N150 M400*35
11:12:17.652 : N151 G1 Z0.01*72
11:12:17.652 : N152 M400*33
11:12:17.772 : ok
11:12:17.772 : ok
11:12:17.772 : ok
11:12:17.772 : N153 G1 Z0.01*74
11:12:17.772 : N154 M400*39
11:12:17.772 : N155 G1 Z0.01*76
11:12:17.772 : ok
11:12:17.772 : N156 M400*37
11:12:17.892 : ok
11:12:17.893 : ok
11:12:17.893 : ok
11:12:17.893 : N157 G1 Z0.01*78
11:12:17.893 : N158 M400*43
11:12:17.893 : ok
11:12:17.893 : N159 G1 Z0.01*64
11:12:17.893 : N160 M400*32
11:12:17.893 : N161 M114*33
11:12:18.018 : ok
11:12:18.018 : ok
11:12:18.018 : ok
11:12:18.018 : ok
11:12:18.138 : ok
11:12:18.138 : ok
11:12:18.138 : ok
11:12:18.138 : X:0.00 Y:0.00 Z:45.25 E:0.00 Count X:0 Y:0 Z:18096
11:12:18.138 : ok
Re: Step Motor Speed
January 28, 2023 12:58PM
Hi, thanks for interest

I am working on motorized microscopy, this device has autofocus and z-stack focus option. What one of I am doing is that taking 25(sometimes less or more) frame from different focal plane, and move motor after every frame grabbing.

My fps is 25 so 1 second for grabbing the 25 frame and 2.5 seconds is for motor move, total time 3.5 (approximately) seconds. I will do this process many time, that's why total time should not be much.

Also what should be best/ideal total time for 25 steps (every step will be 1 micrometer) ? I think 2.5 or 1.5 seconds is big time for this little step size am I wrong ?

I am using Python language in this project, that's why I am using Python

Edited 4 time(s). Last edit at 01/28/2023 01:11PM by veysel_olgun.
Re: Step Motor Speed
January 28, 2023 02:22PM
Strange - I just updated to the latest Repetier Host and now the execution times are about 0.25 seconds.

Maybe the 1.5 - 2.5 second executions times are script issues.

Just for fun I enabled the following in configuration_adv.h and ran a modified script. Execution time was 0.27 seconds.
  • PHOTO_GCODE
  • CHDK_PIN
  • PHOTO_SWITCH_MS 50

I did notice that the LED I selected didn't have a steady glow/pulse. Could be because Windows made the script execution jerky.

You probably want to add a delay to your script to let the carriage/head stop vibrating after the movement. Your final script might look something like:
G91
G1 Z0.001
M400      // wait for movement to finish
G4 P10    // let carriage settle
M240 D50  // 50 ms pulse high on camera trigger



13:08:12.478 : N97 M114*25
13:08:12.478 : N98 G91*32
13:08:12.478 : N99 G1 Z0.001*77
13:08:12.478 : N100 M400*38
13:08:12.478 : N101 M240*37
13:08:12.478 : N102 G1 Z0.001*126
13:08:12.478 : N103 M400*37
13:08:12.478 : N104 M240*32
13:08:12.490 : X:0.00 Y:0.00 Z:0.03 E:0.00 Count X:0 Y:0 Z:6
13:08:12.490 : ok
13:08:12.490 : N105 G1 Z0.001*121
13:08:12.497 : ok
13:08:12.497 : ok
13:08:12.497 : N106 M400*32
13:08:12.497 : N107 M240*35
13:08:12.497 : ok
13:08:12.497 : ok
13:08:12.497 : ok
13:08:12.497 : ok
13:08:12.497 : ok
13:08:12.497 : ok
13:08:12.499 : N108 G1 Z0.001*116
13:08:12.499 : N109 M400*47
13:08:12.499 : N110 M240*37
13:08:12.502 : N111 G1 Z0.001*124
13:08:12.502 : N112 M400*37
13:08:12.502 : N113 M240*38
13:08:12.613 : ok
13:08:12.614 : ok
13:08:12.614 : ok
13:08:12.614 : ok
13:08:12.614 : ok
13:08:12.614 : ok
13:08:12.614 : N114 G1 Z0.001*121
13:08:12.614 : N115 M400*34
13:08:12.614 : N116 M240*35
13:08:12.614 : N117 G1 Z0.001*122
13:08:12.614 : N118 M400*47
13:08:12.614 : ok
13:08:12.614 : N119 M240*44
13:08:12.614 : ok
13:08:12.615 : ok
13:08:12.615 : ok
13:08:12.615 : ok
13:08:12.615 : ok
13:08:12.615 : ok
13:08:12.615 : ok
13:08:12.616 : N120 G1 Z0.001*126
13:08:12.616 : N121 M400*37
13:08:12.616 : N122 M240*36
13:08:12.617 : N123 G1 Z0.001*125
13:08:12.617 : N124 M400*32
13:08:12.617 : N125 M240*35
13:08:12.617 : N126 G1 Z0.001*120
13:08:12.618 : ok
13:08:12.618 : ok
13:08:12.618 : N127 M400*35
13:08:12.618 : N128 M240*46
13:08:12.618 : ok
13:08:12.618 : ok
13:08:12.618 : ok
13:08:12.618 : ok
13:08:12.618 : ok
13:08:12.618 : N129 G1 Z0.001*119
13:08:12.618 : N130 M400*37
13:08:12.618 : N131 M240*38
13:08:12.618 : N132 G1 Z0.001*125
13:08:12.618 : N133 M400*38
13:08:12.618 : N134 M240*35
13:08:12.618 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : N135 G1 Z0.001*122
13:08:12.619 : N136 M400*35
13:08:12.619 : N137 M240*32
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : N138 G1 Z0.001*119
13:08:12.619 : N139 M400*44
13:08:12.619 : N140 M240*32
13:08:12.619 : N141 G1 Z0.001*121
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : N142 M400*32
13:08:12.619 : N143 M240*35
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : ok
13:08:12.619 : N144 G1 Z0.001*124
13:08:12.619 : N145 M400*39
13:08:12.619 : N146 M240*38
13:08:12.620 : N147 G1 Z0.001*127
13:08:12.620 : ok
13:08:12.620 : N148 M400*42
13:08:12.620 : N149 M240*41
13:08:12.620 : ok
13:08:12.620 : N150 G1 Z0.001*121
13:08:12.620 : ok
13:08:12.620 : ok
13:08:12.620 : N151 M400*34
13:08:12.620 : N152 M240*35
13:08:12.620 : ok
13:08:12.620 : ok
13:08:12.620 : N153 G1 Z0.001*122
13:08:12.620 : N154 M400*39
13:08:12.620 : N155 M240*36
13:08:12.620 : ok
13:08:12.620 : ok
13:08:12.620 : ok
13:08:12.620 : N156 G1 Z0.001*127
13:08:12.620 : N157 M400*36
13:08:12.620 : N158 M240*41
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : ok
13:08:12.739 : N159 G1 Z0.001*112
13:08:12.739 : N160 M400*32
13:08:12.739 : N161 M240*35
13:08:12.739 : N162 G1 Z0.001*120
13:08:12.739 : N163 M400*35
13:08:12.739 : N164 M240*38
13:08:12.739 : N165 G1 Z0.001*127
13:08:12.740 : ok
13:08:12.740 : N166 M400*38
13:08:12.740 : N167 M240*37
13:08:12.740 : ok
13:08:12.740 : ok
13:08:12.740 : N168 G1 Z0.001*114
13:08:12.740 : ok
13:08:12.740 : ok
13:08:12.740 : ok
13:08:12.740 : ok
13:08:12.740 : N169 M400*41
13:08:12.740 : N170 M240*35
13:08:12.740 : ok
13:08:12.740 : ok
13:08:12.740 : N171 G1 Z0.001*122
13:08:12.740 : N172 M400*35
13:08:12.740 : N173 M240*32
13:08:12.740 : N174 G1 Z0.001*127
13:08:12.740 : ok
13:08:12.741 : N175 M400*36
13:08:12.741 : N176 M240*37
13:08:12.741 : ok
13:08:12.741 : N177 M114*38
13:08:12.741 : ok
13:08:12.741 : ok
13:08:12.741 : ok
13:08:12.741 : ok
13:08:12.741 : ok
13:08:12.741 : ok
13:08:12.741 : ok
13:08:12.741 : X:0.00 Y:0.00 Z:0.05 E:0.00 Count X:0 Y:0 Z:18
13:08:12.741 : ok
Re: Step Motor Speed
January 29, 2023 06:27AM
Hi, 0.25 seconds looks good

Actually I am not using trigger mode for my Cmos camera. Camera connected to PC, camera has software trigger mode but i did not use the trigger mode, I am just doing pull mode for taking frame from camera, is this barrier to try your settings ? Device is not with me today, I can try your recommendation tomorrow
Re: Step Motor Speed
January 29, 2023 08:39AM
The M240 commands contribute very little to the execution time.

The real question is how you'll coordinate the moves with the camera.

If you use the software trigger then you'll need to develop a python script that will do 25 loops of doing a single move, wait for the completion confirmation and then trigger the camera. That means the overhead will contribute to the overall elapsed time. I have no idea of how much the overhead will cost.

If you use the M240 command to trigger the camera you'll have the lowest execution time.
Re: Step Motor Speed
February 02, 2023 09:48AM
Thanks for your time, but I can't use trigger mode because I can't connect camera to control card. Problem is still going on, I will search the solution
Sorry, only registered users may post in this forum.

Click here to login