Skip to content

Commit

Permalink
Merge pull request #55 from pollen-robotics/54-get-config-from-grpc-a…
Browse files Browse the repository at this point in the history
…nd-adapt-the-sdk-in-function

Get config from grpc method. Adapt head required joints with the config.
  • Loading branch information
pierre-rouanet authored Jun 20, 2023
2 parents c643c7b + 7feefce commit 9e5e638
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 10 additions & 5 deletions reachy_sdk/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ class Head:
expressed in Reachy's coordinate system.
"""

_required_joints = (
'neck_roll', 'neck_pitch', 'neck_yaw', 'l_antenna', 'r_antenna',
)

def __init__(self, joints: List[Joint], grpc_channel) -> None:
def __init__(self, config, joints: List[Joint], grpc_channel) -> None:
"""Set up the head."""
if 'no_head' in config:
self._required_joints = (
'neck_roll', 'neck_pitch', 'neck_yaw',
)
else:
self._required_joints = (
'neck_roll', 'neck_pitch', 'neck_yaw', 'l_antenna', 'r_antenna',
)

self._kin_stub = HeadKinematicsStub(grpc_channel)

def get_joint(name):
Expand Down
8 changes: 7 additions & 1 deletion reachy_sdk/reachy_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from google.protobuf.empty_pb2 import Empty

from reachy_sdk_api import camera_reachy_pb2_grpc
from reachy_sdk_api import config_pb2_grpc
from reachy_sdk_api import joint_pb2, joint_pb2_grpc
from reachy_sdk_api import fan_pb2_grpc
from reachy_sdk_api import sensor_pb2, sensor_pb2_grpc
Expand Down Expand Up @@ -90,6 +91,7 @@ def __init__(
grpc.insecure_channel(f'{self._host}:{self._restart_port}')
)

self._get_config()
self._setup_joints()
self._setup_arms()
self._setup_head()
Expand All @@ -116,6 +118,10 @@ def __repr__(self) -> str:
s
}\n>'''

def _get_config(self) -> None:
config_stub = config_pb2_grpc.ConfigServiceStub(self._grpc_channel)
self._config = config_stub.GetReachyConfig(Empty()).config

def _setup_joints(self):
joint_stub = joint_pb2_grpc.JointServiceStub(self._grpc_channel)

Expand Down Expand Up @@ -148,7 +154,7 @@ def _setup_arms(self):

def _setup_head(self):
try:
head = Head(self._joints, self._grpc_channel)
head = Head(self._config, self._joints, self._grpc_channel)
setattr(self, 'head', head)
except ValueError:
pass
Expand Down

0 comments on commit 9e5e638

Please sign in to comment.