From ffe6ff7a5eb4c7137505b44c87a687f59ab615b9 Mon Sep 17 00:00:00 2001 From: Alexei Belikov Date: Sat, 1 Feb 2020 00:25:54 +0100 Subject: [PATCH 1/4] Add wait command --- pydobot/dobot.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pydobot/dobot.py b/pydobot/dobot.py index 096710f..771f8a6 100644 --- a/pydobot/dobot.py +++ b/pydobot/dobot.py @@ -235,6 +235,13 @@ def _set_end_effector_laser(self, power=255, enable=False): msg.params.extend(bytearray([power])) return self._send_command(msg) + def _set_wait_cmd(self, ms): + msg = Message() + msg.id = 110 + msg.ctrl = 0x03 + msg.params = bytearray(struct.pack('I', ms)) + return self._send_command(msg) + def _set_queued_cmd_start_exec(self): msg = Message() msg.id = 240 @@ -493,6 +500,9 @@ def engrave(self, image, pixel_size, low=0.0, high=40.0, velocity=5, acceleratio self.wait_for_cmd(self.laze(0, False)) + def wait(self, ms): + self._set_wait_cmd(ms) + if __name__ == '__main__': d = Dobot() From 8d16d12de79a2880cbfb13353aa930086afd18f7 Mon Sep 17 00:00:00 2001 From: Alexei Belikov Date: Mon, 20 Jan 2020 10:54:36 +0100 Subject: [PATCH 2/4] Add set io multiplexing command --- pydobot/dobot.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pydobot/dobot.py b/pydobot/dobot.py index 771f8a6..01e82e5 100644 --- a/pydobot/dobot.py +++ b/pydobot/dobot.py @@ -19,6 +19,7 @@ MODE_PTP_MOVL_INC = 0x07 MODE_PTP_MOVJ_XYZ_INC = 0x08 MODE_PTP_JUMP_MOVL_XYZ = 0x09 +IO_MODES = {'Dummy': 1, 'PWM': 2, 'DO': 3, 'DI': 4, 'ADC': 5} STEP_PER_CIRCLE = 360.0 / 1.8 * 10.0 * 16.0 MM_PER_CIRCLE = 3.1415926535898 * 36.0 @@ -242,6 +243,14 @@ def _set_wait_cmd(self, ms): msg.params = bytearray(struct.pack('I', ms)) return self._send_command(msg) + def _set_io_multiplexing(self, address, mode): + msg = Message() + msg.id = 130 + msg.ctrl = 0x03 + msg.params = bytearray(struct.pack('B', address)) + msg.params.extend(bytearray(struct.pack('B', mode))) + return self._send_command(msg) + def _set_queued_cmd_start_exec(self): msg = Message() msg.id = 240 @@ -503,6 +512,9 @@ def engrave(self, image, pixel_size, low=0.0, high=40.0, velocity=5, acceleratio def wait(self, ms): self._set_wait_cmd(ms) + def set_io_mode(self, address, mode, wait=False): + self._set_io_multiplexing(address, IO_MODES[mode], wait) + if __name__ == '__main__': d = Dobot() From 4704474ff547f454953500599b2624bad07244b7 Mon Sep 17 00:00:00 2001 From: Alexei Belikov Date: Mon, 20 Jan 2020 10:55:26 +0100 Subject: [PATCH 3/4] Add set io pwm command --- pydobot/dobot.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pydobot/dobot.py b/pydobot/dobot.py index 01e82e5..57420ed 100644 --- a/pydobot/dobot.py +++ b/pydobot/dobot.py @@ -251,6 +251,15 @@ def _set_io_multiplexing(self, address, mode): msg.params.extend(bytearray(struct.pack('B', mode))) return self._send_command(msg) + def _set_io_pwm(self, address, f, d): + msg = Message() + msg.id = 132 + msg.ctrl = 0x03 + msg.params = bytearray(struct.pack('B', address)) + msg.params.extend(bytearray(struct.pack('f', f))) + msg.params.extend(bytearray(struct.pack('f', d))) + return self._send_command(msg) + def _set_queued_cmd_start_exec(self): msg = Message() msg.id = 240 @@ -512,8 +521,11 @@ def engrave(self, image, pixel_size, low=0.0, high=40.0, velocity=5, acceleratio def wait(self, ms): self._set_wait_cmd(ms) - def set_io_mode(self, address, mode, wait=False): - self._set_io_multiplexing(address, IO_MODES[mode], wait) + def set_io_mode(self, address, mode): + self._set_io_multiplexing(address, IO_MODES[mode]) + + def set_pwm_output(self, address, frequency, duty_cycle): + self._set_io_pwm(address, frequency, duty_cycle) if __name__ == '__main__': From 3f5df457770f101654a2b627d86c71f94092b6bd Mon Sep 17 00:00:00 2001 From: Alexei Belikov Date: Sat, 1 Feb 2020 00:39:49 +0100 Subject: [PATCH 4/4] Update readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 209070e..48b99a3 100644 --- a/README.md +++ b/README.md @@ -64,3 +64,15 @@ Methods * **enable**: _bool_ enables/disables suction * **.grip(enable)** * **enable**: _bool_ enables/disables gripper +* **.wait(ms)** + * **ms**: _integer_ milliseconds to wait before the next command + * **wait**: _bool_ waits until command has been executed to return to process +* **.set_io_mode(address, mode, wait=False)** + * **address**: _integer_ EIO port number + * **mode**: _str_ I/O mode (Dummy, PWM, DO, DI, ADC) + * **wait**: _bool_ waits until command has been executed to return to process +* **.set_pwm_output(address, frequency, duty_cycle, wait=False)** + * **address**: _integer_ EIO port number + * **frequency**: _float_ pulse frequency + * **duty_cycle**: _float_ pulse duty cycle (0 to 100) + * **wait**: _bool_ waits until command has been executed to return to process