43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import sys
|
|
from google.protobuf import timestamp_pb2
|
|
|
|
sys.path.append("../generated")
|
|
|
|
from generated.cmvr.api import humanoid_robot_service_pb2_grpc as rpc
|
|
from generated.cmvr.api import humanoid_robot_command_pb2 as pb
|
|
from generated.cmvr.api import common_pb2
|
|
from clients.base_client import RobotClientBase
|
|
|
|
|
|
class TorqueOffClient(RobotClientBase):
|
|
"""Client to send TorqueOff command"""
|
|
|
|
def send(self, device_id="hc01"):
|
|
# Construct request header
|
|
req = common_pb2.CommandHeader.Request()
|
|
req.device_id = device_id
|
|
ts = timestamp_pb2.Timestamp()
|
|
ts.GetCurrentTime()
|
|
req.timestamp.CopyFrom(ts)
|
|
|
|
# Call RPC
|
|
try:
|
|
resp = self.stub.torqueOff(req, timeout=10)
|
|
print("TorqueOff RPC call succeeded")
|
|
print(f"Success: {resp.success}")
|
|
print(f"Error message: {resp.error_message}")
|
|
print(f"Timestamp: {resp.timestamp.seconds}")
|
|
except Exception as e:
|
|
print("TorqueOff RPC call failed:", e)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Initialize client
|
|
client = TorqueOffClient()
|
|
|
|
# Send TorqueOff command
|
|
client.send(device_id="hc01")
|
|
|
|
# Close client
|
|
client.close()
|