Improve plugin activation
This commit is contained in:
parent
b4f68e78cc
commit
c508c65038
@ -42,24 +42,28 @@ class BtSimNode:
|
|||||||
return SeedResponse()
|
return SeedResponse()
|
||||||
|
|
||||||
def reset(self, req):
|
def reset(self, req):
|
||||||
for plugin in self.plugins:
|
self.deactivate_plugins()
|
||||||
plugin.is_running = False
|
|
||||||
rospy.sleep(1.0) # TODO replace with a read-write lock
|
rospy.sleep(1.0) # TODO replace with a read-write lock
|
||||||
bbox = self.sim.reset()
|
bbox = self.sim.reset()
|
||||||
self.plugins[2].dx_d = np.zeros(6)
|
self.activate_plugins()
|
||||||
res = ResetResponse(to_bbox_msg(bbox))
|
return ResetResponse(to_bbox_msg(bbox))
|
||||||
for plugin in self.plugins:
|
|
||||||
plugin.is_running = True
|
|
||||||
return res
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.start_plugins()
|
self.start_plugins()
|
||||||
|
self.activate_plugins()
|
||||||
rospy.spin()
|
rospy.spin()
|
||||||
|
|
||||||
def start_plugins(self):
|
def start_plugins(self):
|
||||||
for plugin in self.plugins:
|
for plugin in self.plugins:
|
||||||
plugin.thread.start()
|
plugin.thread.start()
|
||||||
plugin.is_running = True
|
|
||||||
|
def activate_plugins(self):
|
||||||
|
for plugin in self.plugins:
|
||||||
|
plugin.activate()
|
||||||
|
|
||||||
|
def deactivate_plugins(self):
|
||||||
|
for plugin in self.plugins:
|
||||||
|
plugin.deactivate()
|
||||||
|
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
@ -70,6 +74,12 @@ class Plugin:
|
|||||||
self.thread = Thread(target=self.loop, daemon=True)
|
self.thread = Thread(target=self.loop, daemon=True)
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
self.is_running = True
|
||||||
|
|
||||||
|
def deactivate(self):
|
||||||
|
self.is_running = False
|
||||||
|
|
||||||
def loop(self):
|
def loop(self):
|
||||||
rate = rospy.Rate(self.rate)
|
rate = rospy.Rate(self.rate)
|
||||||
while not rospy.is_shutdown():
|
while not rospy.is_shutdown():
|
||||||
@ -115,27 +125,21 @@ class CartesianVelocityControllerPlugin(Plugin):
|
|||||||
super().__init__(rate)
|
super().__init__(rate)
|
||||||
self.arm = arm
|
self.arm = arm
|
||||||
self.model = model
|
self.model = model
|
||||||
self.max_linear_vel = 0.1
|
|
||||||
self.max_angular_vel = 1.57
|
|
||||||
self.dx_d = np.zeros(6)
|
|
||||||
rospy.Subscriber("command", Twist, self.target_cb)
|
rospy.Subscriber("command", Twist, self.target_cb)
|
||||||
|
|
||||||
def target_cb(self, msg):
|
def target_cb(self, msg):
|
||||||
self.dx_d = from_twist_msg(msg)
|
self.dx_d = from_twist_msg(msg)
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
self.dx_d = np.zeros(6)
|
||||||
|
self.is_running = True
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
q, _ = self.arm.get_state()
|
q, _ = self.arm.get_state()
|
||||||
dx = self.limit_rate(self.dx_d)
|
|
||||||
J_pinv = np.linalg.pinv(self.model.jacobian(q))
|
J_pinv = np.linalg.pinv(self.model.jacobian(q))
|
||||||
cmd = np.dot(J_pinv, dx)
|
cmd = np.dot(J_pinv, self.dx_d)
|
||||||
self.arm.set_desired_joint_velocities(cmd)
|
self.arm.set_desired_joint_velocities(cmd)
|
||||||
|
|
||||||
def limit_rate(self, dx):
|
|
||||||
linear, angular = dx[:3], dx[3:]
|
|
||||||
linear = np.clip(linear, -self.max_linear_vel, self.max_linear_vel)
|
|
||||||
angular = np.clip(angular, -self.max_angular_vel, self.max_angular_vel)
|
|
||||||
return np.r_[linear, angular]
|
|
||||||
|
|
||||||
|
|
||||||
class MoveActionPlugin(Plugin):
|
class MoveActionPlugin(Plugin):
|
||||||
def __init__(self, gripper, rate=10):
|
def __init__(self, gripper, rate=10):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user