Skip to content

Commit

Permalink
adjust code example on readme
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantuMope committed Aug 27, 2021
1 parent 5eb3048 commit 2d5fda8
Showing 1 changed file with 7 additions and 29 deletions.
36 changes: 7 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cd src # For descriptions on the command line arguments, run python3 calibrate.p
python3 calibrate.py [-h] [-p POSE_PATH] [-m MOTION_PATH] [-c] [-a] [-n] [-s SAMPLE]
```

For those who wish to create their own custom scripts, an example template is provided in `src/example.py` which can also be seen below.
For those who wish to create their own custom scripts, an example template is provided in `src/example.py` *(small snippet shown below)*. Running these examples will also perform the calibration on the provided example data.
```python3
def main():
with open("../example_data/pose_samples.pkl", "rb") as f:
Expand All @@ -37,43 +37,21 @@ def main():
# python 2 to python 3 pickle in case sampling was done in ROS
base_to_hand, camera_to_marker = pickle.load(f, encoding='latin1')

with open("../example_data/paired_poses.pkl", "rb") as f:
motions = pickle.load(f)
# Obtain optimal motions as dual quaternions.
motions = robot_pose_selector(camera_to_marker, base_to_hand)

# Initialize calibrator with precomputed motions.
cb = Calibrator4DOF(motions)

# Our camera and end effector z-axes are antiparallel so we must apply a 180deg x-axis rotation.
# Our camera and end effector z-axes are antiparallel so we apply a 180deg x-axis rotation.
dq_x = cb.calibrate(antiparallel_screw_axes=True)

# Calibration Obtained Hand to Camera
# Hand to Camera TF obtained from handeye calibration.
ca_hand_to_camera = np.linalg.inv(dq_x.as_transform())

# Calibration Obtained with post nonlinear refinement
# Hand to Camera TF obtained from post nonlinear refinement.
nl_hand_to_camera = cb.nonlinear_refinement(base_to_hand, camera_to_marker, ca_hand_to_camera)

ca_rotation = np.rad2deg(R.from_matrix(ca_hand_to_camera[:3, :3]).as_euler('xyz'))
nl_rotation = np.rad2deg(R.from_matrix(nl_hand_to_camera[:3, :3]).as_euler('xyz'))

# Ground Truth Hand to Camera
gt_translation = [-0.456, -0.037, -0.112]
gt_rotation = [180, 0, 0]

# NOTE: (1) Ground Truth itself may be inaccurate (manually measured).
# (2) z-translation is an invalid number.
np.set_printoptions(precision=5)
print("Hand to Camera Transform Comparisons")
print("Translations: Calibration {}".format(ca_hand_to_camera[:3, -1]))
print(" Nonlinear {}".format(nl_hand_to_camera[:3, -1]))
print(" Ground Truth {}".format(gt_translation))
print("Rotations: Calibration {}".format(ca_rotation))
print(" Nonlinear {}".format(nl_rotation))
print(" Ground Truth {}".format(gt_rotation))


if __name__ == '__main__':
main()
```
```

## TODO
- Improve README documentation.
Expand Down

0 comments on commit 2d5fda8

Please sign in to comment.