orionrobots / python_usb_robot_arm

Python code to interact with the maplin robot arm.
Other
16 stars 10 forks source link

Concurrent Movements #14

Open RetroJimmyX opened 2 years ago

RetroJimmyX commented 2 years ago

I watched a youtube video about controlling the arm with Flask and Python and noticed the use of the OR operator "|" in the code to produce concurrent movements. The code was arm.move(usb_arm.WristUp|usb_arm.ElbowUp) In the Python program I made to control the arm, I'm using a function, to which I pass the arguments of which component to use and move by how much. e.g. def arm_control(component,time): if component == "e": if time > 0: arm.move(usb_arm.ElbowUp, time) elif time < 0: arm.move(usb_arm.ElbowDown, time)

It means that essentially I can type easy command such as e3 or s-2 to move the elbow up for 3 seconds or the should down for 2 seconds. I have my code on my repository (word of warning - I'm not a programmer!)

Apologies for posting here but struggling to find a solution. Any ideas how I can use my code to call functions concurrently? Is it just a case of using something like this to call my function simulatenously? i.e. p1 = Process(target = arm_control("e",3)) p1.start() p2 = Process(target = arm_control("s",-2)) p2.start()

...or is the a neater way to do this and utilise the feature you have with the "|" operator?

HUGE thanks in advance!

dannystaple commented 2 years ago

Hello, that video was likely mine. At some point (and this is worthy of a feature request), I should modify this code to be concurrent, or demonstrate such patterns.