Friday, 30 September 2022

How to simulate a linear motion for a Group of Objects

My objective is to animate a linear gripping motion(pick/place), here is a codesandbox to reproduce my problem:

enter image description here

  1. The gripper is created, it starts to move down until it reaches the LEGO brick, then it stops.
const grip_pos = new Vector3(
    pick_pos.x,
    pick_pos.y,
    pick_pos.z + 5
);
createGripper(grip_pos, this.scene);
console.log(this.scene.getObjectByName("gripper", true));
const gripper = this.scene.getObjectByName("gripper", true);
// Down
while (gripper.position.y > (pick_pos.z / 0.48)) {
    gripper.position.y -= 0.1;
};
  1. The gripper is attached to the Lego, it takes it up, and moves to above the place position.
gripper.add(lego);

// if Down then Up
if (!gripper.position.y > (pick_pos.z / 0.48)) {
    while (gripper.position.y < grip_pos) {
        gripper.position.y += 0.1;
    };
    
    if (pick_rot) {
        gripper.rotateY(Math.PI/2);
     };
};

// Move to Place Position
while (gripper.position.x != ((place_pos.y / 0.8) + 9.2)) {
    gripper.position.x += (((place_pos.y / 0.8) + 9.2) - gripper.position.x) / step;
};

while (gripper.position.z != ((place_pos.x / 0.8) + 2.8)) {
    gripper.position.z += ((place_pos.x / 0.8) + 2.8) / step;
};
  1. The gripper moves down to the place position, it reaches the place position, then it detaches the lego, moves up, and vanishes.
// Place Down
if (gripper.position.x === place_pos.y && gripper.position.z === place_pos.x) {
    {
        while (gripper.position.y > (pick_pos.z / 0.48)) {
            gripper.position.y -= 0.1;
        }
    };
    if (place_rot) {
        gripper.rotateY(Math.PI / 2);
    };
};

To do so I have created my gripper, and tried to move it as explained beforehand. But I can't see any motion, and furthermore, my browser becomes stuck without showing any error! can you please guide me on how can I achieve that linear motion? thanks in advance.

Note that there is a conversion in the positions as I'm using two coordinate frames xyz, zyx with translation and scaling.



from How to simulate a linear motion for a Group of Objects

No comments:

Post a Comment