Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added commands for actuators #3

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions pykos/pykos/services/actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,53 @@ def get_calibration_status(self, actuator_id: int):
response = self.operations_stub.GetOperation(operations_pb2.GetOperationRequest(name=f"operations/calibrate_actuator/{actuator_id}"))
metadata = CalibrationMetadata(response.metadata)
return metadata.status

def command_actuators(self, commands: list[dict]):
"""
Command multiple actuators at once.

Args:
commands: List of dictionaries containing actuator commands.
Each dict should have 'actuator_id' and optionally 'position',
'velocity', and 'torque'.

Returns:
List of ActionResult objects indicating success/failure for each command.
"""
actuator_commands = [actuator_pb2.ActuatorCommand(**cmd) for cmd in commands]
request = actuator_pb2.CommandActuatorsRequest(commands=actuator_commands)
response = self.stub.CommandActuators(request)
return response.results

def configure_actuator(self, actuator_id: int, **kwargs):
"""
Configure an actuator's parameters.

Args:
actuator_id: ID of the actuator to configure
**kwargs: Configuration parameters that may include:
kp, kd, ki, max_torque, protective_torque,
protection_time, torque_enabled, new_actuator_id

Returns:
ActionResponse indicating success/failure
"""
config = {"actuator_id": actuator_id, **kwargs}
request = actuator_pb2.ConfigureActuatorRequest(**config)
return self.stub.ConfigureActuator(request)

def get_actuators_state(self, actuator_ids: list[int]):
"""
Get the state of multiple actuators.

Args:
actuator_ids: List of actuator IDs to query

Returns:
List of ActuatorStateResponse objects containing the state information
"""
request = actuator_pb2.GetActuatorsStateRequest(actuator_ids=actuator_ids)
response = self.stub.GetActuatorsState(request)
return response.states


Loading