palmimo-sdk 0.1.0__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,148 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Jizai Inc.
3
+ """palmimo_sdk — the single window into the Palmimo software stack.
4
+
5
+ Users import the facade :class:`Palmimo` and (when driving hardware) attach a
6
+ :class:`ServoDriver`; everything else (gait/IK computation, servo I/O) lives
7
+ behind them.
8
+
9
+ from palmimo_sdk import Palmimo
10
+
11
+ robot = Palmimo() # compute-only (sim / tests)
12
+ robot.forward()
13
+ for _ in range(100):
14
+ pos = robot.step() # dict like {"leg_1_yaw": 2048, ...}
15
+
16
+ To drive hardware, attach a concrete :class:`ServoDriver` and use the ``with``
17
+ protocol (connect / neutral-return / disconnect). :class:`DynamixelDriver` is
18
+ the bundled hardware backend (Dynamixel serial bus); it needs the optional
19
+ ``palmimo-sdk[hardware]`` extra. With no driver attached the facade is
20
+ compute-only, and any :class:`ServoDriver` (e.g. the in-memory fake used in the
21
+ tests) can be injected by the caller.
22
+
23
+ Peripherals hang off the same facade: :class:`FaceDisplay`, :class:`Speaker`,
24
+ :class:`HeadCamera`, and :class:`Microphone` (or :class:`MicStream`, for a
25
+ shared streaming mic) are attached as
26
+ ``Palmimo(display=..., speaker=..., camera=..., mic=...)`` and share the driver's
27
+ connect/disconnect lifecycle. Their ``*Config`` companions are exported
28
+ alongside them.
29
+
30
+ :class:`MicStream` and :class:`Microphone` push captured audio through a
31
+ ``processors`` chain of :class:`AudioProcessor` (a WAV-bytes-in/WAV-bytes-out
32
+ ``Protocol``) before handing it to consumers; :class:`EchoCanceller` (DTLN-AEC)
33
+ is :class:`MicStream`'s default, cancelling a loudspeaker's echo out of a
34
+ microphone channel given a reference channel from the same read. :class:`Denoiser`
35
+ is the bundled GTCRN-based noise-removal implementation for a continuous
36
+ stream — the fallback when the capture device lacks the extra channel
37
+ ``EchoCanceller`` needs — and :class:`ClipDenoiser` is its offline counterpart
38
+ for a complete, self-contained clip (e.g. :class:`Microphone`'s recordings).
39
+
40
+ :class:`Speaker` delegates synthesis to a pluggable :class:`TtsEngine`
41
+ (:class:`PiperEngine`, over ``piper-plus``, is its default); pass a different
42
+ :class:`TtsEngine` to ``Speaker(engine=...)`` to swap backends —
43
+ :class:`OpenAiEngine` is the other one built in.
44
+ :class:`TtsVoice` is the per-utterance handle an engine's ``load_voice``
45
+ returns.
46
+
47
+ :func:`find_servo_port` auto-detects the servo bus's serial port (its
48
+ USB-to-servo bridge) without hard-coding platform-specific paths;
49
+ :class:`PortDetectionError` is raised when detection fails.
50
+ :class:`DynamixelDriver` runs the same detection itself when built with
51
+ ``port=None`` (the default).
52
+ """
53
+
54
+ from . import kinematics
55
+ from .audio import AudioProcessor, ClipDenoiser, Denoiser, EchoCanceller
56
+ from .engine import Motion, MotionEngine
57
+ from .io import (
58
+ SAFE_MAX_TICK,
59
+ SAFE_MIN_TICK,
60
+ SUPPORTED_MOTOR_MODELS,
61
+ DynamixelConnectTimeoutError,
62
+ DynamixelDriver,
63
+ FaceDisplay,
64
+ FaceDisplayConnectTimeoutError,
65
+ FaceDisplayError,
66
+ HeadCamera,
67
+ HeadCameraConfig,
68
+ Microphone,
69
+ MicrophoneConfig,
70
+ MicStream,
71
+ OpenAiEngine,
72
+ PiperEngine,
73
+ PortDetectionError,
74
+ ServoDriver,
75
+ ServoTelemetry,
76
+ Speaker,
77
+ SpeakerConfig,
78
+ SpeechHandle,
79
+ Subscription,
80
+ TtsEngine,
81
+ TtsVoice,
82
+ find_face_port,
83
+ find_servo_port,
84
+ palmimo_motor_ids,
85
+ resolve_alsa_device,
86
+ )
87
+ from .name_match import PALMIMO_NAMES, NameMatch, NameMatcher, name_skeleton
88
+ from .robot import (
89
+ MotionCancelled,
90
+ NeckPitchDegrees,
91
+ NeckPitchNormalized,
92
+ NeckYawDegrees,
93
+ NeckYawNormalized,
94
+ Palmimo,
95
+ RoutineStep,
96
+ )
97
+ from .thermal import NeckThermalState
98
+
99
+
100
+ __all__ = [
101
+ "PALMIMO_NAMES",
102
+ "SAFE_MAX_TICK",
103
+ "SAFE_MIN_TICK",
104
+ "SUPPORTED_MOTOR_MODELS",
105
+ "AudioProcessor",
106
+ "ClipDenoiser",
107
+ "Denoiser",
108
+ "DynamixelConnectTimeoutError",
109
+ "DynamixelDriver",
110
+ "EchoCanceller",
111
+ "FaceDisplay",
112
+ "FaceDisplayConnectTimeoutError",
113
+ "FaceDisplayError",
114
+ "HeadCamera",
115
+ "HeadCameraConfig",
116
+ "MicStream",
117
+ "Microphone",
118
+ "MicrophoneConfig",
119
+ "Motion",
120
+ "MotionCancelled",
121
+ "MotionEngine",
122
+ "NameMatch",
123
+ "NameMatcher",
124
+ "NeckPitchDegrees",
125
+ "NeckPitchNormalized",
126
+ "NeckThermalState",
127
+ "NeckYawDegrees",
128
+ "NeckYawNormalized",
129
+ "OpenAiEngine",
130
+ "Palmimo",
131
+ "PiperEngine",
132
+ "PortDetectionError",
133
+ "RoutineStep",
134
+ "ServoDriver",
135
+ "ServoTelemetry",
136
+ "Speaker",
137
+ "SpeakerConfig",
138
+ "SpeechHandle",
139
+ "Subscription",
140
+ "TtsEngine",
141
+ "TtsVoice",
142
+ "find_face_port",
143
+ "find_servo_port",
144
+ "kinematics",
145
+ "name_skeleton",
146
+ "palmimo_motor_ids",
147
+ "resolve_alsa_device",
148
+ ]
@@ -0,0 +1,71 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Jizai Inc.
3
+ """Signal-suppression helper shared by the shutdown-ramp guards.
4
+
5
+ :func:`signals_ignored` is the one mechanism behind both
6
+ :func:`~palmimo_sdk.robot._deferred_interrupts` (SIGINT only, guarding
7
+ :meth:`~palmimo_sdk.robot.Palmimo.disconnect`'s park) and
8
+ :func:`~palmimo_sdk.mcp.__main__._shutdown_signals_ignored` (the wider
9
+ termination-signal set an MCP server's shutdown needs). Consolidated here so
10
+ the two callers share one tested implementation instead of drifting.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import contextlib
16
+ import signal
17
+ import threading
18
+ from typing import TYPE_CHECKING, Any
19
+
20
+
21
+ if TYPE_CHECKING:
22
+ from collections.abc import Iterator
23
+
24
+
25
+ @contextlib.contextmanager
26
+ def signals_ignored(*signals: signal.Signals) -> Iterator[None]:
27
+ """Make each of *signals* a no-op (``SIG_IGN``) for the duration of the block.
28
+
29
+ ``SIG_IGN`` rather than :func:`signal.pthread_sigmask`: a blocked signal
30
+ stays pending and fires the moment it is unblocked, which would just move
31
+ a mashed signal to right after the block; an ignored one is discarded
32
+ outright, and unlike a Python-level no-op handler it never reaches the C
33
+ trampoline, so an asyncio app using ``loop.add_signal_handler`` does not
34
+ get a callback during the block either. A caller that genuinely must
35
+ interrupt the block still has SIGKILL — which this cannot (and should
36
+ not) intercept.
37
+
38
+ A no-op off the main thread, where Python never delivers signals to begin
39
+ with, and when :func:`signal.signal` refuses installation (``ValueError``,
40
+ e.g. an interpreter that restricts handler changes): any of *signals*
41
+ already switched to ``SIG_IGN`` for this call is restored first, so a
42
+ partial failure never leaves some signals ignored and others not.
43
+ """
44
+ if threading.current_thread() is not threading.main_thread():
45
+ yield
46
+ return
47
+ previous: dict[signal.Signals, Any] = {}
48
+
49
+ def restore() -> None:
50
+ for sig, handler in previous.items():
51
+ # None means the handler it replaced came from outside Python;
52
+ # signal.signal() will not take None back, so the default is the
53
+ # closest restoration available.
54
+ signal.signal(sig, signal.SIG_DFL if handler is None else handler)
55
+
56
+ installed = True
57
+ try:
58
+ for sig in signals:
59
+ previous[sig] = signal.signal(sig, signal.SIG_IGN)
60
+ except ValueError:
61
+ installed = False
62
+ # Both yields sit outside the except clause: one inside it would attach the
63
+ # ValueError as the __context__ of anything the block raises.
64
+ if not installed:
65
+ restore()
66
+ yield
67
+ return
68
+ try:
69
+ yield
70
+ finally:
71
+ restore()
@@ -0,0 +1,33 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Jizai Inc.
3
+ """LLM tool-calling layer for Palmimo.
4
+
5
+ Wraps the synchronous, blocking :class:`~palmimo_sdk.robot.Palmimo` facade as
6
+ a set of pydantic-validated, LLM-callable tools (:class:`Tool` /
7
+ :class:`ToolResult`, defined in :mod:`palmimo_sdk.agent.tools`) plus a
8
+ registry/dispatcher (:class:`AgentToolSet`, in
9
+ :mod:`palmimo_sdk.agent.toolset`) that renders LLM-ready tool schemas and
10
+ turns a provider's tool-call back into a facade call::
11
+
12
+ from palmimo_sdk import Palmimo
13
+ from palmimo_sdk.agent import AgentToolSet
14
+
15
+ robot = Palmimo()
16
+ tools = AgentToolSet(robot)
17
+ llm_tools = tools.to_openai_tools()
18
+ result = await tools.call("forward", {"seconds": 1.5})
19
+ print(result.text)
20
+
21
+ This subpackage is the only part of palmimo_sdk that imports pydantic --
22
+ ``import palmimo_sdk`` itself stays dependency-free (see the top-level
23
+ package docstring). Install the ``palmimo-sdk[agent]`` extra to use it.
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ from .receiver import PalmimoLike
29
+ from .tools import Tool, ToolResult
30
+ from .toolset import AgentToolSet
31
+
32
+
33
+ __all__ = ["AgentToolSet", "PalmimoLike", "Tool", "ToolResult"]
@@ -0,0 +1,175 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 Jizai Inc.
3
+ """PalmimoLike — the structural surface of :class:`~palmimo_sdk.robot.Palmimo`
4
+ that this agent layer (:mod:`palmimo_sdk.agent.tools` /
5
+ :mod:`palmimo_sdk.agent.toolset`) actually depends on.
6
+
7
+ A :class:`~typing.Protocol`, not the concrete facade, so a duck-typed test
8
+ double (a ``FakeRobot`` recording calls, never touching hardware) satisfies
9
+ the type checker exactly to the extent it implements what is used -- no
10
+ subclassing the real facade's connection lifecycle, no ``cast(Palmimo, ...)``
11
+ at every call site. Enumerated by walking every ``robot.<member>`` access in
12
+ ``tools.py`` and ``toolset.py``; the real ``Palmimo`` satisfies it too (see
13
+ ``test_agent_receiver.py`` for the static assertion). :class:`Tool.execute`
14
+ and :class:`~palmimo_sdk.agent.toolset.AgentToolSet`'s constructor are typed
15
+ against this Protocol instead of the concrete facade.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from typing import Any, Protocol, runtime_checkable
21
+
22
+ from palmimo_sdk.robot import NeckPitchDegrees, NeckPitchNormalized, NeckYawDegrees, NeckYawNormalized
23
+ from palmimo_sdk.thermal import NeckThermalState
24
+
25
+
26
+ @runtime_checkable
27
+ class _SpeechHandleLike(Protocol):
28
+ """Structural surface of :class:`~palmimo_sdk.io.speaker.SpeechHandle` that :meth:`PalmimoLike.say`'s
29
+ caller depends on: :meth:`~palmimo_sdk.agent.tools.Tool.execute` joins it (bounded) and polls
30
+ ``is_alive()``; a failure is read back via ``getattr(handle, "error", None)`` rather than a typed
31
+ attribute, so it is deliberately not part of this Protocol.
32
+ """
33
+
34
+ def join(self, timeout: float | None = None) -> None: ...
35
+
36
+ def is_alive(self) -> bool: ...
37
+
38
+
39
+ @runtime_checkable
40
+ class _CameraLike(Protocol):
41
+ """Structural surface of :class:`~palmimo_sdk.io.camera.HeadCamera` that :class:`~palmimo_sdk.agent.tools.CaptureTool`
42
+ (``read``) and a custom face-tracking ``Tool`` such as ``examples/agents/companion``'s (``latest``,
43
+ the background-drain reader) depend on.
44
+ """
45
+
46
+ def read(self) -> tuple[bool, Any]: ...
47
+
48
+ def latest(self, *, timeout: float = 2.0) -> Any | None: ...
49
+
50
+
51
+ @runtime_checkable
52
+ class PalmimoLike(Protocol):
53
+ """Structural surface of :class:`~palmimo_sdk.robot.Palmimo` the agent layer depends on (see module docstring).
54
+
55
+ Movement/gesture setters, ``run``/``stop``/``cancel``, neck
56
+ ``look``/``look_center``, ``set_expression``/``say``/``stop_speech``, the
57
+ ``display``/``camera`` peripherals, ``cancel_checkpoint``/
58
+ ``raise_if_cancelled`` (a custom ``Tool.execute()``'s own cooperative
59
+ loop -- see e.g. ``examples/agents/companion``'s face-tracking tool), and
60
+ the cancel-scope arm/disarm pair :meth:`~palmimo_sdk.agent.toolset.AgentToolSet.call`
61
+ wraps every dispatch in. Precedent: :class:`palmimo_wakeword_agent.wiring._ServoDriverLike`.
62
+ """
63
+
64
+ # ----------------------------------------------------------------
65
+ # Peripheral properties -- only ever compared to ``None`` or (camera)
66
+ # read from, never assigned, so a read-only property is enough.
67
+ # ----------------------------------------------------------------
68
+ @property
69
+ def display(self) -> object | None: ...
70
+
71
+ @property
72
+ def camera(self) -> _CameraLike | None: ...
73
+
74
+ # ----------------------------------------------------------------
75
+ # Movement / gesture setters -- each just switches the engine's target
76
+ # motion; the real signatures take no arguments and return nothing.
77
+ # ----------------------------------------------------------------
78
+ def forward(self) -> None: ...
79
+
80
+ def backward(self) -> None: ...
81
+
82
+ def strafe_left(self) -> None: ...
83
+
84
+ def strafe_right(self) -> None: ...
85
+
86
+ def rotate_left(self) -> None: ...
87
+
88
+ def rotate_right(self) -> None: ...
89
+
90
+ def creep(self) -> None: ...
91
+
92
+ def dance(self) -> None: ...
93
+
94
+ def body_tilt(self) -> None: ...
95
+
96
+ def pushup(self) -> None: ...
97
+
98
+ def wave(self) -> None: ...
99
+
100
+ def wave_both(self) -> None: ...
101
+
102
+ def clap(self) -> None: ...
103
+
104
+ def bow(self) -> None: ...
105
+
106
+ def stretch(self) -> None: ...
107
+
108
+ def nod(self) -> bool: ...
109
+
110
+ def head_shake(self) -> bool: ...
111
+
112
+ # ----------------------------------------------------------------
113
+ # Run / stop / cancel
114
+ # ----------------------------------------------------------------
115
+ def run(self, *, seconds: float | None = None, steps: int | None = None) -> object:
116
+ """Paced-run the current motion. Return value is never read by the agent layer -- ``object``
117
+ covers both the real facade's ``dict[str, int]`` and a test double's ``None``.
118
+ """
119
+ ...
120
+
121
+ def stop(self) -> None: ...
122
+
123
+ def cancel(self) -> None: ...
124
+
125
+ # ----------------------------------------------------------------
126
+ # Sleep / wake -- a pose-and-stiffness pair, not a motion. Peripherals
127
+ # stay open through both, so a sleeping robot can still be spoken to.
128
+ # ----------------------------------------------------------------
129
+ def sleep(self, duration: float = 1.5, end_gain: int = 300) -> None: ...
130
+
131
+ def wake(self, duration: float = 1.5, start_gain: int = 300) -> None: ...
132
+
133
+ def cancel_checkpoint(self) -> int: ...
134
+
135
+ def raise_if_cancelled(self, checkpoint: int) -> None: ...
136
+
137
+ # ----------------------------------------------------------------
138
+ # Neck
139
+ # ----------------------------------------------------------------
140
+ def look(
141
+ self,
142
+ pitch: float | NeckPitchDegrees | NeckPitchNormalized = 0.0,
143
+ yaw: float | NeckYawDegrees | NeckYawNormalized = 0.0,
144
+ ) -> bool: ...
145
+
146
+ def look_center(self) -> None: ...
147
+
148
+ @property
149
+ def neck_thermal_state(self) -> NeckThermalState: ...
150
+
151
+ @property
152
+ def neck_lock_active(self) -> bool: ...
153
+
154
+ @property
155
+ def neck_temperature_c(self) -> float | None: ...
156
+
157
+ # ----------------------------------------------------------------
158
+ # Face / voice
159
+ # ----------------------------------------------------------------
160
+ def set_expression(self, name: str, hold_ms: int = 0) -> str | None: ...
161
+
162
+ def say(self, text: str, lang: str | None = None) -> _SpeechHandleLike | None: ...
163
+
164
+ def stop_speech(self) -> None: ...
165
+
166
+ # ----------------------------------------------------------------
167
+ # Cancellation-scope bracketing -- AgentToolSet.call() arms this around
168
+ # every dispatch so a cancel() delivered between validation and the
169
+ # worker thread's paced entry is not silently absorbed. Private on the
170
+ # real facade (leading underscore) but part of this Protocol because the
171
+ # toolset genuinely calls it -- see toolset.py's docstring.
172
+ # ----------------------------------------------------------------
173
+ def _arm_cancel_scope(self) -> None: ...
174
+
175
+ def _disarm_cancel_scope(self) -> None: ...