Skip to content

Commit 4324fdf

Browse files
committed
refactor: streamline imports and enhance type hinting across multiple files
1 parent 9751872 commit 4324fdf

27 files changed

Lines changed: 111 additions & 77 deletions

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ source .venv/bin/activate
142142
uv sync --dev
143143
```
144144

145+
**Testing with a Different Python Version:**
146+
147+
To create a virtual environment with a specific Python version, use:
148+
149+
```bash
150+
uv venv --clear --python 3.X
151+
```
152+
153+
Replace `3.X` with your desired Python version (e.g., `3.10`).
154+
145155
**Formatting Code:**
146156

147157
To ensure consistency and code quality, run the following commands before submitting your changes:

armctl/_blank/robot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515

1616
# Universal Imports
1717
from __future__ import annotations
18+
1819
import atexit
1920
import math
20-
from armctl.templates import Commands
21-
from armctl.templates import Properties
22-
from armctl.utils import units as uu
23-
from armctl.utils import CommandCheck as cc
21+
22+
from armctl.templates import Commands, Properties
2423

2524
# Choose one of the following Communication Methods
2625
# Uncomment the one you need and comment out the others
2726
from armctl.templates import SocketController as Communication
27+
from armctl.utils import CommandCheck as cc
28+
2829
# from armctl.templates import PLCController as Communication
2930
# from armctl.templates import SerialController as Communication
3031

armctl/dobot/dobot.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import math
2+
3+
from armctl.templates import Commands, Properties
14
from armctl.templates import SerialController as SCT
2-
from armctl.templates import Commands
3-
from armctl.templates import Properties
45
from armctl.utils import CommandCheck as cc
56
from armctl.utils import units as uu
6-
import math
77

88
### Notes ###
99
# - Command Format: CMD(arg)

armctl/elephant_robotics/elephant_robotics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
from __future__ import annotations
2+
13
import time
24

3-
from armctl.templates import Commands
4-
from armctl.templates import Properties
5+
from armctl.templates import Commands, Properties
56
from armctl.templates import SocketController as SCT
6-
77
from armctl.utils import CommandCheck as cc
88
from armctl.utils import units as uu
99

armctl/elephant_robotics/mycobot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .elephant_robotics import ElephantRobotics, uu
2-
import math
32

43

54
class Pro600(ElephantRobotics):

armctl/fanuc/fanuc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
from armctl.templates import Commands
2-
from armctl.templates import Properties
1+
from armctl.templates import Commands, Properties
32
from armctl.templates import PLCController as PLC
4-
53
from armctl.utils import CommandCheck as cc
64

75

armctl/jaka/jaka.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
from __future__ import annotations
2+
13
import ast
24
import math
35
import time
4-
from typing import Any, Dict, List, Union
6+
from typing import Any
57

8+
from armctl.templates import Commands, Properties
9+
from armctl.templates import SocketController as SCT
610
from armctl.utils import CommandCheck as cc
711
from armctl.utils import units as uu
8-
from armctl.templates import Commands
9-
from armctl.templates import Properties
10-
from armctl.templates import SocketController as SCT
1112

1213
### Notes ###
1314
# Command Format: dictionaries/json strings.
@@ -30,9 +31,7 @@ class Jaka(SCT, Commands, Properties):
3031
MAX_JOINT_VELOCITY = uu.deg2rad(180) # rad/s
3132
MAX_JOINT_ACCELERATION = uu.deg2rad(720) # rad/s^2
3233

33-
def __init__(
34-
self, ip: str, port: Union[int, tuple[int, int]] = (10_001, 10_000)
35-
):
34+
def __init__(self, ip: str, port: int | tuple[int, int] = (10_001, 10_000)):
3635
super().__init__(ip, port)
3736

3837
def _response_handler(self, response: str) -> Any:
@@ -41,7 +40,7 @@ def _response_handler(self, response: str) -> Any:
4140
except (ValueError, SyntaxError) as e:
4241
raise RuntimeError(f"Failed to parse response: {response}") from e
4342

44-
def _send_and_check(self, cmd_dict: Dict[str, Any]) -> Dict[str, Any]:
43+
def _send_and_check(self, cmd_dict: dict[str, Any]) -> dict[str, Any]:
4544
resp = self._response_handler(self.send_command(str(cmd_dict)))
4645
if not (
4746
isinstance(resp, dict)
@@ -76,7 +75,7 @@ def sleep(self, seconds: float) -> None:
7675
time.sleep(seconds)
7776

7877
def move_joints(
79-
self, pos: List[float], speed: float = 0.25, acceleration: float = 0.1
78+
self, pos: list[float], speed: float = 0.25, acceleration: float = 0.1
8079
) -> None:
8180
"""
8281
Move the robot to the specified joint positions.
@@ -101,7 +100,7 @@ def move_joints(
101100
self._send_and_check(cmd)
102101

103102
def move_cartesian(
104-
self, pose: List[float], speed: float = 0.25, acceleration: float = 0.0
103+
self, pose: list[float], speed: float = 0.25, acceleration: float = 0.0
105104
) -> None:
106105
"""
107106
Move the robot to the specified cartesian position.
@@ -124,7 +123,7 @@ def move_cartesian(
124123
}
125124
self._send_and_check(cmd)
126125

127-
def get_joint_positions(self) -> List[float]:
126+
def get_joint_positions(self) -> list[float]:
128127
"""
129128
Get the current joint positions of the robot.
130129
Returns
@@ -137,7 +136,7 @@ def get_joint_positions(self) -> List[float]:
137136
response = self._send_and_check(cmd)
138137
return [math.radians(angle) for angle in response["joint_pos"]]
139138

140-
def get_cartesian_position(self) -> List[float]:
139+
def get_cartesian_position(self) -> list[float]:
141140
"""
142141
Retrieves the current Cartesian position of the robot's tool center point (TCP).
143142
Returns
@@ -154,7 +153,7 @@ def stop_motion(self) -> None:
154153
cc.stop_motion()
155154
self._send_and_check({"cmdName": "stop_program"})
156155

157-
def get_robot_state(self) -> Dict[str, Any]:
156+
def get_robot_state(self) -> dict[str, Any]:
158157
"""
159158
Get the current state of the robot.
160159

armctl/templates/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""
1111

1212
from .commands import Commands
13-
from .properties import Properties
1413
from .plc_controller import PLCController
14+
from .properties import Properties
1515
from .serial_controller import SerialController
1616
from .socket_controller import SocketController

armctl/templates/commands.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
2-
from typing import List, Union
34

45

56
class Commands(ABC):
@@ -29,25 +30,25 @@ def sleep(self, seconds: float) -> None:
2930
pass
3031

3132
@abstractmethod
32-
def move_joints(self, pos: List[float]) -> None:
33+
def move_joints(self, pos: list[float]) -> None:
3334
pass
3435

3536
@abstractmethod
36-
def get_joint_positions(self) -> List[float]:
37+
def get_joint_positions(self) -> list[float]:
3738
pass
3839

3940
@abstractmethod
40-
def move_cartesian(self, pose: List[float]) -> None:
41+
def move_cartesian(self, pose: list[float]) -> None:
4142
pass
4243

4344
@abstractmethod
44-
def get_cartesian_position(self) -> List[float]:
45+
def get_cartesian_position(self) -> list[float]:
4546
pass
4647

4748
@abstractmethod
4849
def stop_motion(self) -> None:
4950
pass
5051

5152
@abstractmethod
52-
def get_robot_state(self) -> Union[dict, str]:
53+
def get_robot_state(self) -> dict | str:
5354
pass

armctl/templates/communication.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from __future__ import annotations
2+
13
from abc import ABC, abstractmethod
2-
from typing import Union
34

45

56
class Communication(ABC):
@@ -25,7 +26,5 @@ def disconnect(self) -> None:
2526
pass
2627

2728
@abstractmethod
28-
def send_command(
29-
self, command: Union[str, dict], timeout: float
30-
) -> Union[dict, str]:
29+
def send_command(self, command: str | dict, timeout: float) -> dict | str:
3130
pass

0 commit comments

Comments
 (0)