Python API - way to stop list of set_position commands?

Firmware Version: 3.2.0

Operation System: Mac

uArm Controlling Method: Python
API: uArm-Python-SDK/swift_api.md at master · uArm-Developer/uArm-Python-SDK · GitHub

If I loop through and send a set of set_position commands, but all of a sudden want to stop (in whatever position it is in) and give it a new set of set_position commands, is that possible via the Swift API (or at all)?

Could you post your codes and the logs?

Hi Daniel.

I created an example gist here:

The question is, once I’ve given a series of synchronous commands like in the above, if at any point while it’s carrying out the commands I want to stop, how do I do that?

Hi!
I was looking for the same feature. I want to move the arm down until it reaches an object to pick it up with the pump. The limit switch successfully triggers a callback, but I don’t know how to stop the arm there.

Hi, for instance, if you send loop command to go to point A-B-C-D-A……, and all of a sudden you want the uArm go to point F, if the uArm is on its way to point C, it will go to point C first and then go to point F, then go to point D to continue the loop. Hope this will help you.

Hi Daniel,

2 questions with your example:

  1. Is there any way to stop it immediately, so it doesn’t go to C if it’s on its way?

  2. Is there any way to “flush” the list of commands it has queued? So if it goes to point F after it finishes point C, it will stop after F and not continue to go to D and A?

I’ve been working on a problem that requires me to stop the uarm once a trigger signal occur. Pyuf doesn’t have that command so I looked at the Gcode and add a function into the swift api:

def stop_servo(self, servo_id = None):
‘’’
Stop the uarm from moving
Args:
servo_id: SERVO_BOTTOM, SERVO_LEFT, SERVO_RIGHT, SERVO_HAND
‘’’
cmd = ‘set cmd_sync G2203’
ret = self._ports[‘service’][‘handle’].call(cmd)
return.ret.startswith(‘Ok’)

Although, the uarm doesn’t behave as I expected. It cuts the power to all motor and it dropped dead instead of moving onto the next command line. If you find a way to implement this function, please do let me know.

This will work

x = 300
i = 150
while i <= x:
swift.set_position(i, 0, 60, speed=20000, timeout=1) # go to point C
sleep(.05)
print(i)
button = swift.get_digital(21)
if not button:
cPos = swift.get_position()
print(cPos)
break
i += 1

go to point F
P/s: I’m sorry about the indentation