Pause movement uArm Swift Pro?

I saw in an old post “you could use “!” to pause the movement”.

How is that command sent?

If the movement is paused can I flush the previous command and send a new one?

“!” could pause the movement.
You could send:
! pause
0x18 flush commands
~ terminate pause, and then you could send new commands.
Did you use python? If so,did you try the “swift.send_cmd” function?

More info:
First I send the command:
swift.send_cmd_async(msg=(“G0 X150 Y150 Z150 F1000”)) and the arm starts moving.

Then:
I tried swift.send_cmd_async(msg=(“!\n”)) and that does stop the movement.

Then:
swift.send_cmd_async(msg=(“0x18n”)) or swift.flush_cmd()

Then a new command :
swift.send_cmd_async(msg=(“G0 X100 Y100 Z100 F1000”))

The new command has no effect, the arm does not change position. It seams that after the ! command I cannot send a new command.

What am I missing?


I do use Python.

What is the syntax to use the swift.send_cmd_async() function to send the “!” and “0x18” commands?

Also, I do not see either of those commands in the gcode document. Where are they listed?

did you send "~ " to terminate the pause?

Hi Daniel,

I was unaware of the “~” command.

Where are the “!”, “~”, and “0x18” commands in the documentation?

I do not see any of them.

Geoff

The firmware is based on GRBL, do you familiar with that?

No I am not familiar with GRBL. I’ll look into it.

In a while loop, while a hardware pin is low
I send swift.set_polar(stretch = 160) …{starting from 220}

The arm starts to move.

When the pin goes high and I’m out of the loop I send
swift.send_cmd_async(msg=(“!\n”))
swift.send_cmd_async(msg=(“0x18\n”))
swift.send_cmd_async(msg=(“~\n”))

This does not stop the arm from moving, it continues with the initial movement

Try this:

Change
swift.send_cmd_async(msg=(“0x18\n”))
to
swift.send_cmd_async(msg=(“chr(0x18)\n”))

OK, I’ll try that but why does the arm keep moving after:
swift.send_cmd_async(msg=(“!\n”))

The arm does not stop.

Try this:

import os
import sys
import time
import functools
sys.path.append(os.path.join(os.path.dirname(file), ‘…/…/…’))
from uarm.wrapper import SwiftAPI
from uarm.utils.log import logger

logger.setLevel(logger.DEBUG)

swift = SwiftAPI(filters={‘hwid’: ‘USB VID:PID=2341:0042’})

start = time.time()
swift.waiting_ready()
time.sleep(1)
#position 1
swift.send_cmd_async(msg=“G0 X150 Y150 Z150 F5”)
#move time 2 seconds
time.sleep(2)
#pause
swift.send_cmd_async(msg=“!”)
#pause duration 4 seconds
time.sleep(4)
#flush cmds
swift.send_cmd_async(chr(0x18))
#resume
swift.send_cmd_async(msg=“~”)
#position 2
swift.send_cmd_async(msg=“G0 X150 Y-150 Z150 F5”)

Progress! This code works by itself, thank you for clarifying the syntax.
Now I am trying to incorporate it into my code and I have some questions.

  1. I have removed the time.sleep() commands when I try this in my code.But there is a delay between when the “!” pause command is sent and the arm stops moving. Is there any way to have that happen faster?

  2. This works in my code: swift.send_cmd_async(msg=“G0 X150 Y150 Z150 F5”)
    But if I try to use the polar command: swift.send_cmd_async(msg=“G201 S100 R50 H100 F5”)
    the arm does not move. Is the G201 command valid? It is listed in the uArm gCoded Communication Protocol.

  3. What is the reason for importing functools in your sample?

  4. How do I read the current coordinates of the arm? I tried the Querying Command “P220” and I get no feedback or return values.

  5. If I send a gCode command with only one axis parameter, for example:
    swift.send_cmd_async(msg=“G0 X150 F10000”)
    The arm moves in the Z direction as well. How do I make move in just one axis?

Here is part of the code showing the While Loop:
while GPIO.input(stretch_minus) == False:
sf = True # Flag to track loop execution
swift.send_cmd_async(msg=“G0 X150 Y150 Z150 F10000”)
# swift.send_cmd_async(msg=“G201 S100 R50 H100 F10000”)

This executes when the loop is exited:
while True:
if GPIO.input(stretch_minus) == True and sf == True:
swift.send_cmd_async(msg = “!”)
swift.send_cmd_async(chr(0x18))
swift.send_cmd_async(msg = “~”)
sf = False # Reset flag

More Info…
I timed the 3 commands above:
swift.send_cmd_async(msg = “!”) ------> 2 milliseconds
swift.send_cmd_async(chr(0x18)) ------> 1.4 seconds
swift.send_cmd_async(msg = “~”) ------> 2.0 seconds
The last 2 commands take a very long time, is this correct?
This is too long for real-time operation.
Is there a faster way to accomplish the same result?

You may refer to a wrong protocol, please refer to this one if you use firmware 4.0:https://github.com/uArm-Developer/SwiftProForArduino/blob/Version_V4.0/doc/uArm%20Swift%20Pro%20Protocol%20V4.0.3_en.pdf

OK, that set of commands is very similar to version 1.2 I believe. None of the version numbers are part of the documentation so It is difficult to know which to use. It would be helpful if the version number was added to the top of the protocol documentation.

I would appreciate it if you could answer my other questions.

I will try again with the 4 digit commands.

Thanks

what other questions?

What is the reason for importing functools in your sample?

How do I read the current coordinates of the arm? I tried the Querying Command “P220” and I get no feedback or return values. The API function does work, get_position,so that may be a solution.

If I send a gCode command with only one axis parameter, for example:
swift.send_cmd_async(msg=“G0 X150 F10000”)
The arm moves in the Z direction as well. How do I make the arm move in just one axis?

I timed the 3 commands above:
swift.send_cmd_async(msg = “!”) ------> 2 milliseconds
swift.send_cmd_async(chr(0x18)) ------> 1.4 seconds
swift.send_cmd_async(msg = “~”) ------> 2.0 seconds
The last 2 commands take a very long time, is this correct?
This is too long for real-time operation.
Is there a faster way to accomplish the same result?

Thanks.

If you need real time control, you may try the uarm controller: Robotic Arm Manufacturer - Collaborative Robots | UFACTORY

OK, I ordered a controller, but you still have not answered my questions.

I’m really trying to get to the bottom of this.

Thanks

#clear the commands
import os
import sys
import time
import functools
from serial.tools import list_ports
import serial
import logging
import threading
sys.path.append(os.path.join(os.path.dirname(file), ‘…/…/…’))
from uarm.wrapper import SwiftAPI
swift = SwiftAPI(filters={‘hwid’: ‘USB VID:PID=2341:0042’}, enable_handle_thread=False)
swift.waiting_ready() # wait the rebot ready
print(swift.get_device_info())

rtn = swift.get_mode(wait=True,timeout=10) # <! make sure the work mode is 5

print( rtn )

swift.send_cmd_async(msg = “G0 X253 Y74 Z106 F15\n”)
time.sleep(3)

swift.send_cmd_async(msg = “G0 X119 Y28 Z44 F15\n”)
time.sleep(3)

swift.send_cmd_async(msg = “G0 X253 Y74 Z106 F15\n”)
time.sleep(1)
swift.send_cmd_async(msg = “!”) #stop

swift.send_cmd_async(msg = chr(0x18)) # clear cmd
time.sleep(1)
swift.send_cmd_async(msg = “~”) # verify
time.sleep(2)

swift.send_cmd_async(msg = “G0 X119 Y28 Z44 F15\n”)
time.sleep(4)

#resume
import os
import sys
import time
import functools
from serial.tools import list_ports
import serial
import logging
import threading
sys.path.append(os.path.join(os.path.dirname(file), ‘…/…/…’))
from uarm.wrapper import SwiftAPI
swift = SwiftAPI(filters={‘hwid’: ‘USB VID:PID=2341:0042’}, enable_handle_thread=False)
swift.waiting_ready() # wait the rebot ready
print(swift.get_device_info())

rtn = swift.get_mode(wait=True,timeout=10) # <! make sure the work mode is 5

print( rtn )

swift.send_cmd_async(msg = “G0 X253 Y74 Z106 F15\n”)
time.sleep(3)

swift.send_cmd_async(msg = “G0 X119 Y28 Z44 F15\n”)
time.sleep(3)
swift.send_cmd_async(msg = “G0 X253 Y74 Z106 F15\n”)

time.sleep(1)

swift.send_cmd_async(msg = “!”) #stop
time.sleep(2)
swift.send_cmd_async(msg = “~”) #terminate pause