2021-03-12 10:37:35 +01:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
class CartesianPoseController:
|
|
|
|
def __init__(self, model):
|
|
|
|
self.model = model
|
2021-03-12 14:55:42 +01:00
|
|
|
# self.x_d = x0
|
2021-03-12 10:37:35 +01:00
|
|
|
|
|
|
|
def set_target(self, pose):
|
2021-03-12 14:55:42 +01:00
|
|
|
self.x_d = pose.translation
|
2021-03-12 10:37:35 +01:00
|
|
|
|
|
|
|
def update(self, q, dq):
|
2021-03-12 14:55:42 +01:00
|
|
|
t = self.model.pose(q).translation
|
|
|
|
J = self.model.jacobian(q)[:3, :]
|
2021-03-12 10:37:35 +01:00
|
|
|
J_pinv = np.linalg.pinv(J)
|
|
|
|
|
2021-03-12 14:55:42 +01:00
|
|
|
err = 2.0 * (self.x_d - t)
|
2021-03-12 10:37:35 +01:00
|
|
|
cmd = np.dot(J_pinv, err)
|
|
|
|
|
|
|
|
return cmd
|