loon-python-sdk 0.0.1__py3-none-any.whl

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.
@@ -0,0 +1,17 @@
1
+ """Loon Python SDK.
2
+
3
+ Official Python SDK for communicating with and controlling the Loon ESP32 robot arm.
4
+ """
5
+
6
+ from .client import Client
7
+ from .enums import ClientType, MsgType
8
+ from .transport import SerialTransport, Transport, WebSocketTransport
9
+
10
+ __all__ = [
11
+ "Client",
12
+ "ClientType",
13
+ "MsgType",
14
+ "Transport",
15
+ "WebSocketTransport",
16
+ "SerialTransport",
17
+ ]
@@ -0,0 +1,324 @@
1
+ from typing import Callable, Dict, List, Optional
2
+
3
+ from loon_python_sdk.comms import (
4
+ decode_frame,
5
+ describe_payload,
6
+ encode_frame,
7
+ pack_homing_cmd,
8
+ pack_homing_config,
9
+ pack_joint_angles,
10
+ pack_motor_enable,
11
+ pack_motor_pid,
12
+ pack_motor_position,
13
+ pack_pose,
14
+ parse_motor_telemetry,
15
+ )
16
+ from loon_python_sdk.enums import MsgType
17
+ from loon_python_sdk.transport import SerialTransport, Transport, WebSocketTransport
18
+
19
+
20
+ class Client:
21
+ """High-level client for communicating with the Loon ESP32 robot arm controller.
22
+
23
+ Provides high-level commands for joint positioning, Cartesian pose control (IK),
24
+ homing, motor PID tuning, telemetry tracking, and heartbeat monitoring across
25
+ different communication transports (WebSocket or Serial).
26
+ """
27
+
28
+ def __init__(
29
+ self,
30
+ transport: Optional[Transport] = None,
31
+ on_telemetry: Optional[Callable[[List[dict]], None]] = None,
32
+ ):
33
+ """Initialize a Loon robot arm client.
34
+
35
+ Args:
36
+ transport: The underlying communication transport (WebSocketTransport or
37
+ SerialTransport). If None, can be configured later or initialized via
38
+ factory classmethods `from_websocket()` or `from_serial()`.
39
+ on_telemetry: Optional callback invoked whenever a MOTOR_TELEMETRY frame
40
+ arrives. Receives a list of dictionaries with per-motor states
41
+ (position_deg, speed_rpm, current gains, etc.). Runs on the
42
+ transport's background receiver thread; callers sharing state across
43
+ threads (e.g., in a GUI or game loop) should apply appropriate locking.
44
+ """
45
+ self.transport = transport
46
+ self.on_telemetry = on_telemetry
47
+ self.telemetry: Dict[int, dict] = {}
48
+ self.started: bool = False
49
+
50
+ # Telemetry (~5/sec) and heartbeat (~1/3sec) are broadcast continuously by the
51
+ # ESP32 and quickly bury any other output, so they're hidden by default.
52
+ self.show_telemetry: bool = False
53
+ self.show_heartbeat: bool = False
54
+
55
+ @classmethod
56
+ def from_websocket(
57
+ cls,
58
+ url: str,
59
+ on_telemetry: Optional[Callable[[List[dict]], None]] = None,
60
+ ) -> "Client":
61
+ """Factory method to create and configure a Client using WebSocket transport.
62
+
63
+ Args:
64
+ url: WebSocket URL of the ESP32 (e.g., 'ws://192.168.4.1:80/ws').
65
+ on_telemetry: Optional callback invoked when telemetry frames arrive.
66
+
67
+ Returns:
68
+ A configured Client instance ready to be started via `client.start()`.
69
+ """
70
+ instance = None
71
+ transport = WebSocketTransport(
72
+ url, on_frame_received=lambda frame: instance._handle_frame(frame)
73
+ )
74
+ instance = cls(transport, on_telemetry=on_telemetry)
75
+ return instance
76
+
77
+ @classmethod
78
+ def from_serial(
79
+ cls,
80
+ port: str,
81
+ baudrate: int = 115200,
82
+ on_telemetry: Optional[Callable[[List[dict]], None]] = None,
83
+ ) -> "Client":
84
+ """Factory method to create and configure a Client using Serial transport.
85
+
86
+ Args:
87
+ port: Serial device path or COM port (e.g., '/dev/ttyUSB0' or 'COM3').
88
+ baudrate: Communication baud rate in bits/sec (default: 115200).
89
+ on_telemetry: Optional callback invoked when telemetry frames arrive.
90
+
91
+ Returns:
92
+ A configured Client instance ready to be started via `client.start()`.
93
+ """
94
+ instance = None
95
+ transport = SerialTransport(
96
+ port=port,
97
+ baudrate=baudrate,
98
+ on_frame_received=lambda frame: instance._handle_frame(frame),
99
+ )
100
+ instance = cls(transport, on_telemetry=on_telemetry)
101
+ return instance
102
+
103
+ def start(self, timeout: float = 10.0) -> None:
104
+ """Start the transport background communication thread and connect.
105
+
106
+ Args:
107
+ timeout: Maximum seconds to wait for connection confirmation before
108
+ raising a RuntimeError.
109
+
110
+ Raises:
111
+ RuntimeError: If no transport is attached, or if connection fails.
112
+ """
113
+ if self.transport is None:
114
+ raise RuntimeError("No transport configured for client.")
115
+ self.transport.start(timeout=timeout)
116
+ self.started = True
117
+
118
+ def _handle_frame(self, message: bytes) -> None:
119
+ """Internal callback invoked when raw binary frames are received from transport.
120
+
121
+ Decodes the frame boundary, parses telemetry and status packets, updates
122
+ internal telemetry cache, triggers user callbacks, and prints console messages.
123
+
124
+ Args:
125
+ message: Raw bytes containing a single validated packet.
126
+ """
127
+ try:
128
+ msg_type, payload = decode_frame(message)
129
+ except ValueError as e:
130
+ print(f"[recv] malformed frame ({e}): {message.hex()}")
131
+ return
132
+
133
+ # Handle motor telemetry broadcasts (CAN status, angles, speeds, PID gains)
134
+ if msg_type == MsgType.MOTOR_TELEMETRY:
135
+ parsed = parse_motor_telemetry(payload)
136
+ for m in parsed:
137
+ self.telemetry[m["can_id"]] = m
138
+ if self.on_telemetry is not None:
139
+ self.on_telemetry(parsed)
140
+ if not self.show_telemetry:
141
+ return
142
+
143
+ # Suppress heartbeat pong prints unless explicitly enabled
144
+ if msg_type == MsgType.PONG and not self.show_heartbeat:
145
+ return
146
+
147
+ print(f"[recv] {describe_payload(msg_type, payload)}")
148
+
149
+ def send(self, msg_type: int, payload: bytes = b"") -> None:
150
+ """Encode and transmit a binary command frame to the robot controller.
151
+
152
+ Frames follow the wire protocol format:
153
+ [START 0x7E][TYPE 1B][SIZE 1B][PAYLOAD 0-200B][CHECKSUM 1B]
154
+
155
+ Args:
156
+ msg_type: Packet command identifier (from MsgType enum or integer).
157
+ payload: Binary payload bytes (little-endian encoded).
158
+
159
+ Raises:
160
+ RuntimeError: If client transport is not configured.
161
+ ValueError: If payload length exceeds MAX_PAYLOAD (200 bytes).
162
+ """
163
+ if self.transport is None:
164
+ raise RuntimeError("No transport configured for client.")
165
+ frame = encode_frame(msg_type, payload)
166
+ self.transport.send_bytes(frame)
167
+
168
+ def home_arm(self) -> None:
169
+ """Execute automated sequential homing of arm motors 2, 3, and 4.
170
+
171
+ Sends MsgType.HOME_ARM (0x26). The ESP32 executes homing in the background:
172
+ Motor 2 (Shoulder) -> Motor 3 (Elbow) -> Motor 4 (Wrist) in order.
173
+ An immediate ACK indicates the routine started; watch console LOG messages
174
+ for intermediate motor completion and the final result.
175
+ """
176
+ self.send(MsgType.HOME_ARM)
177
+
178
+ def home_motor(self, can_id: int) -> None:
179
+ """Execute homing sequence for a single specified motor.
180
+
181
+ Sends MsgType.EXECUTE_HOMING (0x25) with target CAN ID.
182
+
183
+ Args:
184
+ can_id: CAN bus identifier of the motor to home (e.g., 2, 3, or 4).
185
+ """
186
+ self.send(MsgType.EXECUTE_HOMING, pack_homing_cmd(can_id))
187
+
188
+ def config_homing(
189
+ self,
190
+ can_id: int,
191
+ direction: int,
192
+ speed: int,
193
+ mode: int,
194
+ offset: int,
195
+ current: int,
196
+ ) -> None:
197
+ """Configure homing parameters for a motor before homing is executed.
198
+
199
+ Sends MsgType.CONFIG_HOMING (0x24) to program the motor's homing behavior.
200
+
201
+ Args:
202
+ can_id: CAN bus ID of the target motor.
203
+ direction: Search direction (0 = Clockwise, 1 = Counter-Clockwise).
204
+ speed: Homing seek speed in RPM (0 to 3000 RPM).
205
+ mode: Homing mode (0 = origin-switch, 1 = mechanical-limit, 2 = single-lap).
206
+ offset: Origin offset count from triggered position.
207
+ current: Zero-return threshold current in mA (for stall/limit detection).
208
+ """
209
+ self.send(
210
+ MsgType.CONFIG_HOMING,
211
+ pack_homing_config(can_id, direction, speed, mode, offset, current),
212
+ )
213
+
214
+ def set_pose(
215
+ self,
216
+ x: float,
217
+ y: float = 0.0,
218
+ z: float = 0.0,
219
+ roll: float = 0.0,
220
+ pitch: float = 0.0,
221
+ yaw: float = 0.0,
222
+ grip: float = 0.0,
223
+ ) -> None:
224
+ """Command end-effector Cartesian pose using the ESP32 on-board Inverse Kinematics (IK).
225
+
226
+ Sends MsgType.POSE_CMD (0x10). The controller's IK solver computes target
227
+ joint angles to position and orient the gripper tool center point (TCP).
228
+
229
+ Args:
230
+ x: Forward Cartesian position from base center.
231
+ y: Lateral Cartesian position (set to 0.0 to prevent base rotation if wired).
232
+ z: Vertical Cartesian height position.
233
+ roll: Tool wrist roll angle (degrees).
234
+ pitch: Tool wrist pitch angle (degrees).
235
+ yaw: Tool wrist yaw angle (degrees).
236
+ grip: Claw gripper position value (0 = closed, higher = open).
237
+ """
238
+ self.send(MsgType.POSE_CMD, pack_pose(x, y, z, roll, pitch, yaw, grip))
239
+
240
+ def set_angle(self, can_id: int, degrees: float) -> None:
241
+ """Command an individual motor directly to an absolute target angle.
242
+
243
+ Sends MsgType.MOTOR_POSITION (0x23).
244
+
245
+ Args:
246
+ can_id: Target motor CAN bus identifier (1 to 6).
247
+ degrees: Target position in degrees.
248
+ """
249
+ self.send(MsgType.MOTOR_POSITION, pack_motor_position(can_id, degrees))
250
+
251
+ def set_joint_angles(
252
+ self,
253
+ base: float = 0.0,
254
+ shoulder: float = 0.0,
255
+ elbow: float = 0.0,
256
+ wrist: float = 0.0,
257
+ twist: float = 0.0,
258
+ claw: float = 0.0,
259
+ ) -> None:
260
+ """Directly command all 6 arm joints simultaneously, bypassing IK.
261
+
262
+ Sends MsgType.JOINT_ANGLES_CMD (0x11).
263
+
264
+ Args:
265
+ base: Base rotation joint angle in degrees (Joint 1).
266
+ shoulder: Shoulder pitch joint angle in degrees (Joint 2).
267
+ elbow: Elbow pitch joint angle in degrees (Joint 3).
268
+ wrist: Wrist pitch joint angle in degrees (Joint 4).
269
+ twist: Wrist roll/twist joint angle in degrees (Joint 5).
270
+ claw: End-effector claw opening in degrees (Joint 6).
271
+ """
272
+ self.send(
273
+ MsgType.JOINT_ANGLES_CMD,
274
+ pack_joint_angles(base, shoulder, elbow, wrist, twist, claw),
275
+ )
276
+
277
+ def set_angles(
278
+ self,
279
+ base: float = 0.0,
280
+ shoulder: float = 0.0,
281
+ elbow: float = 0.0,
282
+ wrist: float = 0.0,
283
+ twist: float = 0.0,
284
+ claw: float = 0.0,
285
+ ) -> None:
286
+ """Convenience alias for `set_joint_angles()`."""
287
+ self.set_joint_angles(base, shoulder, elbow, wrist, twist, claw)
288
+
289
+ def set_pid(self, can_id: int, kp: float, ki: float, kd: float) -> None:
290
+ """Configure PID controller gains for a specific motor on the fly.
291
+
292
+ Sends MsgType.MOTOR_SET_PID (0x22).
293
+
294
+ Args:
295
+ can_id: CAN bus identifier of the motor.
296
+ kp: Proportional gain (determines stiffness and rise time).
297
+ ki: Integral gain (eliminates steady-state offset and gravity droop).
298
+ kd: Derivative gain (damps oscillations and prevents overshoot).
299
+ """
300
+ self.send(MsgType.MOTOR_SET_PID, pack_motor_pid(can_id, kp, ki, kd))
301
+
302
+ def enable_motor(self, can_id: int, enabled: bool = True) -> None:
303
+ """Enable or disable drive torque for a motor.
304
+
305
+ Sends MsgType.MOTOR_ENABLE (0x20).
306
+
307
+ Args:
308
+ can_id: CAN bus identifier of the motor.
309
+ enabled: True to engage active torque control, False to freewheel.
310
+ """
311
+ self.send(MsgType.MOTOR_ENABLE, pack_motor_enable(can_id, enabled))
312
+
313
+ def ping(self) -> None:
314
+ """Send a PING heartbeat request (MsgType.PING / 0x00) to verify link connectivity.
315
+
316
+ The ESP32 responds with a PONG packet upon receipt.
317
+ """
318
+ self.send(MsgType.PING)
319
+
320
+ def close(self) -> None:
321
+ """Close the active communication transport and release underlying resources."""
322
+ if self.transport is not None:
323
+ self.transport.close()
324
+ self.started = False
@@ -0,0 +1,134 @@
1
+ import struct
2
+
3
+ from loon_python_sdk.enums import MsgType
4
+
5
+ START_BYTE = 0x7E
6
+ MAX_PAYLOAD = 200
7
+
8
+ def checksum(data: bytes) -> int:
9
+ return sum(data) & 0xFF
10
+
11
+
12
+ def encode_frame(msg_type: int, payload: bytes = b"") -> bytes:
13
+ if len(payload) > MAX_PAYLOAD:
14
+ raise ValueError(f"payload too large ({len(payload)} > {MAX_PAYLOAD})")
15
+ body = bytes([msg_type & 0xFF, len(payload)]) + payload
16
+ return bytes([START_BYTE]) + body + bytes([checksum(body)])
17
+
18
+
19
+ def decode_frame(data: bytes):
20
+ if len(data) < 4:
21
+ raise ValueError(f"frame too short ({len(data)} bytes)")
22
+ if data[0] != START_BYTE:
23
+ raise ValueError(f"bad start byte: 0x{data[0]:02X}")
24
+ msg_type = data[1]
25
+ size = data[2]
26
+ if len(data) != 3 + size + 1:
27
+ raise ValueError(f"length mismatch: expected {3 + size + 1}, got {len(data)}")
28
+ payload = data[3:3 + size]
29
+ expected = checksum(data[1:3 + size])
30
+ actual = data[3 + size]
31
+ if expected != actual:
32
+ raise ValueError(f"checksum mismatch: expected 0x{expected:02X}, got 0x{actual:02X}")
33
+ return msg_type, payload
34
+
35
+
36
+ # ---- payload helpers (match include/comm.h struct layouts, little-endian) ----
37
+
38
+ def pack_pose(x, y, z, roll, pitch, yaw, grip):
39
+ return struct.pack("<7f", x, y, z, roll, pitch, yaw, grip)
40
+
41
+
42
+ def pack_joint_angles(base, shoulder, elbow, wrist, twist, claw):
43
+ return struct.pack("<7f", base, shoulder, elbow, wrist, twist, claw, 0.0) # trailing padding float
44
+
45
+
46
+ def pack_motor_enable(can_id, enabled):
47
+ return struct.pack("<BB", can_id, 1 if enabled else 0)
48
+
49
+
50
+ def pack_motor_zero(can_id):
51
+ return struct.pack("<B", can_id)
52
+
53
+
54
+ def pack_motor_pid(can_id, kp, ki, kd):
55
+ return struct.pack("<Bfff", can_id, kp, ki, kd)
56
+
57
+
58
+ def pack_motor_position(can_id, degrees):
59
+ return struct.pack("<Bf", can_id, degrees)
60
+
61
+
62
+ # Mirrors HomingConfig in include/comm.h: canId, direction, speed, mode, offset, current
63
+ # (packed, no padding). Note the firmware's ConfigHoming handler currently hardcodes the
64
+ # CAN-level "trig"/limitEnable fields to 0 -- those aren't exposed over this protocol yet.
65
+ def pack_homing_config(can_id, direction, speed, mode, offset, current):
66
+ return struct.pack("<BBHBIH", can_id, direction, speed, mode, offset, current)
67
+
68
+
69
+ def pack_homing_cmd(can_id):
70
+ return struct.pack("<B", can_id)
71
+
72
+
73
+ MOTOR_STATE_WIRE_FMT = "<BBB6fB"
74
+ MOTOR_STATE_WIRE_SIZE = struct.calcsize(MOTOR_STATE_WIRE_FMT) # 28 bytes (trailing `reversed` flag)
75
+ ACK_FMT = "<BB32s"
76
+ MOTOR_STATUS_NAMES = {0: "offline", 1: "online", 2: "error"}
77
+
78
+
79
+ def parse_motor_telemetry(payload: bytes) -> list:
80
+ """Decode a MOTOR_TELEMETRY payload into a list of dicts, one per motor.
81
+ Mirrors MotorStateWire in include/comm.h / parseMotorTelemetry in data/app.js."""
82
+ count = len(payload) // MOTOR_STATE_WIRE_SIZE
83
+ motors = []
84
+ for i in range(count):
85
+ chunk = payload[i * MOTOR_STATE_WIRE_SIZE:(i + 1) * MOTOR_STATE_WIRE_SIZE]
86
+ can_id, enabled, status, pos, target, speed, kp, ki, kd, reversed_ = struct.unpack(MOTOR_STATE_WIRE_FMT, chunk)
87
+ motors.append({
88
+ "can_id": can_id,
89
+ "enabled": bool(enabled),
90
+ "status": status,
91
+ "position_deg": pos,
92
+ "target_position_deg": target,
93
+ "speed_rpm": speed,
94
+ "kp": kp,
95
+ "ki": ki,
96
+ "kd": kd,
97
+ "reversed": bool(reversed_),
98
+ })
99
+ return motors
100
+
101
+
102
+ def describe_payload(msg_type: int, payload: bytes) -> str:
103
+ try:
104
+ t = MsgType(msg_type)
105
+ except ValueError:
106
+ return f"unknown type 0x{msg_type:02X}, {len(payload)} bytes: {payload.hex()}"
107
+
108
+ if t == MsgType.PONG:
109
+ return "PONG (heartbeat)"
110
+ if t == MsgType.ACK:
111
+ acked_type, success, message = struct.unpack(ACK_FMT, payload)
112
+ text = message.split(b"\x00", 1)[0].decode(errors="replace")
113
+ try:
114
+ acked_name = MsgType(acked_type).name
115
+ except ValueError:
116
+ acked_name = f"0x{acked_type:02X}"
117
+ status = "OK" if success else "FAIL"
118
+ return f"ACK[{acked_name}] {status}" + (f" ({text})" if text else "")
119
+ if t == MsgType.LOG:
120
+ return f"LOG: {payload.decode(errors='replace')}"
121
+ if t == MsgType.MOTOR_TELEMETRY:
122
+ lines = []
123
+ for m in parse_motor_telemetry(payload):
124
+ lines.append(
125
+ f" motor {m['can_id']}: {'enabled' if m['enabled'] else 'disabled'}, "
126
+ f"{MOTOR_STATUS_NAMES.get(m['status'], m['status'])}, "
127
+ f"pos={m['position_deg']:.2f} target={m['target_position_deg']:.2f} speed={m['speed_rpm']:.2f} "
128
+ f"pid=({m['kp']:.3f},{m['ki']:.3f},{m['kd']:.3f})"
129
+ f"{' REVERSED' if m['reversed'] else ''}"
130
+ )
131
+ return "MOTOR_TELEMETRY:\n" + "\n".join(lines)
132
+ return f"{t.name}, {len(payload)} bytes: {payload.hex()}"
133
+
134
+
@@ -0,0 +1,26 @@
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 ClientType(IntEnum):
25
+ WEBSOCKET = 0
26
+ SERIAL = 1
@@ -0,0 +1,198 @@
1
+ from abc import ABC, abstractmethod
2
+ import threading
3
+ from typing import Callable, Optional
4
+
5
+ try:
6
+ import websocket
7
+ except ImportError:
8
+ websocket = None
9
+
10
+ try:
11
+ import serial
12
+ except ImportError:
13
+ serial = None
14
+
15
+
16
+ class Transport(ABC):
17
+ """Abstract base class defining the communication transport interface."""
18
+
19
+ def __init__(self, on_frame_received: Callable[[bytes], None]):
20
+ """Initialize transport with an incoming frame callback.
21
+
22
+ Args:
23
+ on_frame_received: Callback function receiving raw packet bytes when a
24
+ valid frame arrives from the hardware.
25
+ """
26
+ self.on_frame_received = on_frame_received
27
+
28
+ @abstractmethod
29
+ def start(self, timeout: float = 10.0) -> None:
30
+ """Establish connection and launch background receive worker thread.
31
+
32
+ Args:
33
+ timeout: Maximum seconds to wait for connection.
34
+ """
35
+ pass
36
+
37
+ @abstractmethod
38
+ def send_bytes(self, data: bytes) -> None:
39
+ """Transmit raw framed bytes over the transport connection.
40
+
41
+ Args:
42
+ data: Raw binary frame to send.
43
+ """
44
+ pass
45
+
46
+ @abstractmethod
47
+ def close(self) -> None:
48
+ """Disconnect and stop background listener threads."""
49
+ pass
50
+
51
+
52
+ class WebSocketTransport(Transport):
53
+ """WebSocket transport client communicating with ESP32 over WiFi/TCP."""
54
+
55
+ def __init__(self, url: str, on_frame_received: Callable[[bytes], None]):
56
+ """Initialize WebSocket transport.
57
+
58
+ Args:
59
+ url: Full WebSocket URL (e.g. 'ws://192.168.4.1:80/ws').
60
+ on_frame_received: Callback invoked when a frame arrives.
61
+ """
62
+ super().__init__(on_frame_received)
63
+ if websocket is None:
64
+ raise ImportError(
65
+ "websocket-client is required for WebSocketTransport. "
66
+ "Run: pip install websocket-client"
67
+ )
68
+ self.url = url
69
+ self._connected = threading.Event()
70
+ self.ws = websocket.WebSocketApp(
71
+ url,
72
+ on_open=self._on_open,
73
+ on_message=self._on_message,
74
+ on_error=self._on_error,
75
+ on_close=self._on_close,
76
+ )
77
+ self._thread = threading.Thread(
78
+ target=self.ws.run_forever, daemon=True, name="WebSocketThread"
79
+ )
80
+
81
+ def start(self, timeout: float = 10.0) -> None:
82
+ """Launch background WebSocket thread and block until connected or timeout.
83
+
84
+ Args:
85
+ timeout: Maximum wait time in seconds for the connection handshake.
86
+ """
87
+ self._thread.start()
88
+ if not self._connected.wait(timeout=timeout):
89
+ raise RuntimeError(f"could not connect to {self.url}")
90
+
91
+ def _on_open(self, _ws) -> None:
92
+ """Internal callback invoked when WebSocket connection is opened."""
93
+ print(f"[connected] {self.url}")
94
+ self._connected.set()
95
+
96
+ def _on_message(self, _ws, message) -> None:
97
+ """Internal callback invoked when a WebSocket message is received."""
98
+ if isinstance(message, str):
99
+ message = message.encode()
100
+ self.on_frame_received(message)
101
+
102
+ def _on_error(self, _ws, error) -> None:
103
+ """Internal callback invoked on WebSocket errors."""
104
+ print(f"[error] {error}")
105
+
106
+ def _on_close(self, _ws, status_code, msg) -> None:
107
+ """Internal callback invoked when WebSocket closes."""
108
+ print(f"[closed] {status_code} {msg}")
109
+ self._connected.clear()
110
+
111
+ def send_bytes(self, data: bytes) -> None:
112
+ """Send raw binary frame over WebSocket as binary opcode."""
113
+ self.ws.send(data, opcode=websocket.ABNF.OPCODE_BINARY)
114
+
115
+ def close(self) -> None:
116
+ """Close WebSocket connection and terminate thread."""
117
+ self.ws.close()
118
+
119
+
120
+ class SerialTransport(Transport):
121
+ """Serial UART transport communicating with ESP32 over USB-to-UART or COM port."""
122
+
123
+ def __init__(
124
+ self,
125
+ port: str,
126
+ baudrate: int = 115200,
127
+ on_frame_received: Optional[Callable[[bytes], None]] = None,
128
+ ):
129
+ """Initialize Serial transport.
130
+
131
+ Args:
132
+ port: Serial device path (e.g. '/dev/ttyUSB0' or 'COM3').
133
+ baudrate: Baud rate in bits/second (default: 115200).
134
+ on_frame_received: Callback invoked when a complete frame is reassembled.
135
+ """
136
+ super().__init__(on_frame_received or (lambda _: None))
137
+ if serial is None:
138
+ raise ImportError(
139
+ "pyserial is required for SerialTransport. "
140
+ "Run: pip install pyserial"
141
+ )
142
+ self.port = port
143
+ self.baudrate = baudrate
144
+ self.ser: Optional[serial.Serial] = None
145
+ self._running = False
146
+ self._thread: Optional[threading.Thread] = None
147
+
148
+ def start(self, timeout: float = 10.0) -> None:
149
+ """Open the serial port and start the stream frame-parser thread.
150
+
151
+ Args:
152
+ timeout: Unused timeout compatibility parameter.
153
+ """
154
+ self.ser = serial.Serial(self.port, self.baudrate, timeout=1.0)
155
+ self._running = True
156
+ self._thread = threading.Thread(
157
+ target=self._read_loop, daemon=True, name="SerialThread"
158
+ )
159
+ self._thread.start()
160
+ print(f"[connected] Serial on {self.port} @ {self.baudrate} baud")
161
+
162
+ def _read_loop(self) -> None:
163
+ """Stream reader thread: synchronizes on 0x7E and extracts complete frames."""
164
+ while self._running and self.ser and self.ser.is_open:
165
+ try:
166
+ # 1. Sync on start byte (0x7E)
167
+ b = self.ser.read(1)
168
+ if not b or b[0] != 0x7E:
169
+ continue
170
+
171
+ # 2. Read msg_type (1B) and size (1B)
172
+ header = self.ser.read(2)
173
+ if len(header) < 2:
174
+ continue
175
+ size = header[1]
176
+
177
+ # 3. Read payload + checksum (size + 1 bytes)
178
+ rest = self.ser.read(size + 1)
179
+ if len(rest) < size + 1:
180
+ continue
181
+
182
+ frame = bytes([0x7E]) + header + rest
183
+ self.on_frame_received(frame)
184
+ except Exception as e:
185
+ if not self._running:
186
+ break
187
+ print(f"[serial error] {e}")
188
+
189
+ def send_bytes(self, data: bytes) -> None:
190
+ """Send raw binary frame over open serial port."""
191
+ if self.ser and self.ser.is_open:
192
+ self.ser.write(data)
193
+
194
+ def close(self) -> None:
195
+ """Signal read loop to terminate and close serial port."""
196
+ self._running = False
197
+ if self.ser and self.ser.is_open:
198
+ self.ser.close()
@@ -0,0 +1,321 @@
1
+ Metadata-Version: 2.4
2
+ Name: loon-python-sdk
3
+ Version: 0.0.1
4
+ Summary: Python SDK for the Loon Industries robotic arm
5
+ Author-email: Jake Horner <jakehorner@loon.industries>, Ryan Erickson <ryanerickson@loon.industries>
6
+ License: Apache License
7
+ Version 2.0, January 2004
8
+ http://www.apache.org/licenses/
9
+
10
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
11
+
12
+ 1. Definitions.
13
+
14
+ "License" shall mean the terms and conditions for use, reproduction,
15
+ and distribution as defined by Sections 1 through 9 of this document.
16
+
17
+ "Licensor" shall mean the copyright owner or entity authorized by
18
+ the copyright owner that is granting the License.
19
+
20
+ "Legal Entity" shall mean the union of the acting entity and all
21
+ other entities that control, are controlled by, or are under common
22
+ control with that entity. For the purposes of this definition,
23
+ "control" means (i) the power, direct or indirect, to cause the
24
+ direction or management of such entity, whether by contract or
25
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
26
+ outstanding shares, or (iii) beneficial ownership of such entity.
27
+
28
+ "You" (or "Your") shall mean an individual or Legal Entity
29
+ exercising permissions granted by this License.
30
+
31
+ "Source" form shall mean the preferred form for making modifications,
32
+ including but not limited to software source code, documentation
33
+ source, and configuration files.
34
+
35
+ "Object" form shall mean any form resulting from mechanical
36
+ transformation or translation of a Source form, including but
37
+ not limited to compiled object code, generated documentation,
38
+ and conversions to other media types.
39
+
40
+ "Work" shall mean the work of authorship, whether in Source or
41
+ Object form, made available under the License, as indicated by a
42
+ copyright notice that is included in or attached to the work
43
+ (an example is provided in the Appendix below).
44
+
45
+ "Derivative Works" shall mean any work, whether in Source or Object
46
+ form, that is based on (or derived from) the Work and for which the
47
+ editorial revisions, annotations, elaborations, or other modifications
48
+ represent, as a whole, an original work of authorship. For the purposes
49
+ of this License, Derivative Works shall not include works that remain
50
+ separable from, or merely link (or bind by name) to the interfaces of,
51
+ the Work and Derivative Works thereof.
52
+
53
+ "Contribution" shall mean any work of authorship, including
54
+ the original version of the Work and any modifications or additions
55
+ to that Work or Derivative Works thereof, that is intentionally
56
+ submitted to Licensor for inclusion in the Work by the copyright owner
57
+ or by an individual or Legal Entity authorized to submit on behalf of
58
+ the copyright owner. For the purposes of this definition, "submitted"
59
+ means any form of electronic, verbal, or written communication sent
60
+ to the Licensor or its representatives, including but not limited to
61
+ communication on electronic mailing lists, source code control systems,
62
+ and issue tracking systems that are managed by, or on behalf of, the
63
+ Licensor for the purpose of discussing and improving the Work, but
64
+ excluding communication that is conspicuously marked or otherwise
65
+ designated in writing by the copyright owner as "Not a Contribution."
66
+
67
+ "Contributor" shall mean Licensor and any individual or Legal Entity
68
+ on behalf of whom a Contribution has been received by Licensor and
69
+ subsequently incorporated within the Work.
70
+
71
+ 2. Grant of Copyright License. Subject to the terms and conditions of
72
+ this License, each Contributor hereby grants to You a perpetual,
73
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
74
+ copyright license to reproduce, prepare Derivative Works of,
75
+ publicly display, publicly perform, sublicense, and distribute the
76
+ Work and such Derivative Works in Source or Object form.
77
+
78
+ 3. Grant of Patent License. Subject to the terms and conditions of
79
+ this License, each Contributor hereby grants to You a perpetual,
80
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
81
+ (except as stated in this section) patent license to make, have made,
82
+ use, offer to sell, sell, import, and otherwise transfer the Work,
83
+ where such license applies only to those patent claims licensable
84
+ by such Contributor that are necessarily infringed by their
85
+ Contribution(s) alone or by combination of their Contribution(s)
86
+ with the Work to which such Contribution(s) was submitted. If You
87
+ institute patent litigation against any entity (including a
88
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
89
+ or a Contribution incorporated within the Work constitutes direct
90
+ or contributory patent infringement, then any patent licenses
91
+ granted to You under this License for that Work shall terminate
92
+ as of the date such litigation is filed.
93
+
94
+ 4. Redistribution. You may reproduce and distribute copies of the
95
+ Work or Derivative Works thereof in any medium, with or without
96
+ modifications, and in Source or Object form, provided that You
97
+ meet the following conditions:
98
+
99
+ (a) You must give any other recipients of the Work or
100
+ Derivative Works a copy of this License; and
101
+
102
+ (b) You must cause any modified files to carry prominent notices
103
+ stating that You changed the files; and
104
+
105
+ (c) You must retain, in the Source form of any Derivative Works
106
+ that You distribute, all copyright, patent, trademark, and
107
+ attribution notices from the Source form of the Work,
108
+ excluding those notices that do not pertain to any part of
109
+ the Derivative Works; and
110
+
111
+ (d) If the Work includes a "NOTICE" text file as part of its
112
+ distribution, then any Derivative Works that You distribute must
113
+ include a readable copy of the attribution notices contained
114
+ within such NOTICE file, excluding those notices that do not
115
+ pertain to any part of the Derivative Works, in at least one
116
+ of the following places: within a NOTICE text file distributed
117
+ as part of the Derivative Works; within the Source form or
118
+ documentation, if provided along with the Derivative Works; or,
119
+ within a display generated by the Derivative Works, if and
120
+ wherever such third-party notices normally appear. The contents
121
+ of the NOTICE file are for informational purposes only and
122
+ do not modify the License. You may add Your own attribution
123
+ notices within Derivative Works that You distribute, alongside
124
+ or as an addendum to the NOTICE text from the Work, provided
125
+ that such additional attribution notices cannot be construed
126
+ as modifying the License.
127
+
128
+ You may add Your own copyright statement to Your modifications and
129
+ may provide additional or different license terms and conditions
130
+ for use, reproduction, or distribution of Your modifications, or
131
+ for any such Derivative Works as a whole, provided Your use,
132
+ reproduction, and distribution of the Work otherwise complies with
133
+ the conditions stated in this License.
134
+
135
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
136
+ any Contribution intentionally submitted for inclusion in the Work
137
+ by You to the Licensor shall be under the terms and conditions of
138
+ this License, without any additional terms or conditions.
139
+ Notwithstanding the above, nothing herein shall supersede or modify
140
+ the terms of any separate license agreement you may have executed
141
+ with Licensor regarding such Contributions.
142
+
143
+ 6. Trademarks. This License does not grant permission to use the trade
144
+ names, trademarks, service marks, or product names of the Licensor,
145
+ except as required for reasonable and customary use in describing the
146
+ origin of the Work and reproducing the content of the NOTICE file.
147
+
148
+ 7. Disclaimer of Warranty. Unless required by applicable law or
149
+ agreed to in writing, Licensor provides the Work (and each
150
+ Contributor provides its Contributions) on an "AS IS" BASIS,
151
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
152
+ implied, including, without limitation, any warranties or conditions
153
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
154
+ PARTICULAR PURPOSE. You are solely responsible for determining the
155
+ appropriateness of using or redistributing the Work and assume any
156
+ risks associated with Your exercise of permissions under this License.
157
+
158
+ 8. Limitation of Liability. In no event and under no legal theory,
159
+ whether in tort (including negligence), contract, or otherwise,
160
+ unless required by applicable law (such as deliberate and grossly
161
+ negligent acts) or agreed to in writing, shall any Contributor be
162
+ liable to You for damages, including any direct, indirect, special,
163
+ incidental, or consequential damages of any character arising as a
164
+ result of this License or out of the use or inability to use the
165
+ Work (including but not limited to damages for loss of goodwill,
166
+ work stoppage, computer failure or malfunction, or any and all
167
+ other commercial damages or losses), even if such Contributor
168
+ has been advised of the possibility of such damages.
169
+
170
+ 9. Accepting Warranty or Additional Liability. While redistributing
171
+ the Work or Derivative Works thereof, You may choose to offer,
172
+ and charge a fee for, acceptance of support, warranty, indemnity,
173
+ or other liability obligations and/or rights consistent with this
174
+ License. However, in accepting such obligations, You may act only
175
+ on Your own behalf and on Your sole responsibility, not on behalf
176
+ of any other Contributor, and only if You agree to indemnify,
177
+ defend, and hold each Contributor harmless for any liability
178
+ incurred by, or claims asserted against, such Contributor by reason
179
+ of your accepting any such warranty or additional liability.
180
+
181
+ END OF TERMS AND CONDITIONS
182
+
183
+ APPENDIX: How to apply the Apache License to your work.
184
+
185
+ To apply the Apache License to your work, attach the following
186
+ boilerplate notice, with the fields enclosed by brackets "[]"
187
+ replaced with your own identifying information. (Don't include
188
+ the brackets!) The text should be enclosed in the appropriate
189
+ comment syntax for the file format. We also recommend that a
190
+ file or class name and description of purpose be included on the
191
+ same "printed page" as the copyright notice for easier
192
+ identification within third-party archives.
193
+
194
+ Copyright [yyyy] [name of copyright owner]
195
+
196
+ Licensed under the Apache License, Version 2.0 (the "License");
197
+ you may not use this file except in compliance with the License.
198
+ You may obtain a copy of the License at
199
+
200
+ http://www.apache.org/licenses/LICENSE-2.0
201
+
202
+ Unless required by applicable law or agreed to in writing, software
203
+ distributed under the License is distributed on an "AS IS" BASIS,
204
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
205
+ See the License for the specific language governing permissions and
206
+ limitations under the License.
207
+
208
+ Project-URL: Homepage, https://github.com/LoonIndustries/loon_python_sdk
209
+ Project-URL: Repository, https://github.com/LoonIndustries/loon_python_sdk
210
+ Classifier: Development Status :: 3 - Alpha
211
+ Classifier: Intended Audience :: Developers
212
+ Classifier: Intended Audience :: Science/Research
213
+ Classifier: License :: OSI Approved :: Apache Software License
214
+ Classifier: Operating System :: OS Independent
215
+ Classifier: Programming Language :: Python :: 3
216
+ Classifier: Programming Language :: Python :: 3.8
217
+ Classifier: Programming Language :: Python :: 3.9
218
+ Classifier: Programming Language :: Python :: 3.10
219
+ Classifier: Programming Language :: Python :: 3.11
220
+ Classifier: Programming Language :: Python :: 3.12
221
+ Classifier: Programming Language :: Python :: 3.13
222
+ Classifier: Topic :: Scientific/Engineering
223
+ Requires-Python: >=3.8
224
+ Description-Content-Type: text/markdown
225
+ License-File: LICENSE
226
+ Requires-Dist: websocket-client>=1.6.0
227
+ Requires-Dist: pyserial>=3.5
228
+ Dynamic: license-file
229
+
230
+ # Loon Python SDK
231
+
232
+ Official Python SDK for communicating with and controlling the **Loon Industries robotic arm**.
233
+
234
+ Python APIs for both **WebSocket (WiFi)** and **Serial (USB)** communication, supporting direct joint angle commands, Cartesian pose control (Inverse Kinematics), motor homing, PID gain configuration, and real-time telemetry streaming.
235
+
236
+ ---
237
+
238
+ ## Features
239
+
240
+ - **Dual Transports**: Seamlessly switch between WiFi WebSocket (`ws://...`) and USB Serial (`/dev/ttyUSB0` or `COM3`).
241
+ - **Joint & IK Control**: Command direct joint angles or stream Cartesian end-effector coordinates solved by the on-board IK engine.
242
+ - **Real-Time Telemetry**: Automatically parses and tracks angles, target positions, RPM speeds, and CAN bus states.
243
+ ---
244
+
245
+ ## Installation
246
+
247
+ ```bash
248
+ pip install loon-python-sdk
249
+ ```
250
+
251
+ Or install locally in editable mode:
252
+
253
+ ```bash
254
+ git clone https://github.com/LoonIndustries/loon_python_sdk.git
255
+ cd loon_python_sdk
256
+ pip install -e .
257
+ ```
258
+
259
+ ---
260
+
261
+ ## Quickstart
262
+
263
+ ### 1. Control Over WiFi (WebSocket)
264
+
265
+ ```python
266
+ from loonpythonsdk import Client
267
+
268
+ # Connect to the ESP32 access point (default: 192.168.4.1)
269
+ client = Client.from_websocket("ws://192.168.4.1:80/ws")
270
+ client.start()
271
+
272
+ # 1. Command all 6 joint angles directly (degrees)
273
+ # (base, shoulder, elbow, wrist, twist, claw)
274
+ client.set_joint_angles(base=0.0, shoulder=20.0, elbow=45.0, wrist=-15.0, twist=0.0, claw=50.0)
275
+
276
+ # 2. Command an individual motor angle
277
+ client.set_angle(can_id=6, degrees=70.0) # Open claw
278
+
279
+ # 3. Disconnect
280
+ client.close()
281
+ ```
282
+
283
+ ### 2. Control Over USB (Serial)
284
+
285
+ ```python
286
+ from loonpythonsdk import Client
287
+
288
+ # Connect via USB serial
289
+ client = Client.from_serial("/dev/ttyUSB0", baudrate=115200)
290
+ client.start()
291
+
292
+ # Home arm motors 2, 3, and 4 in sequence
293
+ client.home_arm()
294
+
295
+ client.close()
296
+ ```
297
+
298
+ ### 3. Cartesian Pose Control (Inverse Kinematics)
299
+
300
+ ```python
301
+ # Command end-effector pose (x, y, z, roll, pitch, yaw, grip)
302
+ # The ESP32's on-board IK solver computes target joint angles automatically
303
+ client.set_pose(x=200.0, y=0.0, z=150.0, roll=0.0, pitch=15.0, yaw=0.0, grip=30.0)
304
+ ```
305
+
306
+ ### 4. Listening to Real-Time Telemetry
307
+
308
+ ```python
309
+ def on_telemetry(motors):
310
+ for m in motors:
311
+ print(f"Motor {m['can_id']}: pos={m['position_deg']:.1f}°, speed={m['speed_rpm']} RPM")
312
+
313
+ client = Client.from_websocket("ws://192.168.4.1:80/ws", on_telemetry=on_telemetry)
314
+ client.start()
315
+ ```
316
+
317
+ ---
318
+
319
+ ## License
320
+
321
+ This project is licensed under the [Apache-2.0 License](LICENSE).
@@ -0,0 +1,10 @@
1
+ loon_python_sdk/__init__.py,sha256=Vomvd07EqUj9a8xFSateSLONMwmwDz_fFC0nUrohHLU,375
2
+ loon_python_sdk/client.py,sha256=YmY4Ujq1LChOGdtm_A3gBZF7hPGuphVG-iOcZzLTEu0,12255
3
+ loon_python_sdk/comms.py,sha256=fuq05aZUuZD6ONPOLG8SYSMtR8lcNY7xj3VsSL0ecEk,4839
4
+ loon_python_sdk/enums.py,sha256=0GupVR-gqLp8d3ECy0G7LvaG3XzP50iQ2B3xK5IgyF4,526
5
+ loon_python_sdk/transport.py,sha256=OlgcqVN-b4bNRBYlTtyoq8v9CnhqYNg8iuKNxzeMk84,6695
6
+ loon_python_sdk-0.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
7
+ loon_python_sdk-0.0.1.dist-info/METADATA,sha256=3XB2C2wBD3SYEVvFnjXvhoT4lq7xN2SHLmSHVcZESYs,16604
8
+ loon_python_sdk-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
9
+ loon_python_sdk-0.0.1.dist-info/top_level.txt,sha256=EIbERb1juDmoqdY15q8Vg434YHz6TyUggeK1ZjsbYfM,16
10
+ loon_python_sdk-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1 @@
1
+ loon_python_sdk