Skip to content

Commit b27eba5

Browse files
authored
Merge pull request #22 from JuBiotech/pep-561-marker
Add PEP 561 marker, fix docstring formatting and make `MotionType` easier to access
2 parents adc20b2 + 6715a6c commit b27eba5

File tree

5 files changed

+91
-78
lines changed

5 files changed

+91
-78
lines changed

cri_lib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.. include:: ../README.md
33
"""
44

5-
from .cri_controller import CRIController
5+
from .cri_controller import CRIController, MotionType
66
from .cri_errors import CRICommandTimeOutError, CRIConnectionError, CRIError
77
from .cri_protocol_parser import CRIProtocolParser
88
from .robot_state import (

cri_lib/cri_controller.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
logger = logging.getLogger(__name__)
1616

1717

18+
class MotionType(Enum):
19+
"""Robot Motion Type for Jogging"""
20+
21+
Joint = "Joint"
22+
CartBase = "CartBase"
23+
CartTool = "CartTool"
24+
Platform = "Platform"
25+
26+
1827
class CRIController:
1928
"""
2029
Class implementing the CRI network protocol for igus Robot Control.
@@ -25,14 +34,6 @@ class CRIController:
2534
RECEIVE_TIMEOUT_SEC = 5
2635
DEFAULT_ANSWER_TIMEOUT = 10.0
2736

28-
class MotionType(Enum):
29-
"""Robot Motion Type for Jogging"""
30-
31-
Joint = "Joint"
32-
CartBase = "CartBase"
33-
CartTool = "CartTool"
34-
Platform = "Platform"
35-
3637
def __init__(self) -> None:
3738
self.robot_state: RobotState = RobotState()
3839
self.robot_state_lock = threading.Lock()
@@ -692,6 +693,7 @@ def move_joints_relative(
692693
acceleration: float | None = None,
693694
) -> bool:
694695
"""Relative joint move
696+
695697
Parameters
696698
----------
697699
A1-A6, E1-E3 : float
@@ -764,6 +766,7 @@ def move_cartesian(
764766
acceleration: float | None = None,
765767
) -> bool:
766768
"""Cartesian move
769+
767770
Parameters
768771
----------
769772
X,Y,Z,A,B,C,E1-E3 : float
@@ -838,6 +841,7 @@ def move_base_relative(
838841
acceleration: float | None = None,
839842
) -> bool:
840843
"""Relative cartesian move in base coordinate system
844+
841845
Parameters
842846
----------
843847
X,Y,Z,A,B,C,E1-E3 : float
@@ -914,6 +918,7 @@ def move_tool_relative(
914918
acceleration: float | None = None,
915919
) -> bool:
916920
"""Relative cartesian move in tool coordinate system
921+
917922
Parameters
918923
----------
919924
X,Y,Z,A,B,C,E1-E3 : float
@@ -1508,3 +1513,7 @@ def get_motor_temperatures(
15081513
return True
15091514
else:
15101515
return False
1516+
1517+
1518+
# Monkey patch to maintain backward compatibility
1519+
CRIController.MotionType = MotionType # type: ignore

cri_lib/cri_protocol_parser.py

Lines changed: 70 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ def parse_message(
3333
self, message: str
3434
) -> dict[str, str] | dict[str, str | None] | None:
3535
"""Parses a message to the RobotState of the class.
36-
Parameters:
37-
-----------
36+
37+
Parameters
38+
----------
3839
message: str
3940
Message to be parsed including `CRISTART` and `CRIEND`
4041
41-
Returns:
42-
--------
42+
Returns
43+
-------
4344
None | dict[str, str]
4445
None if no Notification in necessary or
4546
a dict indicating which answer event to notify (key: "answer") and optionally an error message (key: "error")
@@ -113,10 +114,10 @@ def _parse_status(self, parameters: list[str]) -> None:
113114
"""
114115
Parses a state message to the robot state.
115116
116-
Parameters:
117-
-----------
118-
parameters: list[str]
119-
List of splitted strings between `STATUS` and `CRIEND`
117+
Parameters
118+
----------
119+
parameters: list[str]
120+
List of splitted strings between `STATUS` and `CRIEND`
120121
"""
121122
segment_start_idx = 0
122123

@@ -289,10 +290,10 @@ def _parse_runstate(self, parameters: list[str]) -> None:
289290
"""
290291
Parses a runstate message to the robot state.
291292
292-
Parameters:
293-
-----------
294-
parameters: list[str]
295-
List of splitted strings between `RUNSTATE` and `CRIEND`
293+
Parameters
294+
----------
295+
parameters: list[str]
296+
List of splitted strings between `RUNSTATE` and `CRIEND`
296297
"""
297298
with self.robot_state_lock:
298299
if parameters[0] == "MAIN":
@@ -314,10 +315,10 @@ def _parse_cyclestat(self, parameters: list[str]) -> None:
314315
"""
315316
Parses a cyclestat message to the robot state.
316317
317-
Parameters:
318-
-----------
319-
parameters: list[str]
320-
List of splitted strings between `CYCLESTAT` and `CRIEND`
318+
Parameters
319+
----------
320+
parameters: list[str]
321+
List of splitted strings between `CYCLESTAT` and `CRIEND`
321322
"""
322323
with self.robot_state_lock:
323324
self.robot_state.cycle_time = float(parameters[0])
@@ -327,10 +328,10 @@ def _parse_gripperstate(self, parameters: list[str]) -> None:
327328
"""
328329
Parses a gripperstate message to the robot state.
329330
330-
Parameters:
331-
-----------
332-
parameters: list[str]
333-
List of splitted strings between `GRIPPERSTATE` and `CRIEND`
331+
Parameters
332+
----------
333+
parameters: list[str]
334+
List of splitted strings between `GRIPPERSTATE` and `CRIEND`
334335
"""
335336
with self.robot_state_lock:
336337
self.robot_state.gripper_state = float(parameters[0])
@@ -339,10 +340,10 @@ def _parse_variables(self, parameters: Sequence[str]) -> None:
339340
"""
340341
Parses a variables message to the robot state.
341342
342-
Parameters:
343-
-----------
344-
parameters: list[str]
345-
List of splitted strings between `VARIABLES` and `CRIEND`
343+
Parameters
344+
----------
345+
parameters: list[str]
346+
List of splitted strings between `VARIABLES` and `CRIEND`
346347
"""
347348
variables: dict[str, float | PosVariable] = {}
348349
idx = 0
@@ -370,10 +371,10 @@ def _parse_opinfo(self, parameters: Sequence[str]) -> None:
370371
"""
371372
Parses a opinfo message to the robot state.
372373
373-
Parameters:
374-
-----------
375-
parameters: list[str]
376-
List of splitted strings between `OPINFO` and `CRIEND`
374+
Parameters
375+
----------
376+
parameters: list[str]
377+
List of splitted strings between `OPINFO` and `CRIEND`
377378
"""
378379
values = []
379380
for i in range(7):
@@ -386,13 +387,13 @@ def _parse_cmd(self, parameters: Sequence[str]) -> str | None:
386387
"""
387388
Parses a cmd message to the robot state.
388389
389-
Parameters:
390-
-----------
391-
parameters: list[str]
392-
List of splitted strings between `CMD` and `CRIEND`
390+
Parameters
391+
----------
392+
parameters: list[str]
393+
List of splitted strings between `CMD` and `CRIEND`
393394
394-
Returns:
395-
--------
395+
Returns
396+
-------
396397
str:
397398
id of answer event
398399
"""
@@ -414,10 +415,10 @@ def _parse_message_message(self, parameters: Sequence[str]) -> None:
414415
"""
415416
Parses a message message to the robot state.
416417
417-
Parameters:
418-
-----------
419-
parameters: list[str]
420-
List of splitted strings between `MESSAGE` and `CRIEND`
418+
Parameters
419+
----------
420+
parameters: list[str]
421+
List of splitted strings between `MESSAGE` and `CRIEND`
421422
"""
422423
if parameters[0] == "RobotControl":
423424
if parameters[1] == "Version":
@@ -468,15 +469,15 @@ def _parse_can_bridge(self, parameters: Sequence[str]) -> dict[str, Any] | None:
468469
parameters: list[str]
469470
List of splitted strings between `CANBridge` and `CRIEND`
470471
471-
Returns:
472-
--------
472+
Returns
473+
-------
473474
dict[str, any] | None
474475
dict with the following keys:
475-
id: CAN id
476-
length: length of CAN packet
477-
data: bytearray with can message
478-
time: timestamp from CRI, 0 at the moment
479-
system_time: system timestamp vrom CRI
476+
- id: CAN id
477+
- length: length of CAN packet
478+
- data: bytearray with can message
479+
- time: timestamp from CRI, 0 at the moment
480+
- system_time: system timestamp vrom CRI
480481
"""
481482
if parameters[0] != "Msg":
482483
return None
@@ -521,10 +522,10 @@ def _parse_config(self, parameters: Sequence[str]) -> None:
521522
"""
522523
Parses a config message to the robot state.
523524
524-
Parameters:
525-
-----------
526-
parameters: list[str]
527-
List of splitted strings between `CONFIG` and `CRIEND`
525+
Parameters
526+
----------
527+
parameters: list[str]
528+
List of splitted strings between `CONFIG` and `CRIEND`
528529
"""
529530
if parameters[0] == "ProjectFile":
530531
with self.robot_state_lock:
@@ -533,13 +534,13 @@ def _parse_config(self, parameters: Sequence[str]) -> None:
533534
def _parse_cmderror(self, parameters: Sequence[str]) -> dict[str, str]:
534535
"""Parses a CMDERROR message to notify calling function
535536
536-
Parameters:
537-
-----------
537+
Parameters
538+
----------
538539
parameters: list[str]
539540
List of splitted strings between `CMDERROR` and `CRIEND`
540541
541-
Returns:
542-
--------
542+
Returns
543+
-------
543544
dict[str, str]
544545
A dict indicating which message id to notify (key: "answer") and the error message (key: "error")
545546
"""
@@ -550,10 +551,10 @@ def _parse_info(self, parameters: list[str]) -> str | None:
550551
"""
551552
Parses a info message to the robot state.
552553
553-
Parameters:
554-
-----------
555-
parameters: list[str]
556-
List of splitted strings between `INFO` and `CRIEND`
554+
Parameters
555+
----------
556+
parameters: list[str]
557+
List of splitted strings between `INFO` and `CRIEND`
557558
"""
558559
if parameters[0] == "ReferencingInfo":
559560
# handle bug in RobotControl with missing space before 'Mandatory'
@@ -603,13 +604,13 @@ def _parse_info(self, parameters: list[str]) -> str | None:
603604
def _parse_execerror(self, parameters: Sequence[str]) -> dict[str, str]:
604605
"""Parses a EXECERROR message to notify calling function
605606
606-
Parameters:
607-
-----------
607+
Parameters
608+
----------
608609
parameters: list[str]
609610
List of splitted strings between `EXECERROR` and `CRIEND`
610611
611-
Returns:
612-
--------
612+
Returns
613+
-------
613614
dict[str, str]
614615
A dict indicating which message id to notify (key: "answer") and the error message (key: "error")
615616
"""
@@ -621,15 +622,15 @@ def _split_quotes_aware(msg: str) -> Sequence[str]:
621622
"""
622623
Splits a string at whitespaces but ignores whitespace whithin quotes.
623624
624-
Parameters:
625-
-----------
626-
msg: str
627-
String to be splitted
625+
Parameters
626+
----------
627+
msg: str
628+
String to be splitted
628629
629-
Returns:
630-
--------
631-
list[str]
632-
list containing the splitted parts of the string
630+
Returns
631+
-------
632+
list[str]
633+
list containing the splitted parts of the string
633634
"""
634635
parts = []
635636
current_part = ""

cri_lib/py.typed

Whitespace-only changes.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ dependencies = []
1212
[tool.setuptools]
1313
packages = ["cri_lib"]
1414

15+
[tool.setuptools.package-data]
16+
"cri_lib" = ["py.typed"]
17+
1518
[tool.isort]
1619
profile = "black"

0 commit comments

Comments
 (0)