diff --git a/schunk_egu_egk_gripper_dummy/doc/plc_control_double_word.png b/schunk_egu_egk_gripper_dummy/doc/plc_control_double_word.png new file mode 100644 index 0000000..b25d51f Binary files /dev/null and b/schunk_egu_egk_gripper_dummy/doc/plc_control_double_word.png differ diff --git a/schunk_egu_egk_gripper_dummy/doc/plc_data_exchange.png b/schunk_egu_egk_gripper_dummy/doc/plc_data_exchange.png new file mode 100644 index 0000000..97003d9 Binary files /dev/null and b/schunk_egu_egk_gripper_dummy/doc/plc_data_exchange.png differ diff --git a/schunk_egu_egk_gripper_dummy/doc/plc_input_data_frame.png b/schunk_egu_egk_gripper_dummy/doc/plc_input_data_frame.png new file mode 100644 index 0000000..1a0031b Binary files /dev/null and b/schunk_egu_egk_gripper_dummy/doc/plc_input_data_frame.png differ diff --git a/schunk_egu_egk_gripper_dummy/doc/plc_output_data_frame.png b/schunk_egu_egk_gripper_dummy/doc/plc_output_data_frame.png new file mode 100644 index 0000000..862cc96 Binary files /dev/null and b/schunk_egu_egk_gripper_dummy/doc/plc_output_data_frame.png differ diff --git a/schunk_egu_egk_gripper_dummy/doc/plc_status_double_word.png b/schunk_egu_egk_gripper_dummy/doc/plc_status_double_word.png new file mode 100644 index 0000000..349bd25 Binary files /dev/null and b/schunk_egu_egk_gripper_dummy/doc/plc_status_double_word.png differ diff --git a/schunk_egu_egk_gripper_dummy/src/dummy.py b/schunk_egu_egk_gripper_dummy/src/dummy.py index 42216d6..4e451cc 100644 --- a/schunk_egu_egk_gripper_dummy/src/dummy.py +++ b/schunk_egu_egk_gripper_dummy/src/dummy.py @@ -13,6 +13,8 @@ def __init__(self): self.enum = None self.metadata = None self.data = None + self.plc_input = "0x0040" + self.plc_output = "0x0048" enum_config = os.path.join( Path(__file__).resolve().parents[1], "config/enum.json" @@ -30,6 +32,9 @@ def __init__(self): with open(data_config, "r") as f: self.data = json.load(f) + self.plc_input_buffer = bytearray(bytes.fromhex(self.data[self.plc_input][0])) + self.plc_output_buffer = bytearray(bytes.fromhex(self.data[self.plc_output][0])) + def start(self) -> None: if self.running: return @@ -83,6 +88,16 @@ def get_data(self, query: dict[str, str]) -> list: return result if inst not in self.data: return result + if inst == self.plc_input: + return self.get_plc_input() + if inst == self.plc_output: + return self.get_plc_output() return self.data[inst] else: return [] + + def get_plc_input(self): + return [self.plc_input_buffer.hex().upper()] + + def get_plc_output(self): + return [self.plc_output_buffer.hex().upper()] diff --git a/schunk_egu_egk_gripper_dummy/tests/test_plc_communication.py b/schunk_egu_egk_gripper_dummy/tests/test_plc_communication.py new file mode 100644 index 0000000..cfd9c73 --- /dev/null +++ b/schunk_egu_egk_gripper_dummy/tests/test_plc_communication.py @@ -0,0 +1,48 @@ +from src.dummy import Dummy +import pytest + +# [1]: https://stb.cloud.schunk.com/media/IM0046706.PDF + + +def test_dummy_initializes_plc_data_buffers(): + dummy = Dummy() + assert dummy.data[dummy.plc_input][0] == dummy.plc_input_buffer.hex().upper() + assert dummy.data[dummy.plc_output][0] == dummy.plc_output_buffer.hex().upper() + + +def test_dummy_returns_plc_data(): + dummy = Dummy() + assert dummy.data[dummy.plc_input] == dummy.get_plc_input() + assert dummy.data[dummy.plc_output] == dummy.get_plc_output() + + +# See p. 24 in +# Booting and establishing operational readiness [1] + + +@pytest.mark.skip() +def test_dummy_starts_in_error_state(): + dummy = Dummy() + query = {"inst": dummy.plc_input, "count": 1} + data = dummy.get_data(query)[0] + assert data[0:2] == "80" + assert data[30:] == "D9" # ERR_FAST_STOP + + +@pytest.mark.skip() +def test_dummy_is_ready_after_acknowledge(): + dummy = Dummy() + control_double_word = "04000000" + set_position = "00000000" + set_speed = "00000000" + gripping_force = "00000000" + command = { + "inst": dummy.plc_output, + "value": control_double_word + set_position + set_speed + gripping_force, + } + dummy.post(command) + + query = {"inst": dummy.plc_input, "count": 1} + data = dummy.get_data(query)[0] + assert data[0:2] == "11" + assert data[30:] == "00" # ERR_NONE