Skip to content

Commit af3116a

Browse files
committed
torque settings & speeds
1 parent b20ad99 commit af3116a

File tree

4 files changed

+156
-34
lines changed

4 files changed

+156
-34
lines changed

openlch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.5.3"
1+
__version__ = "0.6.0"
22

33
from .hal import HAL

openlch/hal.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class Servo:
3434
def __init__(self, stub):
3535
self.__stub = stub
3636

37-
def get_positions(self) -> List[Tuple[int, float]]:
37+
def get_positions(self) -> List[Tuple[int, float, float]]:
3838
"""
39-
Get current positions of all servos.
39+
Get current positions and speeds of all servos.
4040
4141
Returns:
42-
List[Tuple[int, float]]: A list of tuples containing servo IDs and their positions.
42+
List[Tuple[int, float, float]]: A list of tuples containing servo IDs, their positions, and speeds.
4343
"""
4444
response = self.__stub.GetPositions(hal_pb_pb2.Empty())
45-
return [(pos.id, pos.position) for pos in response.positions]
45+
return [(pos.id, pos.position, pos.speed) for pos in response.positions]
4646

4747
def set_positions(self, positions: List[Tuple[int, float]]) -> None:
4848
"""
@@ -52,7 +52,7 @@ def set_positions(self, positions: List[Tuple[int, float]]) -> None:
5252
positions (List[Tuple[int, float]]): A list of tuples, each containing a servo ID and its target position.
5353
"""
5454
joint_positions = [
55-
hal_pb_pb2.JointPosition(id=id, position=position)
55+
hal_pb_pb2.JointPosition(id=id, position=position, speed=0)
5656
for id, position in positions
5757
]
5858
request = hal_pb_pb2.JointPositions(positions=joint_positions)
@@ -191,6 +191,34 @@ def get_calibration_status(self) -> Dict[str, Union[bool, int]]:
191191
'calibrating_servo_id': response.calibrating_servo_id
192192
}
193193

194+
def set_torque(self, torque_settings: List[Tuple[int, float]]) -> None:
195+
"""
196+
Set torque for multiple servos.
197+
198+
Args:
199+
torque_settings (List[Tuple[int, float]]): A list of tuples, each containing a servo ID and its target torque.
200+
"""
201+
settings = [
202+
hal_pb_pb2.TorqueSetting(id=id, torque=torque)
203+
for id, torque in torque_settings
204+
]
205+
request = hal_pb_pb2.TorqueSettings(settings=settings)
206+
self.__stub.SetTorque(request)
207+
208+
def set_torque_enable(self, enable_settings: List[Tuple[int, bool]]) -> None:
209+
"""
210+
Enable or disable torque for multiple servos.
211+
212+
Args:
213+
enable_settings (List[Tuple[int, bool]]): A list of tuples, each containing a servo ID and a boolean indicating whether to enable torque.
214+
"""
215+
settings = [
216+
hal_pb_pb2.TorqueEnableSetting(id=id, enable=enable)
217+
for id, enable in enable_settings
218+
]
219+
request = hal_pb_pb2.TorqueEnableSettings(settings=settings)
220+
self.__stub.SetTorqueEnable(request)
221+
194222
class System:
195223
"""Class for system-related operations."""
196224

openlch/hal_pb_pb2.py

Lines changed: 36 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openlch/hal_pb_pb2_grpc.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ def __init__(self, channel):
9494
request_serializer=hal__pb__pb2.Empty.SerializeToString,
9595
response_deserializer=hal__pb__pb2.CalibrationStatus.FromString,
9696
_registered_method=True)
97+
self.SetTorque = channel.unary_unary(
98+
'/hal_pb.ServoControl/SetTorque',
99+
request_serializer=hal__pb__pb2.TorqueSettings.SerializeToString,
100+
response_deserializer=hal__pb__pb2.Empty.FromString,
101+
_registered_method=True)
102+
self.SetTorqueEnable = channel.unary_unary(
103+
'/hal_pb.ServoControl/SetTorqueEnable',
104+
request_serializer=hal__pb__pb2.TorqueEnableSettings.SerializeToString,
105+
response_deserializer=hal__pb__pb2.Empty.FromString,
106+
_registered_method=True)
97107

98108

99109
class ServoControlServicer(object):
@@ -171,6 +181,18 @@ def GetCalibrationStatus(self, request, context):
171181
context.set_details('Method not implemented!')
172182
raise NotImplementedError('Method not implemented!')
173183

184+
def SetTorque(self, request, context):
185+
"""Missing associated documentation comment in .proto file."""
186+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
187+
context.set_details('Method not implemented!')
188+
raise NotImplementedError('Method not implemented!')
189+
190+
def SetTorqueEnable(self, request, context):
191+
"""Missing associated documentation comment in .proto file."""
192+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
193+
context.set_details('Method not implemented!')
194+
raise NotImplementedError('Method not implemented!')
195+
174196

175197
def add_ServoControlServicer_to_server(servicer, server):
176198
rpc_method_handlers = {
@@ -234,6 +256,16 @@ def add_ServoControlServicer_to_server(servicer, server):
234256
request_deserializer=hal__pb__pb2.Empty.FromString,
235257
response_serializer=hal__pb__pb2.CalibrationStatus.SerializeToString,
236258
),
259+
'SetTorque': grpc.unary_unary_rpc_method_handler(
260+
servicer.SetTorque,
261+
request_deserializer=hal__pb__pb2.TorqueSettings.FromString,
262+
response_serializer=hal__pb__pb2.Empty.SerializeToString,
263+
),
264+
'SetTorqueEnable': grpc.unary_unary_rpc_method_handler(
265+
servicer.SetTorqueEnable,
266+
request_deserializer=hal__pb__pb2.TorqueEnableSettings.FromString,
267+
response_serializer=hal__pb__pb2.Empty.SerializeToString,
268+
),
237269
}
238270
generic_handler = grpc.method_handlers_generic_handler(
239271
'hal_pb.ServoControl', rpc_method_handlers)
@@ -568,3 +600,57 @@ def GetCalibrationStatus(request,
568600
timeout,
569601
metadata,
570602
_registered_method=True)
603+
604+
@staticmethod
605+
def SetTorque(request,
606+
target,
607+
options=(),
608+
channel_credentials=None,
609+
call_credentials=None,
610+
insecure=False,
611+
compression=None,
612+
wait_for_ready=None,
613+
timeout=None,
614+
metadata=None):
615+
return grpc.experimental.unary_unary(
616+
request,
617+
target,
618+
'/hal_pb.ServoControl/SetTorque',
619+
hal__pb__pb2.TorqueSettings.SerializeToString,
620+
hal__pb__pb2.Empty.FromString,
621+
options,
622+
channel_credentials,
623+
insecure,
624+
call_credentials,
625+
compression,
626+
wait_for_ready,
627+
timeout,
628+
metadata,
629+
_registered_method=True)
630+
631+
@staticmethod
632+
def SetTorqueEnable(request,
633+
target,
634+
options=(),
635+
channel_credentials=None,
636+
call_credentials=None,
637+
insecure=False,
638+
compression=None,
639+
wait_for_ready=None,
640+
timeout=None,
641+
metadata=None):
642+
return grpc.experimental.unary_unary(
643+
request,
644+
target,
645+
'/hal_pb.ServoControl/SetTorqueEnable',
646+
hal__pb__pb2.TorqueEnableSettings.SerializeToString,
647+
hal__pb__pb2.Empty.FromString,
648+
options,
649+
channel_credentials,
650+
insecure,
651+
call_credentials,
652+
compression,
653+
wait_for_ready,
654+
timeout,
655+
metadata,
656+
_registered_method=True)

0 commit comments

Comments
 (0)