Skip to content

Commit

Permalink
Successfully run ControlArmPanelTest
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Dec 7, 2023
1 parent bc05aaa commit 64dee90
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ private ShapeComponent findChildShapeComponent(Entity entity) {
return null;
}

/**
* Look for a DHComponent in the children of the given Entity.
* @param entity the entity to search
* @return the DHComponent if found, null otherwise
*/
private DHComponent findChildDHComponent(Entity entity) {
for( Entity child : entity.getChildren()) {
DHComponent found = child.getComponent(DHComponent.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,72 @@
import javax.vecmath.Matrix4d;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
import java.util.ArrayList;
import java.util.List;

public class RobotComponentTest {
private RobotComponent build3AxisArm() {
EntityManager entityManager = new EntityManager();
private static RobotComponent buildGenericArm(EntityManager entityManager,int numJoints) {
Entity base = new Entity("Base");
entityManager.addEntityToParent(base,entityManager.getRoot());
RobotComponent robot = new RobotComponent();
base.addComponent(robot);
// add target
Entity target = new Entity(RobotComponent.TARGET_NAME);
entityManager.addEntityToParent(target, base);
// position arm
List<Entity> joints = new ArrayList<>();
List<DHComponent> dh = new ArrayList<>();

// add bones
Entity prev = base;
for(int i=0;i<3;++i) {
for(int i=0;i<numJoints;++i) {
Entity e = new Entity("J"+i);
joints.add(e);
entityManager.addEntityToParent(e,prev);
e.addComponent(new DHComponent());
prev = e;
DHComponent dhc = new DHComponent();
dh.add(dhc);
e.addComponent(dhc);
}
dh.get(0).set(0,0,90,0,60,-60,true);
dh.get(1).set(0,10,0,45,170,-170,true);
dh.get(2).set(0,10,0,-90,170,-170,true);
joints.get(2).addComponent(new ArmEndEffectorComponent());

// add end effector
prev.addComponent(new ArmEndEffectorComponent());

// connect everything
robot.findBones();
robot.set(Robot.END_EFFECTOR_TARGET,robot.get(Robot.END_EFFECTOR));

return robot;
}
public static RobotComponent build5AxisSixi3(EntityManager entityManager) {
RobotComponent robot = buildGenericArm(entityManager,5);

// set DH parameters
DHComponent bone0 = robot.getBone(0);
DHComponent bone1 = robot.getBone(1);
DHComponent bone2 = robot.getBone(2);
DHComponent bone3 = robot.getBone(3);
DHComponent bone4 = robot.getBone(4);
bone0.set(8.000, 0.000, 270.000, 0.000, 170.000, -170.00, true);
bone1.set(9.130, 17.909, 0.000, 270.000, 370.000, 170.000, true);
bone2.set(0.000, 12.455, 0.000, 0.000, 150.000, -150.00, true);
bone3.set(0.000, 0.000, 270.000, 270.000, 440.000, 100.000, true);
bone4.set(5.100, 0.000, 0.000, 0.000, 360.000, 0.000, true);
bone0.setJointHome(0.000);
bone1.setJointHome(270.000);
bone2.setJointHome(0.000);
bone3.setJointHome(270.000);
bone4.setJointHome(0.000);

robot.set(Robot.END_EFFECTOR_TARGET,robot.get(Robot.END_EFFECTOR));

return robot;
}

private static RobotComponent build3AxisArm(EntityManager entityManager) {
RobotComponent robot = buildGenericArm(entityManager,3);

// set DH parameters
robot.getBone(0).set(0,0,90,0,60,-60,true);
robot.getBone(1).set(0,10,0,45,170,-170,true);
robot.getBone(2).set(0,10,0,-90,170,-170,true);

robot.set(Robot.END_EFFECTOR_TARGET,robot.get(Robot.END_EFFECTOR));

return robot;
}

private void testEndEffectorAtPosition(RobotComponent robot, Point3d expected) {
Point3d actual = (Point3d)robot.get(Robot.END_EFFECTOR_TARGET_POSITION);
Expand All @@ -55,7 +87,8 @@ private void testEndEffectorAtPosition(RobotComponent robot, Point3d expected) {
*/
@Test
public void test3AxisArmAtPosition() {
RobotComponent robot = build3AxisArm();
EntityManager entityManager = new EntityManager();
RobotComponent robot = build3AxisArm(entityManager);
testEndEffectorAtPosition(robot,new Point3d(14.14214,0,0));
}

Expand All @@ -65,7 +98,8 @@ public void test3AxisArmAtPosition() {
*/
@Test
public void test3AxisArmAtPosition2() {
RobotComponent robot = build3AxisArm();
EntityManager entityManager = new EntityManager();
RobotComponent robot = build3AxisArm(entityManager);
// a few iterations are needed to refine the movement.
for(int i=0;i<12;++i) {
robot.set(Robot.END_EFFECTOR_TARGET_POSITION, new Point3d(15.14214, 0, 0));
Expand All @@ -79,7 +113,8 @@ public void test3AxisArmAtPosition2() {
*/
@Test
public void test3AxisArmAtPosition3() {
RobotComponent robot = build3AxisArm();
EntityManager entityManager = new EntityManager();
RobotComponent robot = build3AxisArm(entityManager);
Matrix4d pose = MatrixHelper.createIdentityMatrix4();
pose.setTranslation(new Vector3d(10,0,0));
robot.set(RobotComponent.POSE,pose);
Expand All @@ -92,7 +127,8 @@ public void test3AxisArmAtPosition3() {
*/
@Test
public void test3AxisArmAtPosition4() {
RobotComponent robot = build3AxisArm();
EntityManager entityManager = new EntityManager();
RobotComponent robot = build3AxisArm(entityManager);
Matrix4d pose = (Matrix4d)robot.get(RobotComponent.POSE);
robot.set(RobotComponent.POSE,pose);
// a few iterations are needed to refine the movement.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.marginallyclever.convenience.log.Log;
import com.marginallyclever.robotoverlord.components.RobotComponent;
import com.marginallyclever.robotoverlord.components.RobotComponentTest;
import com.marginallyclever.robotoverlord.entity.EntityManager;
import com.marginallyclever.robotoverlord.swing.translator.Translator;

import javax.swing.*;
Expand All @@ -14,7 +16,8 @@ public static void main(String[] args) {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch(Exception ignored) {}

RobotComponent robot = new RobotComponent();
EntityManager entityManager = new EntityManager();
RobotComponent robot = RobotComponentTest.build5AxisSixi3(entityManager);

JFrame frame = new JFrame(ControlArmPanel.class.getSimpleName());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Expand All @@ -24,3 +27,11 @@ public static void main(String[] args) {
frame.setVisible(true);
}
}








0 comments on commit 64dee90

Please sign in to comment.