loon-python-sdk 0.0.3__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {loon_python_sdk-0.0.3/src/loon_python_sdk.egg-info → loon_python_sdk-0.0.4}/PKG-INFO +1 -1
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/pyproject.toml +1 -1
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk/__init__.py +4 -1
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk/client.py +44 -7
- loon_python_sdk-0.0.4/src/loon_python_sdk/enums.py +53 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4/src/loon_python_sdk.egg-info}/PKG-INFO +1 -1
- loon_python_sdk-0.0.3/src/loon_python_sdk/enums.py +0 -26
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/LICENSE +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/README.md +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/setup.cfg +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk/comms.py +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk/transport.py +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk.egg-info/SOURCES.txt +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk.egg-info/dependency_links.txt +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk.egg-info/requires.txt +0 -0
- {loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: loon-python-sdk
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: Python SDK for the Loon Industries robotic arm
|
|
5
5
|
Author-email: Jake Horner <jakehorner@loon.industries>, Ryan Erickson <ryanerickson@loon.industries>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -4,13 +4,16 @@ Official Python SDK for communicating with and controlling the Loon ESP32 robot
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
from .client import Loon5Arm
|
|
7
|
-
from .enums import TransportType, MsgType
|
|
7
|
+
from .enums import TransportType, MsgType, MotorIds, MotorConnectionStatus, MotorTelemetry
|
|
8
8
|
from .transport import SerialTransport, Transport, WebSocketTransport
|
|
9
9
|
|
|
10
10
|
__all__ = [
|
|
11
11
|
"Loon5Arm",
|
|
12
12
|
"TransportType",
|
|
13
13
|
"MsgType",
|
|
14
|
+
"MotorIds",
|
|
15
|
+
"MotorConnectionStatus",
|
|
16
|
+
"MotorTelemetry",
|
|
14
17
|
"Transport",
|
|
15
18
|
"WebSocketTransport",
|
|
16
19
|
"SerialTransport",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import threading
|
|
1
2
|
from typing import Callable, Dict, List, Optional
|
|
2
3
|
|
|
3
4
|
from loon_python_sdk.comms import (
|
|
@@ -13,7 +14,7 @@ from loon_python_sdk.comms import (
|
|
|
13
14
|
pack_pose,
|
|
14
15
|
parse_motor_telemetry,
|
|
15
16
|
)
|
|
16
|
-
from loon_python_sdk.enums import MsgType
|
|
17
|
+
from loon_python_sdk.enums import MotorTelemetry, MsgType
|
|
17
18
|
from loon_python_sdk.transport import SerialTransport, Transport, WebSocketTransport
|
|
18
19
|
|
|
19
20
|
|
|
@@ -45,16 +46,21 @@ class Loon5Arm:
|
|
|
45
46
|
self.transport = transport
|
|
46
47
|
self.on_telemetry = on_telemetry
|
|
47
48
|
self.telemetry: Dict[int, dict] = {}
|
|
49
|
+
self._telemetry_lock = threading.Lock()
|
|
48
50
|
self.started: bool = False
|
|
49
51
|
|
|
50
52
|
# Telemetry (~5/sec) and heartbeat (~1/3sec) are broadcast continuously by the
|
|
51
53
|
# ESP32 and quickly bury any other output, so they're hidden by default.
|
|
52
54
|
self.show_telemetry: bool = False
|
|
53
55
|
self.show_heartbeat: bool = False
|
|
56
|
+
def __enter__(self):
|
|
57
|
+
self.start();
|
|
58
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
59
|
+
self.close();
|
|
54
60
|
|
|
55
61
|
@classmethod
|
|
56
62
|
def from_websocket(
|
|
57
|
-
|
|
63
|
+
self,
|
|
58
64
|
url: str,
|
|
59
65
|
on_telemetry: Optional[Callable[[List[dict]], None]] = None,
|
|
60
66
|
) -> "Loon5Arm":
|
|
@@ -71,12 +77,12 @@ class Loon5Arm:
|
|
|
71
77
|
transport = WebSocketTransport(
|
|
72
78
|
url, on_frame_received=lambda frame: instance._handle_frame(frame)
|
|
73
79
|
)
|
|
74
|
-
instance =
|
|
80
|
+
instance = self(transport, on_telemetry=on_telemetry)
|
|
75
81
|
return instance
|
|
76
82
|
|
|
77
83
|
@classmethod
|
|
78
84
|
def from_serial(
|
|
79
|
-
|
|
85
|
+
self,
|
|
80
86
|
port: str,
|
|
81
87
|
baudrate: int = 115200,
|
|
82
88
|
on_telemetry: Optional[Callable[[List[dict]], None]] = None,
|
|
@@ -97,7 +103,7 @@ class Loon5Arm:
|
|
|
97
103
|
baudrate=baudrate,
|
|
98
104
|
on_frame_received=lambda frame: instance._handle_frame(frame),
|
|
99
105
|
)
|
|
100
|
-
instance =
|
|
106
|
+
instance = self(transport, on_telemetry=on_telemetry)
|
|
101
107
|
return instance
|
|
102
108
|
|
|
103
109
|
def start(self, timeout: float = 10.0) -> None:
|
|
@@ -115,6 +121,9 @@ class Loon5Arm:
|
|
|
115
121
|
self.transport.start(timeout=timeout)
|
|
116
122
|
self.started = True
|
|
117
123
|
|
|
124
|
+
def is_connected(self) -> bool:
|
|
125
|
+
return self.started;
|
|
126
|
+
|
|
118
127
|
def _handle_frame(self, message: bytes) -> None:
|
|
119
128
|
"""Internal callback invoked when raw binary frames are received from transport.
|
|
120
129
|
|
|
@@ -133,8 +142,9 @@ class Loon5Arm:
|
|
|
133
142
|
# Handle motor telemetry broadcasts (CAN status, angles, speeds, PID gains)
|
|
134
143
|
if msg_type == MsgType.MOTOR_TELEMETRY:
|
|
135
144
|
parsed = parse_motor_telemetry(payload)
|
|
136
|
-
|
|
137
|
-
|
|
145
|
+
with self._telemetry_lock:
|
|
146
|
+
for m in parsed:
|
|
147
|
+
self.telemetry[m["can_id"]] = m
|
|
138
148
|
if self.on_telemetry is not None:
|
|
139
149
|
self.on_telemetry(parsed)
|
|
140
150
|
if not self.show_telemetry:
|
|
@@ -310,6 +320,33 @@ class Loon5Arm:
|
|
|
310
320
|
"""
|
|
311
321
|
self.send(MsgType.MOTOR_ENABLE, pack_motor_enable(can_id, enabled))
|
|
312
322
|
|
|
323
|
+
def get_motor_telemetry(self, can_id: int) -> Optional[MotorTelemetry]:
|
|
324
|
+
"""Return the latest telemetry for a specific motor, or None if not yet received.
|
|
325
|
+
|
|
326
|
+
Args:
|
|
327
|
+
can_id: CAN bus identifier of the motor.
|
|
328
|
+
|
|
329
|
+
Returns:
|
|
330
|
+
MotorTelemetry dataclass for the requested motor, or None if no
|
|
331
|
+
telemetry frame has been received for that CAN ID yet.
|
|
332
|
+
"""
|
|
333
|
+
with self._telemetry_lock:
|
|
334
|
+
data = self.telemetry.get(can_id)
|
|
335
|
+
return MotorTelemetry(**data) if data is not None else None
|
|
336
|
+
|
|
337
|
+
def get_arm_telemetry(self) -> Dict[int, MotorTelemetry]:
|
|
338
|
+
"""Return the latest telemetry for all motors that have reported in.
|
|
339
|
+
|
|
340
|
+
Returns:
|
|
341
|
+
Dictionary mapping each motor's CAN ID to its latest MotorTelemetry.
|
|
342
|
+
"""
|
|
343
|
+
with self._telemetry_lock:
|
|
344
|
+
return {
|
|
345
|
+
can_id: MotorTelemetry(**data)
|
|
346
|
+
for can_id, data in self.telemetry.items()
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
|
|
313
350
|
def ping(self) -> None:
|
|
314
351
|
"""Send a PING heartbeat request (MsgType.PING / 0x00) to verify link connectivity.
|
|
315
352
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from enum import IntEnum
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MsgType(IntEnum):
|
|
6
|
+
PING = 0x00
|
|
7
|
+
PONG = 0x01
|
|
8
|
+
ACK = 0x02
|
|
9
|
+
LOG = 0x03
|
|
10
|
+
STATUS_REQUEST = 0x04
|
|
11
|
+
POSE_CMD = 0x10
|
|
12
|
+
JOINT_ANGLES_CMD = 0x11
|
|
13
|
+
MOTOR_ENABLE = 0x20
|
|
14
|
+
MOTOR_ZERO = 0x21
|
|
15
|
+
MOTOR_SET_PID = 0x22
|
|
16
|
+
MOTOR_POSITION = 0x23
|
|
17
|
+
CONFIG_HOMING = 0x24
|
|
18
|
+
EXECUTE_HOMING = 0x25
|
|
19
|
+
HOME_ARM = 0x26
|
|
20
|
+
MOTOR_SET_CURRENT = 0x27
|
|
21
|
+
MOTOR_TELEMETRY = 0x30
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TransportType(IntEnum):
|
|
25
|
+
WEBSOCKET = 0
|
|
26
|
+
SERIAL = 1
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class MotorConnectionStatus(IntEnum):
|
|
30
|
+
OFFLINE = 0
|
|
31
|
+
ONLINE = 1
|
|
32
|
+
ERROR = 2
|
|
33
|
+
|
|
34
|
+
class MotorIds(IntEnum):
|
|
35
|
+
BASE = 1
|
|
36
|
+
SHOULDER = 2
|
|
37
|
+
ELBOW = 3
|
|
38
|
+
WRIST = 4
|
|
39
|
+
END = 5
|
|
40
|
+
|
|
41
|
+
@dataclass
|
|
42
|
+
class MotorTelemetry:
|
|
43
|
+
can_id: int
|
|
44
|
+
enabled: bool
|
|
45
|
+
status: int # MotorConnectionStatus
|
|
46
|
+
position_deg: float
|
|
47
|
+
target_position_deg: float
|
|
48
|
+
speed_rpm: float
|
|
49
|
+
kp: float
|
|
50
|
+
ki: float
|
|
51
|
+
kd: float
|
|
52
|
+
reversed: bool
|
|
53
|
+
working_current_ma: int = 0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: loon-python-sdk
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.4
|
|
4
4
|
Summary: Python SDK for the Loon Industries robotic arm
|
|
5
5
|
Author-email: Jake Horner <jakehorner@loon.industries>, Ryan Erickson <ryanerickson@loon.industries>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
from enum import IntEnum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class MsgType(IntEnum):
|
|
5
|
-
PING = 0x00
|
|
6
|
-
PONG = 0x01
|
|
7
|
-
ACK = 0x02
|
|
8
|
-
LOG = 0x03
|
|
9
|
-
STATUS_REQUEST = 0x04
|
|
10
|
-
POSE_CMD = 0x10
|
|
11
|
-
JOINT_ANGLES_CMD = 0x11
|
|
12
|
-
MOTOR_ENABLE = 0x20
|
|
13
|
-
MOTOR_ZERO = 0x21
|
|
14
|
-
MOTOR_SET_PID = 0x22
|
|
15
|
-
MOTOR_POSITION = 0x23
|
|
16
|
-
CONFIG_HOMING = 0x24
|
|
17
|
-
EXECUTE_HOMING = 0x25
|
|
18
|
-
HOME_ARM = 0x26
|
|
19
|
-
MOTOR_SET_CURRENT = 0x27
|
|
20
|
-
MOTOR_SET_ACCEL = 0x28
|
|
21
|
-
MOTOR_SET_SPEED = 0x29
|
|
22
|
-
MOTOR_TELEMETRY = 0x30
|
|
23
|
-
|
|
24
|
-
class TransportType(IntEnum):
|
|
25
|
-
WEBSOCKET = 0
|
|
26
|
-
SERIAL = 1
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{loon_python_sdk-0.0.3 → loon_python_sdk-0.0.4}/src/loon_python_sdk.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|