dobot-python icon indicating copy to clipboard operation
dobot-python copied to clipboard

I got an error in the "set_end_effector_params()" function

Open hoshianaaa opened this issue 4 years ago • 4 comments

I added bot.set_end_effector_params (60,0,0) in homing.py. When I ran it, I got the following error:

Traceback (most recent call last): File "examples/homing.py", line 17, in bot.set_end_effector_params(60, 0, 0) File "/home/hoshina/dobot-python/lib/interface.py", line 130, in set_end_effector_params request = Message([0xAA, 0xAA], 2, 60, True, False, [bias_x, bias_y, bias_z], direction='out') File "/home/hoshina/dobot-python/lib/message.py", line 19, in init self.raw_params = self.parse_params('out') File "/home/hoshina/dobot-python/lib/message.py", line 95, in parse_params return parser(self.params) File "/home/hoshina/dobot-python/lib/parsers.py", line 43, in 60: [lambda x: struct.unpack('<' + 'f' * 3, bytearray(x)), None, lambda x: struct.unpack('<Q', bytearray(x))[0], lambda x: list(struct.pack('<' + 'f' * 4, *x))], struct.error: pack expected 4 items for packing (got 3)`

Do you know how to fix the error?

hoshianaaa avatar Feb 16 '21 13:02 hoshianaaa

I think this is one of the functions that weren't very well documented in the official documentation for the low-level API.

There might be an error here:

https://github.com/AlexGustafsson/dobot-python/blob/49c36edb4fd9d05bcbfe6ff9d089f8b1edc10ef3/lib/parsers.py#L43.

The set_end_effector_params only seem to be intended to take three parameters, but the parser expects four.

Try to modify lib/parsers.py, line 43 to use 'f' * 3 instead of 'f' * 4:

- 60: [lambda x: struct.unpack('<' + 'f' * 3, bytearray(x)), None, lambda x: struct.unpack('<Q', bytearray(x))[0], lambda x: list(struct.pack('<' + 'f' * 4, *x))],
+ 60: [lambda x: struct.unpack('<' + 'f' * 3, bytearray(x)), None, lambda x: struct.unpack('<Q', bytearray(x))[0], lambda x: list(struct.pack('<' + 'f' * 3, *x))],

AlexGustafsson avatar Feb 17 '21 10:02 AlexGustafsson

Thank you for your reply. When I tried it, But I got the following error:

Traceback (most recent call last): File "examples/homing.py", line 17, in bot.set_end_effector_params(60, 0, 0) File "/home/hoshina/dobot-python/lib/interface.py", line 131, in set_end_effector_params return self.send(request) File "/home/hoshina/dobot-python/lib/interface.py", line 24, in send response = Message.read(self.serial) File "/home/hoshina/dobot-python/lib/message.py", line 63, in read return Message.parse(header + bytes([length]) + payload + checksum) File "/home/hoshina/dobot-python/lib/message.py", line 50, in parse return Message(header, length, id, rw, is_queued, params) File "/home/hoshina/dobot-python/lib/message.py", line 16, in init self.params = self.parse_params('in') File "/home/hoshina/dobot-python/lib/message.py", line 83, in parse_params return parser(self.raw_params) File "/home/hoshina/dobot-python/lib/parsers.py", line 43, in 60: [lambda x: struct.unpack('<' + 'f' * 3, bytearray(x)), None, lambda x: struct.unpack('<Q', bytearray(x))[0], lambda x: list(struct.pack('<' + 'f' * 3, *x))], struct.error: unpack requires a buffer of 12 bytes

hoshianaaa avatar Feb 18 '21 03:02 hoshianaaa

After that, Dobot Magician froze and stopped working without restarting the power supply.

hoshianaaa avatar Feb 18 '21 03:02 hoshianaaa

Unfortunately this seems to be an instance where the documentation didn't match reality, and I wasn't able to properly test the functionality. I don't have my hands on a robot right now. If you have the time and interest, the documentation I used to implement the functionality is available here: https://download.dobot.cc/product-manual/dobot-magician/pdf/en/Dobot-Communication-Protocol-V1.1.5.pdf.

With some trial and error, you may find how set_end_effector_params should actually be called and fix the mistake in this library.

I'll keep this open, but for now I won't be able to be much of help.

AlexGustafsson avatar Feb 19 '21 13:02 AlexGustafsson