-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MarlinRobotArm supports G1 linear moves
- Loading branch information
1 parent
df81258
commit c747001
Showing
8 changed files
with
448 additions
and
140 deletions.
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
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
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
136 changes: 0 additions & 136 deletions
136
src/main/java/com/marginallyclever/ro3/node/nodes/MarlinRobotArm.java
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
.../marginallyclever/ro3/node/nodes/marlinrobotarm/ApproximateJacobianFiniteDifferences.java
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,66 @@ | ||
package com.marginallyclever.ro3.node.nodes.marlinrobotarm; | ||
|
||
import com.marginallyclever.ro3.node.nodes.Pose; | ||
import com.marginallyclever.robotoverlord.systems.robot.robotarm.ApproximateJacobian; | ||
|
||
import javax.vecmath.Matrix3d; | ||
import javax.vecmath.Matrix4d; | ||
import java.security.InvalidParameterException; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Calculates the approximate jacobian for a robot arm using | ||
* <a href="https://en.wikipedia.org/wiki/Finite_difference_method">finite differences</a>. | ||
*/ | ||
public class ApproximateJacobianFiniteDifferences extends ApproximateJacobian { | ||
public double ANGLE_STEP_SIZE_DEGREES = 0.1; // degrees | ||
protected ApproximateJacobianFiniteDifferences(MarlinRobotArm arm) { | ||
super(arm.getNumJoints()); | ||
|
||
Pose endEffector = arm.getEndEffector(); | ||
if(endEffector==null) throw new InvalidParameterException("Robot must have an end effector."); | ||
|
||
double[] jointAnglesOriginal = arm.getAllJointValues(); | ||
Matrix4d endEffectorPose = endEffector.getWorld(); | ||
Matrix4d endEffectorDifference = new Matrix4d(); | ||
Matrix3d endEffectorPoseRotation = new Matrix3d(); | ||
Matrix3d endEffectorDifferenceRotation = new Matrix3d(); | ||
Matrix3d skewSymmetric = new Matrix3d(); | ||
try { | ||
for (int i = 0; i < DOF; ++i) { | ||
// use anglesB to get the hand matrix after a tiny adjustment on one joint. | ||
double[] jointAnglesPlusDelta = Arrays.copyOf(jointAnglesOriginal, jointAnglesOriginal.length); | ||
jointAnglesPlusDelta[i] += ANGLE_STEP_SIZE_DEGREES; | ||
arm.setAllJointValues(jointAnglesPlusDelta); | ||
Matrix4d endEffectorPosePlusDelta = endEffector.getWorld(); | ||
|
||
// use the finite difference in the two matrixes | ||
// aka the approximate the rate of change (aka the integral, aka the velocity) | ||
// in one column of the jacobian matrix at this position. | ||
endEffectorDifference.sub(endEffectorPosePlusDelta, endEffectorPose); | ||
endEffectorDifference.mul(1.0 / Math.toRadians(ANGLE_STEP_SIZE_DEGREES)); | ||
|
||
jacobian[0][i] = endEffectorDifference.m03; | ||
jacobian[1][i] = endEffectorDifference.m13; | ||
jacobian[2][i] = endEffectorDifference.m23; | ||
|
||
// Find the rotation part. | ||
endEffectorPose.getRotationScale(endEffectorPoseRotation); | ||
endEffectorDifference.getRotationScale(endEffectorDifferenceRotation); | ||
endEffectorPoseRotation.transpose(); // inverse of a rotation matrix is its transpose | ||
skewSymmetric.mul(endEffectorDifferenceRotation, endEffectorPoseRotation); | ||
|
||
// [ 0 -Wz Wy] | ||
// [ Wz 0 -Wx] | ||
// [-Wy Wx 0] | ||
|
||
jacobian[3][i] = skewSymmetric.m12; | ||
jacobian[4][i] = skewSymmetric.m20; | ||
jacobian[5][i] = skewSymmetric.m01; | ||
} | ||
} finally { | ||
arm.setAllJointValues(jointAnglesOriginal); | ||
arm.update(0); | ||
} | ||
} | ||
} |
Oops, something went wrong.