-
-
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.
make jaw position per-jaw, not per-gripper
- Loading branch information
1 parent
fc5b252
commit 9a4615f
Showing
11 changed files
with
404 additions
and
200 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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/marginallyclever/robotoverlord/components/GripperComponentAbstract.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.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); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/marginallyclever/robotoverlord/components/GripperComponentJaw.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,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); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/marginallyclever/robotoverlord/components/GripperComponentLinear.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,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); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/marginallyclever/robotoverlord/components/GripperComponentRotary.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,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); | ||
} | ||
} |
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
111 changes: 0 additions & 111 deletions
111
src/main/java/com/marginallyclever/robotoverlord/components/RobotGripperComponent.java
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
src/main/java/com/marginallyclever/robotoverlord/components/RobotGripperJawComponent.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.