Python client library for NAO Bridge HTTP API
Project description
NAO Bridge Client
This directory contains a Python 3 client for the NAO Bridge HTTP API.
Installation
- Install the client package
pip install nao-bridge-client
Quick Start
from nao_bridge_client import NAOBridgeClient
# Create client instance
client = NAOBridgeClient("http://localhost:3000")
# Get robot status
status = client.get_status()
print(f"Robot connected: {status.data.robot_connected}")
# Enable stiffness and stand up
client.enable_stiffness()
client.stand()
# Make robot speak
client.say("Hello, I am a NAO robot!")
# Control LEDs
client.set_leds(leds={"eyes": "blue"})
# Sit down and disable stiffness
client.sit()
client.disable_stiffness()
# Close the client
client.close()
Using Context Manager
The client supports context manager usage for automatic cleanup:
with NAOBridgeClient("http://localhost:3000") as client:
status = client.get_status()
print(f"Robot connected: {status.data.robot_connected}")
# Client automatically closed when exiting the context
Error Handling
The client provides proper error handling with custom exceptions:
from nao_bridge_client import NAOBridgeClient, NAOBridgeError
client = NAOBridgeClient("http://localhost:3000")
try:
status = client.get_status()
print("Success!")
except NAOBridgeError as e:
print(f"API Error: {e.message}")
print(f"Error Code: {e.code}")
if e.details:
print(f"Details: {e.details}")
except Exception as e:
print(f"Unexpected error: {e}")
Available Methods
Status and Information
get_status()- Get robot and API statusget_operations()- List active operationsget_operation(operation_id)- Get status of specific operation
Robot Control
enable_stiffness(duration=None)- Enable robot stiffnessdisable_stiffness()- Disable robot stiffnessput_in_rest()- Put robot in rest modewake_up()- Wake up robot from rest modeset_autonomous_life_state(state)- Set autonomous life state
Posture Control
stand(speed=None, variant=None)- Move to standing positionsit(speed=None, variant=None)- Move to sitting positioncrouch(speed=None)- Move to crouching positionlie(speed=None, position=None)- Move to lying position
Movement Control
move_arms_preset(position=None, duration=None, arms=None, offset=None)- Control armscontrol_hands(left_hand=None, right_hand=None, duration=None)- Control handsmove_head(yaw=None, pitch=None, duration=None)- Control head positioning
Speech and LEDs
say(text, blocking=None, animated=None)- Make robot speakset_leds(leds=None, duration=None)- Control LED colorsturn_off_leds()- Turn off all LEDs
Walking
start_walking(x=None, y=None, theta=None, speed=None)- Start walkingstop_walking()- Stop walkingwalk_preset(action=None, duration=None, speed=None)- Preset walking patterns
Sensors
get_sonar()- Get sonar sensor readingsget_joint_angles(chain)- Get joint angles for chainget_joint_names(chain)- Get joint names for a specified chain
Vision and Camera
get_camera_image_json(camera, resolution)- Get camera image as JSON with base64 dataget_camera_image_bytes(camera, resolution)- Get camera image as raw JPEG bytesget_camera_resolutions()- Get available camera resolutions
Animations
execute_animation(animation, parameters=None)- Execute predefined animationsget_animations()- Get list of available animationsexecute_sequence(sequence, blocking=None)- Execute movement sequences
Behaviors
execute_behaviour(behaviour, blocking=None)- Execute a behavior on the robotget_behaviours(behaviour_type)- Get list of behaviours by typeset_behaviour_default(behaviour, default=True)- Set a behaviour as default
Configuration
set_duration(duration)- Set global movement duration
Async Usage
The client also supports async operations:
import asyncio
from nao_bridge_client import NAOBridgeClient
async def main():
async with NAOBridgeClient("http://localhost:3000") as client:
# Get status asynchronously
status = await client.async_get_status()
print(f"Robot connected: {status.data.robot_connected}")
# Make robot speak asynchronously
await client.async_say("Hello from async!")
# Start walking asynchronously
await client.async_start_walking(x=0.1, speed=0.5)
# Get sensor data asynchronously
sonar = await client.async_get_sonar()
print(f"Sonar left: {sonar.data.left}, right: {sonar.data.right}")
# Run the async function
asyncio.run(main())
Available Async Methods
async_get_status()- Get robot status (async)async_say(text, blocking=None, animated=None)- Make robot speak (async)async_start_walking(x=None, y=None, theta=None, speed=None)- Start walking (async)async_stop_walking()- Stop walking (async)async_move_head(yaw=None, pitch=None, duration=None)- Move robot head (async)async_get_sonar()- Get sonar readings (async)async_get_joint_angles(chain)- Get joint angles for chain (async)async_get_camera_image_json(camera, resolution)- Get camera image as JSON (async)
Data Models
The client uses Pydantic models for type-safe request and response handling:
Core Data Models
StatusData- Robot status informationSonarData- Sonar sensor readingsVisionData- Camera image metadataJointAnglesData- Joint angle information
Response Models
BaseResponse- Base response structureStatusResponse- Robot status informationSuccessResponse- Successful operation responsesSonarResponse- Sonar sensor dataVisionResponse- Camera image dataJointAnglesResponse- Joint angles dataAnimationsListResponse- Available animations listOperationsResponse- Active operations listOperationResponse- Single operation statusBehaviourResponse- Behavior execution responseBehavioursListResponse- Available behaviors list
Request Models
DurationRequest- Duration-based operationsPostureRequest- Posture change requestsSpeechRequest- Speech commandsWalkRequest- Walking commandsHeadPositionRequest- Head positioningLEDsRequest- LED controlAnimationExecuteRequest- Animation executionSequenceRequest- Movement sequencesBehaviourExecuteRequest- Behavior executionArmsPresetRequest- Arms preset positionsHandsRequest- Hand controlLieRequest- Lie postureAutonomousLifeRequest- Autonomous life state
Exception Types
NAOBridgeError- Base exception for all NAO Bridge errors
Example Usage
See example_usage.py for comprehensive examples demonstrating:
- Basic robot control
- Movement and positioning
- Speech and LED control
- Sensor reading
- Animation execution
- Walking control
- Sequence execution
- Error handling
- Context manager usage
- Async operations
Running the Example
python example_usage.py
Make sure the NAO Bridge server is running on http://localhost:3000 and a NAO robot is connected before running the example.
API Documentation
The client is based on the OpenAPI/Swagger specification available at:
- Swagger UI:
http://localhost:3000/swagger - OpenAPI JSON:
http://localhost:3000/api/v1/swagger.json
Requirements
- Python 3.8+
- httpx>=0.24.0
- pydantic>=2.0.0
- pillow>=8.0.0
- typing-extensions>=4.0.0 (for Python < 3.11)
License
This client is part of the NAO Bridge project and follows the same license terms.
Installing from test.pypi.org
Allow main index as fallback
pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ nao-bridge-client
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nao_bridge_client-0.1.3.tar.gz.
File metadata
- Download URL: nao_bridge_client-0.1.3.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d65a70724f5fb74a51a0424942f96dba4c68cf8cb999eaf744188a41f54d5f26
|
|
| MD5 |
d07785f903d0c50ce90eb052f099ac47
|
|
| BLAKE2b-256 |
efe704c473e2802e65639b06d81c63548b819715656ff19239cdaed4d7fced6b
|
Provenance
The following attestation bundles were made for nao_bridge_client-0.1.3.tar.gz:
Publisher:
pypi.yml on davesnowdon/nao-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nao_bridge_client-0.1.3.tar.gz -
Subject digest:
d65a70724f5fb74a51a0424942f96dba4c68cf8cb999eaf744188a41f54d5f26 - Sigstore transparency entry: 315072126
- Sigstore integration time:
-
Permalink:
davesnowdon/nao-bridge@6eec98edad2947c16ec9ed928929f4c11eb89140 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/davesnowdon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@6eec98edad2947c16ec9ed928929f4c11eb89140 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nao_bridge_client-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nao_bridge_client-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47ab25ca94179a2630d6e0b8db76ba1aed74d44ab037ac69bddaa0ac5146607b
|
|
| MD5 |
c7109dfba2a874f181cddfe566ccf88a
|
|
| BLAKE2b-256 |
bdbe94dad9cec5820ceb7ed0daf64b4af04b28939b80f31b69757103ddd3ce29
|
Provenance
The following attestation bundles were made for nao_bridge_client-0.1.3-py3-none-any.whl:
Publisher:
pypi.yml on davesnowdon/nao-bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nao_bridge_client-0.1.3-py3-none-any.whl -
Subject digest:
47ab25ca94179a2630d6e0b8db76ba1aed74d44ab037ac69bddaa0ac5146607b - Sigstore transparency entry: 315072136
- Sigstore integration time:
-
Permalink:
davesnowdon/nao-bridge@6eec98edad2947c16ec9ed928929f4c11eb89140 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/davesnowdon
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@6eec98edad2947c16ec9ed928929f4c11eb89140 -
Trigger Event:
release
-
Statement type: