diff --git a/unitree_sdk2py/g1/status/g1_health_api.py b/unitree_sdk2py/g1/status/g1_health_api.py new file mode 100644 index 0000000..825b8ca --- /dev/null +++ b/unitree_sdk2py/g1/status/g1_health_api.py @@ -0,0 +1,14 @@ +""" +" service name +""" +HEALTH_SERVICE_NAME = "health" + +""" +" service api version +""" +HEALTH_API_VERSION = "1.0.0" + +""" +" api id +""" +ROBOT_API_ID_GET_HEALTH_STATUS = 9001 \ No newline at end of file diff --git a/unitree_sdk2py/g1/status/g1_health_client.py b/unitree_sdk2py/g1/status/g1_health_client.py new file mode 100644 index 0000000..cb85a26 --- /dev/null +++ b/unitree_sdk2py/g1/status/g1_health_client.py @@ -0,0 +1,18 @@ +import json +from ...rpc.client import Client +from .g1_health_api import * + +class G1HealthClient(Client): + def __init__(self): + super().__init__(HEALTH_SERVICE_NAME, False) + self._SetApiVerson(HEALTH_API_VERSION) + self._RegistApi(ROBOT_API_ID_GET_HEALTH_STATUS, 0) + + def GetHealthStatus(self): + p = {} + parameter = json.dumps(p) + code, data = self._Call(ROBOT_API_ID_GET_HEALTH_STATUS, parameter) + if code == 0: + return code, json.loads(data) + else: + return code, None \ No newline at end of file diff --git a/unitree_sdk2py/g1/visual_feedback/__init__.py b/unitree_sdk2py/g1/visual_feedback/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unitree_sdk2py/g1/visual_feedback/visual_feedback_api.py b/unitree_sdk2py/g1/visual_feedback/visual_feedback_api.py new file mode 100644 index 0000000..cb6d33d --- /dev/null +++ b/unitree_sdk2py/g1/visual_feedback/visual_feedback_api.py @@ -0,0 +1,16 @@ +""" +Visual Feedback API for G1 robot. +Defines sensor data structures and threshold values for obstacle detection. +""" + +# Threshold distances in meters +SAFE_DISTANCE = 1.5 # Green zone +WARNING_DISTANCE = 0.7 # Yellow zone +CRITICAL_DISTANCE = 0.3 # Red zone + +# Display colors +DISPLAY_COLORS = { + "SAFE": "GREEN", + "WARNING": "YELLOW", + "CRITICAL": "RED" +} \ No newline at end of file diff --git a/unitree_sdk2py/g1/visual_feedback/visual_feedback_client.py b/unitree_sdk2py/g1/visual_feedback/visual_feedback_client.py new file mode 100644 index 0000000..87193bd --- /dev/null +++ b/unitree_sdk2py/g1/visual_feedback/visual_feedback_client.py @@ -0,0 +1,48 @@ +""" +Visual Feedback Client +Processes sensor data and provides visual feedback to the user. +""" + +import time +import random # Simulated sensor data +from .visual_feedback_api import SAFE_DISTANCE, WARNING_DISTANCE, CRITICAL_DISTANCE, DISPLAY_COLORS + +class VisualFeedbackClient: + def __init__(self): + self.initialized = False + + def initialize(self): + # Initialize sensors or connections if needed + self.initialized = True + print("Visual Feedback Client initialized.") + + def get_obstacle_distance(self): + """ + Simulate reading distance from sensors. + Replace with actual sensor reading in real implementation. + """ + # Random distance between 0.1 and 2.0 meters + return round(random.uniform(0.1, 2.0), 2) + + def update_display(self, distance: float): + """ + Update visual feedback based on distance + """ + if distance >= SAFE_DISTANCE: + color = DISPLAY_COLORS["SAFE"] + elif distance >= WARNING_DISTANCE: + color = DISPLAY_COLORS["WARNING"] + else: + color = DISPLAY_COLORS["CRITICAL"] + + # In real robot: send command to LED/display + print(f"[Visual Feedback] Distance: {distance} m → {color}") + +# Example usage +if __name__ == "__main__": + client = VisualFeedbackClient() + client.initialize() + while True: + d = client.get_obstacle_distance() + client.update_display(d) + time.sleep(1) diff --git a/unitree_sdk2py/g1/voice_control/__init__.py b/unitree_sdk2py/g1/voice_control/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unitree_sdk2py/g1/voice_control/vui_client.py b/unitree_sdk2py/g1/voice_control/vui_client.py new file mode 100644 index 0000000..cf8f245 --- /dev/null +++ b/unitree_sdk2py/g1/voice_control/vui_client.py @@ -0,0 +1,37 @@ +""" +VUIClient starter module +Processes voice commands and sends them to the robot +""" + +from .vui_client_api import VOICE_COMMANDS +import random # Simülate + +class VUIClient: + def __init__(self): + self.initialized = False + + def initialize(self): + # Initialize voice recognition system (placeholder) + self.initialized = True + print("VUI Client initialized.") + + def listen_command(self): + """ + Simulate listening to a voice command. + Replace with actual voice recognition in real implementation. + """ + return random.choice(list(VOICE_COMMANDS.keys())) + + def execute_command(self, command): + if command in VOICE_COMMANDS: + print(f"[Voice Command] Executing: {VOICE_COMMANDS[command]}") + else: + print(f"[Voice Command] Unknown command: {command}") + +# Example usage +if __name__ == "__main__": + client = VUIClient() + client.initialize() + while True: + cmd = client.listen_command() + client.execute_command(cmd) diff --git a/unitree_sdk2py/g1/voice_control/vui_client_api.py b/unitree_sdk2py/g1/voice_control/vui_client_api.py new file mode 100644 index 0000000..f80e44b --- /dev/null +++ b/unitree_sdk2py/g1/voice_control/vui_client_api.py @@ -0,0 +1,13 @@ +""" +VUIClient API for G1 robot. +Defines command structure and supported voice commands. +""" + +# Supported commands +VOICE_COMMANDS = { + "move_forward": "Move forward", + "move_backward": "Move backward", + "turn_left": "Turn left", + "turn_right": "Turn right", + "stop": "Stop" +}