Skip to content

Commit

Permalink
added RobotArmToolComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 12, 2023
1 parent 8dd147d commit a482d03
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ public void setExpanded(boolean arg0) {
* Called when this component is attached to an entity.
*/
public void onAttach() {}

/**
* Called when this component is detached from an entity.
*/
public void onDetach() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Dan Royer
* @since 2.11.0
*/
public abstract class GripperComponentAbstract extends ShapeComponent {
public abstract class GripperComponentAbstract extends RobotArmToolComponent {
public static String [] names = new String[] {
"Opening",
"Open",
Expand All @@ -32,7 +32,6 @@ public abstract class GripperComponentAbstract extends ShapeComponent {

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

public int getMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,4 @@ public class GripperComponentLinear extends GripperComponentAbstract {
public GripperComponentLinear() {
super();
}


@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 @@ -26,12 +26,4 @@ public class GripperComponentRotary extends GripperComponentAbstract {
public GripperComponentRotary() {
super();
}

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

// TODO draw arc of gripper movement
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.marginallyclever.robotoverlord.components;

public class RobotArmToolComponent extends Component {
@Override
public void onAttach() {
super.onAttach();

RobotComponent robot = getEntity().findFirstComponentInParents(RobotComponent.class);
if(robot!=null) {
robot.set(RobotComponent.TOOL_ENTITY,getEntity());
}
}

@Override
public void onDetach() {
super.onDetach();

RobotComponent robot = getEntity().findFirstComponentInParents(RobotComponent.class);
if(robot!=null) {
robot.set(RobotComponent.TOOL_ENTITY,null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public Object get(int property) {
case JOINT_HOME: return getBone(activeJoint).getJointHome();
case ALL_JOINT_VALUES: return getAllJointValues();
case DESIRED_LINEAR_VELOCITY: return desiredLinearVelocity.get();
case TOOL_ENTITY: return getTool();
case TOOL_ACTIVE: return false;
default : {
logger.warn("invalid get() property {}", property);
Expand All @@ -112,11 +113,27 @@ public void set(int property, Object value) {
case JOINT_HOME -> getBone(activeJoint).setJointHome((double) value);
case ALL_JOINT_VALUES -> setAllJointValues((double[]) value);
case DESIRED_LINEAR_VELOCITY -> desiredLinearVelocity.set((double) value);
case TOOL_ENTITY -> setTool((Entity)value);
case TOOL_ACTIVE -> fireRobotEvent(new RobotEvent(RobotEvent.TOOL_ACTIVATE, this, value));
default -> logger.warn("invalid set() property {}", property);
}
}

private Entity toolAttached;

private Object getTool() {
return toolAttached;
}

private void setTool(Entity value) {
toolAttached = value;
fireToolAttached();
}

private void fireToolAttached() {
fireRobotEvent(new RobotEvent(RobotEvent.TOOL_CHANGE, this, toolAttached));
}

private Object getActiveJointValue() {
DHComponent b = getBone(activeJoint);
return b.getJointValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public void onAttach() {
}
}

@Override
public void onDetach() {
super.onDetach();
myMesh.clear();
}

@Override
public JSONObject toJSON(SerializationContext context) {
JSONObject jo = super.toJSON(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public void addChild(int index, Entity e) {
* Use {@link EntityManager#addEntityToParent(Entity, Entity)} instead.
* @param child the child to add
*/
@Deprecated
public void addChild(Entity child) {
//System.out.println("add "+child.getFullPath()+" to "+this.getFullPath());
children.add(child);
Expand All @@ -105,7 +104,6 @@ public void addChild(Entity child) {
* Use {@link EntityManager#removeEntityFromParent(Entity, Entity)} instead.
* @param child the child to remove
*/
@Deprecated
public void removeChild(Entity child) {
if (children.contains(child)) {
children.remove(child);
Expand Down Expand Up @@ -274,6 +272,7 @@ public Component getComponent(int i) {

public void removeComponent(Component c) {
components.remove(c);
c.onDetach();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.marginallyclever.robotoverlord.robots;

import com.marginallyclever.robotoverlord.entity.Entity;

import javax.vecmath.Matrix4d;
import javax.vecmath.Point3d;

Expand Down Expand Up @@ -29,7 +27,8 @@ public interface Robot {
int END_EFFECTOR_TARGET_POSITION = 15;
int ALL_JOINT_VALUES = 16;
int DESIRED_LINEAR_VELOCITY = 17;
int TOOL_ACTIVE = 18;
int TOOL_ENTITY = 18;
int TOOL_ACTIVE = 19;

/**
* @param property can be any one of the following:
Expand All @@ -52,6 +51,7 @@ public interface Robot {
* <li>{@link #JOINT_HOME}: returns a double representing the degrees or millimeters of the active joint at its home position.</li>
* <li>{@link #ALL_JOINT_VALUES} returns a double array {@link #NUM_JOINTS} long containing the value of the active component in each joint.</li>
* <li>{@link #DESIRED_LINEAR_VELOCITY} returns a double.</li>
* <li>{@link #TOOL_ENTITY} returns an Entity that contains a RobotToolComponent.</li>
* <li>{@link #TOOL_ACTIVE} returns a boolean.</li>
* </ul>
* @return the requested property or null.
Expand All @@ -74,6 +74,7 @@ public interface Robot {
* <li>{@link #JOINT_POSE}: a {@link Matrix4d} relative to the origin of this robot.</li>
* <li>{@link #ALL_JOINT_VALUES} a double array NUM_JOINTS long containing the value for the active component in each joint.</li>
* <li>{@link #DESIRED_LINEAR_VELOCITY} a positive, non-zero double in centimeters/s.</li>
* <li>{@link #TOOL_ENTITY} an Entity that contains a RobotToolComponent.</li>
* <li>{@link #TOOL_ACTIVE} a boolean.</li>
* </ul>
*/
Expand Down

0 comments on commit a482d03

Please sign in to comment.