Skip to content

Commit

Permalink
MarlinRobotArm supports G1 linear moves
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 21, 2023
1 parent df81258 commit c747001
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 140 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/marginallyclever/ro3/RecentFilesMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public void removePath(String filePath) {
updateRecentFilesMenu();
}

/**
* Adds a path to the list of recent files. If the path already exists in the list, it will be moved to the head of the list.
* @param filePath the path to add.
*/
public void addPath(String filePath) {
// remove the path if it already exists so it will be moved to the top of the list.
recentFiles.remove(filePath);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/marginallyclever/ro3/Registry.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.marginallyclever.ro3.listwithevents.ListWithEvents;
import com.marginallyclever.ro3.node.nodes.*;
import com.marginallyclever.ro3.node.Node;
import com.marginallyclever.ro3.node.nodes.marlinrobotarm.MarlinRobotArm;
import com.marginallyclever.ro3.render.RenderPass;
import com.marginallyclever.ro3.render.renderpasses.*;
import com.marginallyclever.ro3.texture.TextureFactory;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/marginallyclever/ro3/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,11 @@ public void removeRenameListener(NodeRenameListener listener) {
* Called every frame.
* @param dt the time since the last frame.
*/
public void update(double dt) {}
public void update(double dt) {
for(Node child : children) {
child.update(dt);
}
}

/**
* Build a Swing Component that represents this Node.
Expand Down
136 changes: 0 additions & 136 deletions src/main/java/com/marginallyclever/ro3/node/nodes/MarlinRobotArm.java

This file was deleted.

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);
}
}
}
Loading

0 comments on commit c747001

Please sign in to comment.