Skip to content

Instantly share code, notes, and snippets.

@nick-jonas
Last active March 20, 2018 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nick-jonas/96e2030b2cf1ba949b97f4dcbb7e4ab4 to your computer and use it in GitHub Desktop.
Save nick-jonas/96e2030b2cf1ba949b97f4dcbb7e4ab4 to your computer and use it in GitHub Desktop.
Run through and position a series of points - question is how can I stop in the middle?
def set_position(self, x = None, y = None, z = None,
speed = 5000, relative = False,
wait = True, timeout = 10):
if True != self.swift.set_position(x, y, z, speed, relative, wait, timeout):
print("Set position failed!")
def raise_arm(self):
self.swift.flush_cmd()
self.set_position(z = self.RAISED_Z, relative = False)
def lower_arm(self):
self.swift.flush_cmd()
self.set_position(z = self.DRAWING_Z, relative = False)
# points is a 3-dimen array, like this:
points = [[[26,27],[26,36],[26,43],[26,52],[26,60],[26,65],[26,69],[26,72]],[[27,25],[30,25],[35,25],[39,25],[42,25],[46,25],[51,25],[55,25],[59,25],[62,25],[67,25],[73,25],[76,25]],[[58,50],[58,53],[58,57],[58,60],[58,64],[58,67]],[[52,46],[55,46],[58,46],[61,46],[64,46],[68,46],[71,46]],[[83,49],[83,52],[83,55],[83,58],[83,61],[83,64],[84,66],[87,66],[90,66],[95,66],[99,66],[102,66]],[[449,21],[452,21],[456,22],[458,23],[460,24],[464,24],[467,24],[469,25],[473,25],[475,26],[478,26],[480,29],[479,34],[478,39],[478,45],[478,49],[478,55],[478,59],[478,65],[478,69],[478,72]],[[474,446],[474,452],[474,456],[474,459],[474,463],[474,466],[474,469],[474,472],[474,475],[475,478],[472,479],[470,478],[465,478],[462,478],[458,477],[455,477],[452,477],[449,477],[447,478]],[[26,444],[26,447],[26,451],[26,454],[26,457],[26,460],[26,463],[26,467],[26,470],[26,473],[25,477],[30,477],[33,477],[37,477],[42,477],[46,477],[51,477],[55,477],[58,477],[62,477]]]
i = 0
while i < len(points):
move_to_x, move_to_y = points[i][0]
move_to_x = move_to_x - last_x
move_to_y = move_to_y - last_y
# reverse x & y for the robot
set_position(x = move_to_y, y = move_to_x, relative = True)
last_x, last_y = points[i][0]
lower_arm()
if len(points[i]) > 0:
# we've moved to the first point, start drawing with the second point
j = 1
while j < len(points[i]):
x, y = points[i][j]
x = x - last_x
y = y - last_y
# reverse x & y for the robot
set_position(x = y, y = x, relative = True)
last_x, last_y = points[i][j]
j += 1
i += 1
raise_arm()
@alihammoud90
Copy link

Hello, did you find any solution for sudden stopping the uarm when several criterias are met? I'm sending serial commands to the uArm using Java, and I want the uArm to stop when it matches some coordinates, can you help me with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment