-
Notifications
You must be signed in to change notification settings - Fork 131
/
launch_franka_interface_server.py
48 lines (39 loc) · 1.45 KB
/
launch_franka_interface_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import zerorpc
from polymetis import RobotInterface
import scipy.spatial.transform as st
import numpy as np
import torch
class FrankaInterface:
def __init__(self):
self.robot = RobotInterface('localhost')
def get_ee_pose(self):
data = self.robot.get_ee_pose()
pos = data[0].numpy()
quat_xyzw = data[1].numpy()
rot_vec = st.Rotation.from_quat(quat_xyzw).as_rotvec()
return np.concatenate([pos, rot_vec]).tolist()
def get_joint_positions(self):
return self.robot.get_joint_positions().numpy().tolist()
def get_joint_velocities(self):
return self.robot.get_joint_velocities().numpy().tolist()
def move_to_joint_positions(self, positions, time_to_go):
self.robot.move_to_joint_positions(
positions=torch.Tensor(positions),
time_to_go=time_to_go
)
def start_cartesian_impedance(self, Kx, Kxd):
self.robot.start_cartesian_impedance(
Kx=torch.Tensor(Kx),
Kxd=torch.Tensor(Kxd)
)
def update_desired_ee_pose(self, pose):
pose = np.asarray(pose)
self.robot.update_desired_ee_pose(
position=torch.Tensor(pose[:3]),
orientation=torch.Tensor(st.Rotation.from_rotvec(pose[3:]).as_quat())
)
def terminate_current_policy(self):
self.robot.terminate_current_policy()
s = zerorpc.Server(FrankaInterface())
s.bind("tcp://0.0.0.0:4242")
s.run()