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

update_status parsing error #10

Closed ICE-Timo closed 4 years ago

ICE-Timo commented 4 years ago

Hi there, I run into this error when using update_status()

File "C:/Users/Timo/.PyCharm2019.2/config/scratches/scratch_4.py", line 67, in <module>
    miro.update_status()
  File "C:\Users\Timo\Anaconda3\lib\site-packages\mirobot\mirobot.py", line 257, in update_status
    self.status = self._parse_status(status_msg)
  File "C:\Users\Timo\Anaconda3\lib\site-packages\mirobot\mirobot.py", line 315, in _parse_status
    raise MirobotStatusError(f'Could not parse status message "{msg}"')
mirobot.exceptions.MirobotStatusError: Could not parse status message "ok"
rirze commented 4 years ago

Hi,

Would you mind posting the code that caused this error? I'd like to duplicate this eror.

Thanks!

ICE-Timo commented 4 years ago

It actually occurs everytime I call update_status() Even with this simple example:

from mirobot import Mirobot
miro = Mirobot(debug=True)
miro.home_simultaneous(wait=True)
miro.increment_axis(0,0,0,0,0,1,2000)
miro.update_status()
rirze commented 4 years ago

Weird... I don't get the same error. When was the last time you updated this package? What version are you using?

JorisvanDamTUD commented 4 years ago

Hi Rirze, first of all: great work on this python library for Mirobot!

I'm getting the same errors as ICE-TIMO. I've used his simple example code above and tried other ones from the example code folder. All generate the same "Could not parse status message "ok". The initial homing sequence does start, it only at the end of this that the exception got thrown.

Installed (on 29 april) with pip3 , version indicates its 1.0.5

rirze commented 4 years ago

Thanks!

I really want to fix this issue as it seems critical, so I very appreciate your feedback.

First thing I'm going to do is try and use the pip package and see if I get the same error with the release. It might be that I fixed a bug but didn't include it in the release.

The only other thing I can think of is that some people have different output from their Mirobots, and that the initial startup message has a different terminator string than that of mine. If my version testing doesn't replicate the error, would you mind if I asked for what your Mirobot outputs all the way up to the end of the homing sequence?

Will reach back to you soon.

rirze commented 4 years ago

Unluckily, reverting my version and trying it didn't replicate the issue.

Just for documentation, this is the output I see from the Mirobot when I create it with the debug=True parameter (with Mirobot(debug=True) as m:) :


Grbl 0.9j ['$' for help]

Qinnew Robot 20191228_2 based on Grbl 0.9j ['$' for help]

D1: 78
A1: 32
A2: 108
A3: 20
D4: 170
L: -25
X offset: 0
Y offset: 0
Z offset: 0
Initialized Cartesian coordinates and rotation:
X: 202
Y: 0
Z: 181
RX: 0
RY: 0
RZ: 0
Using reset pos!
Message sent:  $H
ok
MirobotCartesianValues(x=202.0, y=0.0, z=181.0, a=0.0, b=0.0, c=0.0)

If this is somehow different for other users, then I need to know exactly what it outputs before I write a patch.

If you or anyone with this error could show me what Mirobot returns, either from using the debug parameter or from WLkata's Studio (from startup to homing ($H) to status message (?)), that would be very helpful.

JorisvanDamTUD commented 4 years ago

Hi Rirze,

For the record, I'm getting the exact same output (except last line course, because that doesnt run due to the exception)

Grbl 0.9j ['$' for help]

Qinnew Robot 20191228_2 based on Grbl 0.9j ['$' for help]

D1: 78 A1: 32 A2: 108 A3: 20 D4: 170 L: -25 X offset: 0 Y offset: 0 Z offset: 0 Initialized Cartesian coordinates and rotation: X: 202 Y: 0 Z: 181 RX: 0 RY: 0 RZ: 0 Using reset pos! Message sent: $H ok

rirze commented 4 years ago

Great, that's good to know. Now if you're willing, could you show me what output you get from these commands?

Option # 1: Open WKlata Studio and run these commands:

Option # 2:

with Mirobot(debug=True) as m:
    m.home_simultaneous()
    m.get_status()
    m.wait_for_ok()

If this doesn't terminate on it's own, feel free to interrupt it (Control-C)

Please let me know what you see from either method.

JorisvanDamTUD commented 4 years ago

Option #1 Grbl 0.9j ['$' for help]

Qinnew Robot 20191228_2 based on Grbl 0.9j ['$' for help]

D1: 78 A1: 32 A2: 108 A3: 20 D4: 170 L: -25 X offset: 0 Y offset: 0 Z offset: 0 Initialized Cartesian coordinates and rotation: X: 202 Y: 0 Z: 181 RX: 0 RY: 0 RZ: 0 Using reset pos! $H ok ok ? <Idle,Angle(ABCDXYZ):0.000,0.000,0.000,0.000,0.000,0.000,0.000,Cartesian coordinate(XYZ RxRyRz):202.000,0.000,181.000,0.000,0.000,0.000,Pump PWM:0,Valve PWM:0,Motion_MODE:0> ok ok

JorisvanDamTUD commented 4 years ago

Option # 2: comment: I've used the code below, as I always have to explicitly set the portname, not sure if thats related

!/usr/bin/env python3

from mirobot import Mirobot

with Mirobot(portname="COM11", debug=True) as m: m.home_simultaneous() m.get_status() m.wait_for_ok()

Output Option # 2:

Grbl 0.9j ['$' for help]

Qinnew Robot 20191228_2 based on Grbl 0.9j ['$' for help]

D1: 78 A1: 32 A2: 108 A3: 20 D4: 170 L: -25 X offset: 0 Y offset: 0 Z offset: 0 Initialized Cartesian coordinates and rotation: X: 202 Y: 0 Z: 181 RX: 0 RY: 0 RZ: 0 Using reset pos! Message sent: $H ok Traceback (most recent call last): File "D:/Dropbox/1_ TUD/80.Python_Learn/Mirorobot Learn/Test Issue #10.py", line 5, in m.home_simultaneous() File "C:\Users\localadmin\Anaconda2\envs\LearnPython_0810\lib\site-packages\mirobot\base_mirobot.py", line 454, in home_simultaneous return self.send_msg(msg, wait=wait) File "C:\Users\localadmin\Anaconda2\envs\LearnPython_0810\lib\site-packages\mirobot\base_mirobot.py", line 208, in wait_wrapper self.wait_until_idle() File "C:\Users\localadmin\Anaconda2\envs\LearnPython_0810\lib\site-packages\mirobot\base_mirobot.py", line 350, in wait_until_idle self.update_status(disable_debug=True) File "C:\Users\localadmin\Anaconda2\envs\LearnPython_0810\lib\site-packages\mirobot\base_mirobot.py", line 288, in update_status self.status = self._parse_status(status_msg) File "C:\Users\localadmin\Anaconda2\envs\LearnPython_0810\lib\site-packages\mirobot\base_mirobot.py", line 333, in _parse_status raise MirobotStatusError(f'Could not parse status message "{msg}"') mirobot.exceptions.MirobotStatusError: Could not parse status message "ok"

Process finished with exit code 1

rirze commented 4 years ago

This is very strange...

I can reproduce the error when I mismatch wait values between class and homing.

Can you show me the default value for wait in the python script?:

#!/usr/bin/env python3
from mirobot import Mirobot

with Mirobot(portname="COM11", debug=True) as m:
    print("Class wait parameter is:", m.wait)
    m.home_simultaneous()

Let me know if this returns the same error:

#!/usr/bin/env python3
from mirobot import Mirobot

with Mirobot(portname="COM11", debug=True, wait=True) as m:
    print("Class wait parameter is:", m.wait)
    m.home_simultaneous(wait=True)
JorisvanDamTUD commented 4 years ago

same results for both: "Class wait parameter is: True". And both throw the exception and halt

rirze commented 4 years ago

So I still can't exactly reproduce the error, but it might be the case that I can mitigate it at least.

You'll have to download the latest version of this library, which is yet unreleased through pip. Are you able to clone this repository and install it with pip3 install -e .?

If that is not possible, leave your email and I can send you a .whl file that you can use install on your machine locally.

rirze commented 4 years ago

I can reproduce this error.

I managed to get my hands on a Windows machine, and I can replicate the same error with the same stack trace as you both have.

Gonna be working on why this is happening on Windows and not on Linux.

JorisvanDamTUD commented 4 years ago

Ah yes, getting stuff to work on Windows can be a pain, sorry about that :( Good to know it works on Linux though, i might step over to that for the time being.

I did do the pip installation with the cloned git, but that seems to be raising all kinds of new serial port related issues. The exception log form below was from a fresh restarted system, without WlkataStudio or anything else running, so not sure where the serial conflict.

<class 'logging.LogRecord'> [COM11] [DEBUG] Attempting to open serial port COM11 <class 'logging.LogRecord'> [COM11] [DEBUG] Succeeded in opening serial port COM11 [COM11] [DEBUG] Attempting to lock serial port COM11 <class 'logging.LogRecord'> <class 'logging.LogRecord'> [COM11] [ERROR] Unable to acquire port COM11. Make sure another process is not using it! Traceback (most recent call last): <class 'logging.LogRecord'> <class 'logging.LogRecord'> File "C:\Users\localadmin\Anaconda2\envs\LearnPython0810\lib\site-packages\portalocker\portalocker.py", line 62, in lock savepos = file.tell() io.UnsupportedOperation: seek

rirze commented 4 years ago

The current project is definitely a mess for Windows at the moment-- I'm currently ironing out all those issues. The errors you're seeing are errors with the library on Windows, not OS or permissions errors.

I do feel really relieved about being able to isolate the bug to Windows. This gives a spot from which I can work to solve this problem.

JorisvanDamTUD commented 4 years ago

Great! Let me know if I can be of assistance in more testing.

rirze commented 4 years ago

Ok I can confirm that this ...is super lame.

For whatever reason, on Windows, Mirobot's serial port sends 'ok' in response to commands twice. On Linux, it only sends 'ok' once. When I saw this behavior on WKlata Studio, I thought it was some bug or duplicate messaging in the program-- but apparently it's not.

Accounting for platform fixes this error. This patch and other Windows fixes will be committed soon.

Thank you so much @JorisvanDamTUD for your patience in debugging the source of this problem. This'll make this package more accessible to others.