rirze / mirobot-py

A Python interface library for WLkata's Mirobot
https://rirze.github.io/mirobot-py/
MIT License
24 stars 9 forks source link

Sleep needed for first movement after homing and parsing of cartesian coordinates fails #7

Closed rirze closed 4 years ago

rirze commented 4 years ago

Thank you for this nice library!

All functions I've tested are working fine, but only if I wait for the arm to idle before I send the next movement. Edit: Only for the first movement after the home routine I need to wait for idle state. Therefore I would wish for a function wait_for_idle()

Another issue might be the parsing of the cartesian values they never change and stay all zero.

Here is my code for testing:

from mirobot import Mirobot
import time

with Mirobot() as m:
   m.debug = True
   m.home_simultaneous(wait=True)
   time.sleep(10)
   print(m.status.cartesian)
   count=0
   while count < 5 :
       mx = 180.00
       my = 0.00 + count*5
       mz = 170 +count*5
       m.go_to_cartesian_ptp(mx, my, mz, 0.0, 0.0, 0.0, 2000.0, wait=True)
       time.sleep(1)
       print(m.status.cartesian)
       count = count+1

Output:

Message sent:  $H
ok
MirobotCartesianValues(x=0.0, y=0.0, z=0.0, a=0.0, b=0.0, c=0.0)
Message sent:  M20 G90 G0 X180.0 Y0.0 Z170 A0.0 B0.0 C0.0 F2000
ok
MirobotCartesianValues(x=0.0, y=0.0, z=0.0, a=0.0, b=0.0, c=0.0)
Message sent:  M20 G90 G0 X180.0 Y5.0 Z175 A0.0 B0.0 C0.0 F2000
ok
MirobotCartesianValues(x=0.0, y=0.0, z=0.0, a=0.0, b=0.0, c=0.0)
Message sent:  M20 G90 G0 X180.0 Y10.0 Z180 A0.0 B0.0 C0.0 F2000
ok
MirobotCartesianValues(x=0.0, y=0.0, z=0.0, a=0.0, b=0.0, c=0.0)
Message sent:  M20 G90 G0 X180.0 Y15.0 Z185 A0.0 B0.0 C0.0 F2000
ok
MirobotCartesianValues(x=0.0, y=0.0, z=0.0, a=0.0, b=0.0, c=0.0)
Message sent:  M20 G90 G0 X180.0 Y20.0 Z190 A0.0 B0.0 C0.0 F2000
ok
MirobotCartesianValues(x=0.0, y=0.0, z=0.0, a=0.0, b=0.0, c=0.0)

Orginally posted here

rirze commented 4 years ago

This is a very critical issue-- as I did not account for time it takes for the robot to adjust position accordingly after any issued commands.

As desired, I've added a wait_until_idle command under Mirobot. Futhermore, I've integrated this with all default operations, so it doesn't need to be explicitly invoked after each command.

So now, a cleaned up version of OP's code now works as expected:

from mirobot import Mirobot

with Mirobot(debug=True, wait=True) as m:
    m.home_simultaneous()

    print(m.status.cartesian)

    for count in range(5):
        mx = 180.00
        my = 0.00 + count * 5
        mz = 170 + count * 5
        print(f"************Count {count}**********")
        m.go_to_cartesian_ptp(mx, my, mz)

        print(m.status.cartesian)

This will be updated in a new commit on master soon.