Skip to content

Commit

Permalink
Keep plc data buffers separate
Browse files Browse the repository at this point in the history
This makes bit operations on these data easier than with immutable
strings.
Also add image documentation for the different plc data messages and
double words.
  • Loading branch information
stefanscherzinger committed Jul 30, 2024
1 parent e77ce6d commit e79f736
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions schunk_egu_egk_gripper_dummy/src/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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()]
48 changes: 48 additions & 0 deletions schunk_egu_egk_gripper_dummy/tests/test_plc_communication.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e79f736

Please sign in to comment.