-
Notifications
You must be signed in to change notification settings - Fork 48
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
Dev taskspace control #200
Open
OmidRezayof
wants to merge
26
commits into
lbr-stack:humble
Choose a base branch
from
OmidRezayof:dev-taskspace-control
base: humble
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
712e2cf
latest changes to make move_2_cart a service
OmidRezayof 774a475
Merge pull request #1 from OmidRezayof/FRI3
OmidRezayof 05a1e3e
fixing long_lines
OmidRezayof e70f33b
long_lines node added / working
OmidRezayof 46a734b
pivot calibration added
OmidRezayof 75b738f
adding 'wait for goal' method and adding velocity value to service me…
OmidRezayof 9073c5b
added FreeForm service
OmidRezayof 1ea8080
Adding Sheela's admittance Demo
OmidRezayof ca44b87
Submerged demo added/bug fixings in move_2_cart
OmidRezayof 75ef71f
latest changes to demos / move_2_cart_dev getting completed, testsing…
OmidRezayof d0aee83
Combining move command generation for rotation only and normal moveme…
OmidRezayof 469ac65
curved vasc demo
OmidRezayof 735c764
Adding sheela's demo
OmidRezayof d22a5ac
latest changes to drill admittance for sheela's admittance demo
OmidRezayof 809f793
latest changes to codes
OmidRezayof 6c00953
debugging methods: pose_to_string
OmidRezayof 9f746eb
RPY fixed. Comments added.
OmidRezayof faff26b
latest changes
OmidRezayof fee8223
Orientation planning in quaternion space: SLERP
OmidRezayof 9bb99b8
fixing +- signs in pivot calibration algorithm
OmidRezayof 9d53092
Needle height adjustment after pivot calibration, adding bioprinter R…
OmidRezayof d785079
added layer by layer point deposition method
OmidRezayof b265b2c
Merge branch 'lbr-stack:humble' into dev-humble-omid
OmidRezayof 5353497
latest changes to long_lines and submerged_demo
OmidRezayof ed88f62
Deleted unnecessary files and modified move_to_pose_client.py
OmidRezayof 114a064
Deleted unnecessary files and modified move_to_pose_client.py
OmidRezayof File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
lbr_demos/lbr_demos_advanced_py/lbr_demos_advanced_py/pivot_calibration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import numpy as np | ||
import rclpy | ||
import threading | ||
import sys | ||
import select | ||
import lbr_demos_py.asbr | ||
|
||
from geometry_msgs.msg import Pose | ||
|
||
from lbr_fri_idl.msg import LBRState | ||
|
||
from .admittance_controller import AdmittanceController | ||
from .lbr_base_position_command_node import LBRBasePositionCommandNode | ||
|
||
capture_request = False | ||
|
||
|
||
|
||
def listen_for_keypress(node): | ||
global capture_request | ||
while rclpy.ok(): | ||
# Check for user input | ||
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]: | ||
line = sys.stdin.readline().strip() | ||
if line == 'e': | ||
print("Shutting down...") | ||
rclpy.shutdown() | ||
break | ||
if line == 'c': | ||
capture_request = True | ||
print('Capture requested') | ||
|
||
class PivotCalibrationNode(LBRBasePositionCommandNode): | ||
def __init__(self, node_name: str = "pivot_calib") -> None: | ||
super().__init__(node_name=node_name) | ||
|
||
# parameters | ||
self.declare_parameter("base_link", "link_0") | ||
self.declare_parameter("end_effector_link", "link_ee") | ||
self.declare_parameter("f_ext_th", [2.0, 2.0, 8.0, 0.5, 0.5, 0.5]) | ||
self.declare_parameter("dq_gains", [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) | ||
self.declare_parameter("dx_gains", [0.2, 0.2, 0.2, 0.4, 0.4, 0.4]) | ||
self.declare_parameter("exp_smooth", 0.95) | ||
|
||
self._init = False | ||
self._lbr_state = LBRState() | ||
self._exp_smooth = ( | ||
self.get_parameter("exp_smooth").get_parameter_value().double_value | ||
) | ||
if self._exp_smooth < 0.0 or self._exp_smooth > 1.0: | ||
raise ValueError("Exponential smoothing factor must be in [0, 1].") | ||
|
||
self._controller = AdmittanceController( | ||
robot_description=self._robot_description, | ||
base_link=self.get_parameter("base_link") | ||
.get_parameter_value() | ||
.string_value, | ||
end_effector_link=self.get_parameter("end_effector_link") | ||
.get_parameter_value() | ||
.string_value, | ||
f_ext_th = self.get_parameter('f_ext_th').value, | ||
dq_gains = self.get_parameter('dq_gains').value, | ||
dx_gains = self.get_parameter('dx_gains').value, | ||
) | ||
|
||
# log parameters to terminal | ||
self._log_parameters() | ||
|
||
self.curr_pose_subs = self.create_subscription(Pose, 'state/pose', self.curr_pose_update, 1) | ||
self.curr_pose = Pose() | ||
|
||
self.Pivot_Calibration_Poses = [] | ||
|
||
def _log_parameters(self) -> None: | ||
self.get_logger().info("*** Parameters:") | ||
self.get_logger().info( | ||
f"* base_link: {self.get_parameter('base_link').value}" | ||
) | ||
self.get_logger().info( | ||
f"* end_effector_link: {self.get_parameter('end_effector_link').value}" | ||
) | ||
self.get_logger().info(f"* f_ext_th: {self.get_parameter('f_ext_th').value}") | ||
self.get_logger().info(f"* dq_gains: {self.get_parameter('dq_gains').value}") | ||
self.get_logger().info(f"* dx_gains: {self.get_parameter('dx_gains').value}") | ||
self.get_logger().info(f"* exp_smooth: {self.get_parameter('exp_smooth').value}") | ||
|
||
def _on_lbr_state(self, lbr_state: LBRState) -> None: | ||
self._smooth_lbr_state(lbr_state) | ||
|
||
lbr_command = self._controller(self._lbr_state, self._dt) | ||
self._lbr_joint_position_command_pub.publish(lbr_command) | ||
|
||
def _smooth_lbr_state(self, lbr_state: LBRState) -> None: | ||
if not self._init: | ||
self._lbr_state = lbr_state | ||
self._init = True | ||
return | ||
|
||
self._lbr_state.measured_joint_position = ( | ||
(1 - self._exp_smooth) | ||
* np.array(self._lbr_state.measured_joint_position.tolist()) | ||
+ self._exp_smooth * np.array(lbr_state.measured_joint_position.tolist()) | ||
).data | ||
|
||
self._lbr_state.external_torque = ( | ||
(1 - self._exp_smooth) * np.array(self._lbr_state.external_torque.tolist()) | ||
+ self._exp_smooth * np.array(lbr_state.external_torque.tolist()) | ||
).data | ||
|
||
def curr_pose_update(self, msg): | ||
self.curr_pose = msg | ||
global capture_request | ||
if capture_request: | ||
self.Pivot_Calibration_Poses.append(msg) | ||
print('Pose Added! Total number of poses: {}'.format(len(self.Pivot_Calibration_Poses))) | ||
if(len(self.Pivot_Calibration_Poses)>2): | ||
tip, divot, resid_dist = self.run_pivot_calibration(self.Pivot_Calibration_Poses) | ||
print('Tip wrt EE [m]:', tip) | ||
print('Divot Location [m]:', divot) | ||
print('Residual distances for each observation [m]:', resid_dist, '\n') | ||
|
||
capture_request = False | ||
|
||
def run_pivot_calibration(self, poses): | ||
# poses: a list of geometry_msgs.msg.Pose objects, containing position (x,y,z) | ||
# and orientation (x,y,z,w) as quat | ||
n = len(poses) | ||
A = np.empty((n * 3, 6)) | ||
b = np.empty((n * 3, 1)) | ||
for pi,p in enumerate(poses): | ||
rbase = 3 * pi | ||
R = lbr_demos_py.asbr.Rotation(p.orientation) | ||
b[rbase + 0, 0] = -p.position.x | ||
b[rbase + 1, 0] = -p.position.y | ||
b[rbase + 2, 0] = -p.position.z | ||
A[rbase:rbase+3, 0:3] = R.m | ||
A[rbase:rbase+3, 3:6] = -np.eye(3) | ||
|
||
x = np.linalg.lstsq(A, b, rcond=None)[0] | ||
|
||
resid = np.matmul(A, x) - b | ||
resid_dist = np.sqrt(np.sum(np.square(resid.reshape((3,-1))), axis=0)) | ||
tip = (x[0,0], x[1,0], x[2,0]) | ||
divot = (x[3,0], x[4,0], x[5,0]) | ||
return (tip, divot, resid_dist) | ||
|
||
|
||
|
||
def main(args=None) -> None: | ||
rclpy.init(args=args) | ||
admittance_control_node = PivotCalibrationNode() | ||
|
||
# Start the keypress listener thread | ||
keypress_thread = threading.Thread(target=listen_for_keypress, args=(admittance_control_node,), daemon=True) | ||
keypress_thread.start() | ||
|
||
try: | ||
rclpy.spin(admittance_control_node) | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
rclpy.shutdown() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line needs removal