Skip to content

Commit

Permalink
make jaw position per-jaw, not per-gripper
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 5, 2023
1 parent fc5b252 commit 9a4615f
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public abstract class ComponentFactory {

MeshFromFile.class,
Box.class,
Cylinder.class,
Decal.class,
Grid.class,
Sphere.class,
Decal.class,
Cylinder.class,

Background.class,

Expand All @@ -56,8 +56,9 @@ public abstract class ComponentFactory {
ProgramComponent.class,
ProjectorComponent.class,

RobotGripperComponent.class,
RobotGripperJawComponent.class,
GripperComponentLinear.class,
GripperComponentRotary.class,
GripperComponentJaw.class,

DCMotorComponent.class,
ServoComponent.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.marginallyclever.robotoverlord.components;

import com.marginallyclever.robotoverlord.SerializationContext;
import com.marginallyclever.robotoverlord.entity.Entity;
import com.marginallyclever.robotoverlord.parameters.IntParameter;
import com.marginallyclever.robotoverlord.systems.render.mesh.Mesh;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
* A gripper is a component that can grab and hold things.
* @author Dan Royer
* @since 2.11.0
*/
public abstract class GripperComponentAbstract extends ShapeComponent {
public static String [] names = new String[] {
"Opening",
"Open",
"Closing",
"Closed"
};

public static final int MODE_OPENING = 0;
public static final int MODE_OPEN = 1;
public static final int MODE_CLOSING = 2;
public static final int MODE_CLOSED = 3;

public final IntParameter mode = new IntParameter("Mode",MODE_OPEN);

protected GripperComponentAbstract() {
super();
myMesh = new Mesh();
}

public int getMode() {
return mode.get();
}

/**
* @return the {@link ShapeComponent} of all {@link GripperComponentJaw} children.
*/
public List<GripperComponentJaw> getJaws() {
List<GripperComponentJaw> results = new ArrayList<>();
List<Entity> children = getEntity().getChildren();
for(Entity child : children) {
GripperComponentJaw jaw = child.getComponent(GripperComponentJaw.class);
if(jaw!=null) results.add(jaw);
}
return results;
}

@Override
public JSONObject toJSON(SerializationContext context) {
JSONObject jo = super.toJSON(context);
jo.put("mode",mode.toJSON(context));
return jo;
}

@Override
public void parseJSON(JSONObject json, SerializationContext context) {
mode.parseJSON(json.getJSONObject("mode"),context);
super.parseJSON(json,context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.marginallyclever.robotoverlord.components;

import com.jogamp.opengl.GL3;
import com.marginallyclever.convenience.helpers.MatrixHelper;
import com.marginallyclever.robotoverlord.SerializationContext;
import com.marginallyclever.robotoverlord.entity.Entity;
import com.marginallyclever.robotoverlord.parameters.DoubleParameter;
import org.json.JSONObject;

import javax.vecmath.Matrix4d;
import javax.vecmath.Vector3d;
import java.util.List;

/**
* Identifier so that systems can find each child jaw of a gripper.
*/
public class GripperComponentJaw extends Component {
public DoubleParameter openDistance = new DoubleParameter("Open Distance",5.0);
public DoubleParameter closeDistance = new DoubleParameter("Close Distance",1.0);

@Override
public JSONObject toJSON(SerializationContext context) {
JSONObject jo = super.toJSON(context);
jo.put("openDistance",openDistance.toJSON(context));
jo.put("closeDistance",closeDistance.toJSON(context));
return jo;
}

@Override
public void parseJSON(JSONObject json, SerializationContext context) {
openDistance.parseJSON(json.getJSONObject("openDistance"),context);
if(json.has("closeDistance")) closeDistance.parseJSON(json.getJSONObject("closeDistance"),context);
super.parseJSON(json,context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.marginallyclever.robotoverlord.components;

import com.jogamp.opengl.GL3;
import com.marginallyclever.convenience.helpers.MatrixHelper;
import com.marginallyclever.robotoverlord.SerializationContext;
import com.marginallyclever.robotoverlord.entity.Entity;
import com.marginallyclever.robotoverlord.parameters.DoubleParameter;
import org.json.JSONObject;

import javax.vecmath.Matrix4d;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import java.util.ArrayList;
import java.util.List;

/**
* A gripper is a component that can grab and hold things. The jaws move in a straight line.
* @author Dan Royer
* @since 2.6.1
*/
public class GripperComponentLinear extends GripperComponentAbstract {
public GripperComponentLinear() {
super();
}

/**
* @return the center of the {@link GripperComponentJaw} child entities in world space.
*/
public List<Point3d> getPoints() {
List<Entity> children = getEntity().getChildren();
List<Point3d> results = new ArrayList<>();
for(Entity child : children) {
if(child.getComponent(GripperComponentJaw.class)==null) continue;
Matrix4d pose = child.getComponent(PoseComponent.class).getWorld();
results.add(new Point3d(MatrixHelper.getPosition(pose)));
}
return results;
}

@Override
public void render(GL3 gl) {
List<Entity> children = getEntity().getChildren();
if(children.size()<2) return;

myMesh.setRenderStyle(GL3.GL_LINES);
myMesh.clear();
for(GripperComponentJaw jaw : getJaws()) {
Matrix4d m = jaw.getEntity().getComponent(PoseComponent.class).getLocal();
Vector3d p = MatrixHelper.getPosition(m);
Vector3d z = MatrixHelper.getZAxis(m);
double d = (jaw.openDistance.get() - jaw.closeDistance.get());
z.scaleAdd(d,z,p);

myMesh.addColor(1.0f,0.0f,0.5f,1.0f); myMesh.addVertex((float)p.x,(float)p.y,(float)p.z);
myMesh.addColor(1.0f,0.5f,1.0f,1.0f); myMesh.addVertex((float)z.x,(float)z.y,(float)z.z);
}
myMesh.render(gl);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.marginallyclever.robotoverlord.components;

import com.jogamp.opengl.GL3;
import com.marginallyclever.convenience.helpers.MatrixHelper;
import com.marginallyclever.robotoverlord.SerializationContext;
import com.marginallyclever.robotoverlord.entity.Entity;
import com.marginallyclever.robotoverlord.parameters.DoubleParameter;
import com.marginallyclever.robotoverlord.parameters.IntParameter;
import org.json.JSONObject;

import javax.vecmath.Matrix4d;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import java.util.ArrayList;
import java.util.List;

/**
* A gripper is a component that can grab and hold things. The jaws rotate around a point.
* @author Dan Royer
* @since 2.11.0
*/
public class GripperComponentRotary extends GripperComponentAbstract {
public GripperComponentRotary() {
super();
}

/**
* @return the center of the {@link GripperComponentJaw} child entities in world space.
*/
public List<Point3d> getPoints() {
List<Entity> children = getEntity().getChildren();
List<Point3d> results = new ArrayList<>();
for(Entity child : children) {
if(child.getComponent(GripperComponentJaw.class)==null) continue;
Matrix4d pose = child.getComponent(PoseComponent.class).getWorld();
results.add(new Point3d(MatrixHelper.getPosition(pose)));
}
return results;
}

@Override
public void render(GL3 gl) {
List<Entity> children = getEntity().getChildren();
if(children.size()<2) return;

myMesh.setRenderStyle(GL3.GL_LINES);
myMesh.clear();
for(GripperComponentJaw jaw : getJaws()) {
Matrix4d m = jaw.getEntity().getComponent(PoseComponent.class).getLocal();
Vector3d p = MatrixHelper.getPosition(m);
Vector3d z = MatrixHelper.getZAxis(m);
double d = (jaw.openDistance.get() - jaw.closeDistance.get());
z.scaleAdd(d,z,p);

myMesh.addColor(1.0f,0.0f,0.5f,1.0f); myMesh.addVertex((float)p.x,(float)p.y,(float)p.z);
myMesh.addColor(1.0f,0.5f,1.0f,1.0f); myMesh.addVertex((float)z.x,(float)z.y,(float)z.z);
}
myMesh.render(gl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setLocalMatrix4(Matrix4d m) {

/**
* Convert a matrix to Euler rotations. There are many valid solutions.
* See also <a href="https://www.learnopencv.com/rotation-matrix-to-euler-angles/">...</a>
* See also <a href="https://www.learnopencv.com/rotation-matrix-to-euler-angles/">learnopencv.com</a>
* Euler rotations are using the ZYX convention.
* @return a {@link Vector3d} with degree rotations.
*/
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9a4615f

Please sign in to comment.