armbot trigger events added

This commit is contained in:
Gomathi 2025-04-28 12:08:57 +05:30
parent fe527a7e52
commit dc77d9ed43
6 changed files with 25 additions and 16 deletions

View File

@ -8,7 +8,7 @@ function RoboticArmAnimator({ armUuid, HandleCallback, currentPhase, ikSolver, t
const { armBots } = useArmBotStore(); const { armBots } = useArmBotStore();
const { scene } = useThree(); const { scene } = useThree();
const restSpeed = 0.1; const restSpeed = 0.1;
const restPosition = new THREE.Vector3(0, 2, 1.6); const restPosition = new THREE.Vector3(0, 1, -1.6);
const initialCurveRef = useRef<THREE.CatmullRomCurve3 | null>(null); const initialCurveRef = useRef<THREE.CatmullRomCurve3 | null>(null);
const initialStartPositionRef = useRef<THREE.Vector3 | null>(null); const initialStartPositionRef = useRef<THREE.Vector3 | null>(null);
const [initialProgress, setInitialProgress] = useState(0); const [initialProgress, setInitialProgress] = useState(0);
@ -26,7 +26,7 @@ function RoboticArmAnimator({ armUuid, HandleCallback, currentPhase, ikSolver, t
}, [path]) }, [path])
useEffect(() => { useEffect(() => {
}, [currentPath]) }, [currentPath])
useFrame((_, delta) => { useFrame((_, delta) => {
@ -42,13 +42,13 @@ function RoboticArmAnimator({ armUuid, HandleCallback, currentPhase, ikSolver, t
currentPath.map(point => new THREE.Vector3(point[0], point[1], point[2])) currentPath.map(point => new THREE.Vector3(point[0], point[1], point[2]))
); );
const next = initialProgressRef.current + delta * 0.5; const next = initialProgressRef.current + delta * 0.5;
if (next >= 1) { if (next >= 1) {
bone.position.copy(restPosition); // bone.position.copy(restPosition);
HandleCallback(); // Call the callback when the path is completed HandleCallback(); // Call the callback when the path is completed
initialProgressRef.current = 0; // Set ref to 1 when done initialProgressRef.current = 0; // Set ref to 1 when done
} else { } else {
const point = curve.getPoint(next); // Get the interpolated point from the curve const point = curve.getPoint(next); // Get the interpolated point from the curve
bone.position.copy(point); // Update the bone position along the curve bone.position.copy(point); // Update the bone position along the curve
initialProgressRef.current = next; // Update progress initialProgressRef.current = next; // Update progress

View File

@ -16,6 +16,7 @@ interface Process {
endPoint?: Vector3; endPoint?: Vector3;
speed: number; speed: number;
} }
function RoboticArmInstance({ robot }: { robot: ArmBotStatus }) { function RoboticArmInstance({ robot }: { robot: ArmBotStatus }) {
const { isPlaying } = usePlayButtonStore(); const { isPlaying } = usePlayButtonStore();
@ -29,7 +30,7 @@ function RoboticArmInstance({ robot }: { robot: ArmBotStatus }) {
const groupRef = useRef<any>(null); const groupRef = useRef<any>(null);
const [processes, setProcesses] = useState<Process[]>([]); const [processes, setProcesses] = useState<Process[]>([]);
const [armBotCurvePoints, setArmBotCurvePoints] = useState({ start: [], end: [] }) const [armBotCurvePoints, setArmBotCurvePoints] = useState({ start: [], end: [] })
const restPosition = new THREE.Vector3(0, 2, 1.6); const restPosition = new THREE.Vector3(0, 1, -1.6);
let armBotCurveRef = useRef<THREE.CatmullRomCurve3 | null>(null) let armBotCurveRef = useRef<THREE.CatmullRomCurve3 | null>(null)
const [path, setPath] = useState<[number, number, number][]>([]); const [path, setPath] = useState<[number, number, number][]>([]);

View File

@ -15,6 +15,7 @@ type IKInstanceProps = {
setArmBotCurvePoints: any setArmBotCurvePoints: any
}; };
function IKInstance({ modelUrl, setIkSolver, ikSolver, robot, groupRef, processes, setArmBotCurvePoints }: IKInstanceProps) { function IKInstance({ modelUrl, setIkSolver, ikSolver, robot, groupRef, processes, setArmBotCurvePoints }: IKInstanceProps) {
console.log('robot: ', robot.position, robot.rotation);
const { scene } = useThree(); const { scene } = useThree();
const gltf = useLoader(GLTFLoader, modelUrl, (loader) => { const gltf = useLoader(GLTFLoader, modelUrl, (loader) => {
const draco = new DRACOLoader(); const draco = new DRACOLoader();
@ -65,15 +66,24 @@ function IKInstance({ modelUrl, setIkSolver, ikSolver, robot, groupRef, processe
setIkSolver(solver); setIkSolver(solver);
const helper = new CCDIKHelper(OOI.Skinned_Mesh, iks, 0.05); const helper = new CCDIKHelper(OOI.Skinned_Mesh, iks, 0.05);
if (solver) {
// scene.add(groupRef.current) const bone = solver.mesh.skeleton.bones.find(
(b: any) => b.name === targetBoneName
) ?? "";
if (bone) {
const position = new THREE.Vector3();
bone.getWorldPosition(position);
console.log("world position", position.x, position.y, position.z); // this is the bone's world position
}
}
scene.add(helper)
}, [gltf]); }, [gltf]);
return ( return (
<> <>
<group ref={groupRef} position={robot.position}> <group ref={groupRef} position={robot.position} rotation={robot.rotation}>
<primitive <primitive
uuid={"ArmBot-X200"} uuid={"ArmBot-X200"}
object={cloned} object={cloned}

View File

@ -12,8 +12,8 @@ function RoboticArm() {
state: "idle", state: "idle",
modelUuid: "armbot-xyz-001", modelUuid: "armbot-xyz-001",
modelName: "ArmBot-X200", modelName: "ArmBot-X200",
position: [91.94347308985614, 0, 6.742905194869091], position: [0, 0, 0],
rotation: [0, 0, 0], rotation: [-3.141592653589793, 0.3861702258311774, -3.141592653589793],
type: "roboticArm", type: "roboticArm",
speed: 1.5, speed: 1.5,
point: { point: {
@ -26,8 +26,8 @@ function RoboticArm() {
actionName: "Pick Component", actionName: "Pick Component",
actionType: "pickAndPlace", actionType: "pickAndPlace",
process: { process: {
startPoint: [5.52543010919071, 1, -8.433681161200905], startPoint: [-1, 2, 1],
endPoint: [10.52543010919071, 1, -12.433681161200905], endPoint: [-2, 1, -1],
}, },
triggers: [ triggers: [
{ {
@ -145,7 +145,7 @@ function RoboticArm() {
]; ];
useEffect(() => { useEffect(() => {
removeArmBot(armBotStatusSample[0].modelUuid); removeArmBot(armBotStatusSample[0].modelUuid);
addArmBot('123', armBotStatusSample[0]); addArmBot('123', armBotStatusSample[0]);
// addArmBot('123', armBotStatusSample[1]); // addArmBot('123', armBotStatusSample[1]);

View File

@ -140,8 +140,6 @@ function VehicleAnimator({ path, handleCallBack, currentPhase, agvUuid, agvDetai
const elapsedTime = performance.now() - startTime; const elapsedTime = performance.now() - startTime;
if (elapsedTime >= fixedInterval) { if (elapsedTime >= fixedInterval) {
console.log('fixedInterval: ', fixedInterval);
console.log('elapsedTime: ', elapsedTime);
let droppedMat = droppedMaterial - 1; let droppedMat = droppedMaterial - 1;
decrementVehicleLoad(agvDetail.modelUuid, 1); decrementVehicleLoad(agvDetail.modelUuid, 1);
if (droppedMat === 0) return; if (droppedMat === 0) return;

View File

@ -148,7 +148,7 @@ function Vehicles() {
}, []) }, [])
useEffect(() => { useEffect(() => {
console.log('vehicles: ', vehicles); // console.log('vehicles: ', vehicles);
}, [vehicles]) }, [vehicles])