| | |
| | | import Box from './box'; |
| | | import * as Common from '../utils/common'; |
| | | import * as TWEEN from "@tweenjs/tween.js"; |
| | | import { useStore } from '@/store'; |
| | | import { |
| | | INTERVAL_TIME, |
| | | MODEL_AGV_SCALE, |
| | |
| | | if (loaderAngle > 180 - 10 && loaderAngle < 180 + 10) { |
| | | return -forkDis; |
| | | } |
| | | if (loaderAngle > 270 - 10 && loaderAngle < 270 + 10) { |
| | | if (loaderAngle > 90 - 10 && loaderAngle < 90 + 10) { |
| | | return forkDis; |
| | | } |
| | | if (loaderAngle > 90 - 10 && loaderAngle < 90 + 10) { |
| | | if (loaderAngle > 270 - 10 && loaderAngle < 270 + 10) { |
| | | return forkDis; |
| | | } |
| | | return forkDis; |
| | | } |
| | | |
| | | const getLoaderHasBox = (loaderAngle, forkDis, finger1, finger2, finger3, finger4) => { |
| | | console.log(loaderAngle, forkDis, finger1, finger2, finger3, finger4); |
| | | const getLoaderHasBox = (loaderAngle, inOutFlag, finger1, finger2, finger3, finger4) => { |
| | | // console.log(loaderAngle, forkDis, finger1, finger2, finger3, finger4); |
| | | if (loaderAngle > 360 - 10 || loaderAngle < 0 + 10) { |
| | | if (inOutFlag === 1) { |
| | | return finger1 && finger2; |
| | | } |
| | | if (inOutFlag === 2) { |
| | | return finger3 && finger4; |
| | | } |
| | | return finger1 && finger2; // 取货是对的 放货是错的 (右) |
| | | /** |
| | | * 2排 (0) |
| | |
| | | */ |
| | | } |
| | | if (loaderAngle > 180 - 10 && loaderAngle < 180 + 10) { |
| | | if (inOutFlag === 1) { |
| | | return finger1 && finger2; |
| | | } |
| | | if (inOutFlag === 2) { |
| | | return finger3 && finger4; |
| | | } |
| | | return finger3 && finger4; // 放货是对的 取货是错的 (左) |
| | | /** |
| | | * 1、3排 (180) |
| | |
| | | */ |
| | | } |
| | | if (loaderAngle > 90 - 10 && loaderAngle < 90 + 10) { |
| | | if (inOutFlag === 3) { |
| | | return finger3 && finger4; |
| | | } |
| | | if (inOutFlag === 4) { |
| | | return finger1 && finger2; |
| | | } |
| | | return finger1 && finger2; // 放货是对的 取货是错的 (中) |
| | | /** |
| | | * 背篓 (90) |
| | |
| | | return finger1 && finger2 && finger3 && finger4; |
| | | } |
| | | |
| | | const forkLengthFn = (forkLen, loaderAngle) => { |
| | | let maxVal = 800; |
| | | if (loaderAngle > 360 - 10 || loaderAngle < 0 + 10) { |
| | | maxVal = 1100; |
| | | } |
| | | if (loaderAngle > 180 - 10 && loaderAngle < 180 + 10) { |
| | | maxVal = 1100; |
| | | } |
| | | if (loaderAngle > 90 - 10 && loaderAngle < 90 + 10) { |
| | | maxVal = 800; |
| | | } |
| | | if (loaderAngle > 270 - 10 && loaderAngle < 270 + 10) { |
| | | maxVal = 0; |
| | | } |
| | | if (forkLen < 0) { |
| | | return -maxVal * 0.077; |
| | | } else if (forkLen > 0) { |
| | | return maxVal * 0.077; |
| | | } else { |
| | | return 0; |
| | | } |
| | | } |
| | | |
| | | const getMajorPos = (position, bodyAngle, offset) => { |
| | | const majorAngle = Common.positiveAngle(bodyAngle); |
| | | // console.log(position, majorAngle, offset); |
| | | if (majorAngle > 360 - 10 || majorAngle < 0 + 10) { |
| | | return { |
| | | x: (position?.[2] + offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, |
| | | y: position?.[1] * REAL_COMPARE_MAP_SCALE, |
| | | z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, |
| | | } |
| | | } |
| | | if (majorAngle > 180 - 10 && majorAngle < 180 + 10) { |
| | | return { |
| | | x: (position?.[2] - offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, |
| | | y: position?.[1] * REAL_COMPARE_MAP_SCALE, |
| | | z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, |
| | | } |
| | | } |
| | | if (majorAngle > 90 - 10 && majorAngle < 90 + 10) { |
| | | return { |
| | | x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, |
| | | y: position?.[1] * REAL_COMPARE_MAP_SCALE, |
| | | z: (position?.[0] - offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, |
| | | } |
| | | } |
| | | if (majorAngle > 270 - 10 && majorAngle < 270 + 10) { |
| | | return { |
| | | x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, |
| | | y: position?.[1] * REAL_COMPARE_MAP_SCALE, |
| | | z: (position?.[0] + offset) * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, |
| | | } |
| | | } |
| | | } |
| | | |
| | | const Agv = (props) => { |
| | | const { agvNo, position, trayList, hasBox, finger1, finger2, finger3, finger4 } = props; |
| | | const { agvNo, position, trayList, hasBox, finger1, finger2, finger3, finger4, inOutFlag, offset } = props; |
| | | const theta = -props.theta; |
| | | const height = props.height * 0.0655; |
| | | const forkLength = props.forkLength * 0.077; |
| | | // console.log(props.forkLength); |
| | | const loaderTheta = Number(props.loaderTheta?.toFixed(1)); |
| | | |
| | | const [groupPos, setGroupPos] = useState({ x: 0, y: 0, z: 0 }); |
| | | const [groupTheta, setGroupTheta] = useState(0); |
| | |
| | | const [loaderAngle, setLoaderAngle] = useState(0); |
| | | const [forkDis, setForkDis] = useState(0); |
| | | const [realTrayList, setRealTrayList] = useState([]); |
| | | const store = useStore(); |
| | | |
| | | useEffect(() => { |
| | | if (store.autoCruise && agvNo === store.cruiseAgvNo) { |
| | | // store.lookAt = groupPos; |
| | | |
| | | store.lookAt.x = groupPos.x; |
| | | store.lookAt.y = loaderHeight; |
| | | store.lookAt.z = groupPos.z; |
| | | } |
| | | }, [groupPos, loaderHeight]) |
| | | |
| | | useEffect(() => { |
| | | if (!props || Object.keys(props).length === 0) { |
| | | return; |
| | | } |
| | | |
| | | // group theta |
| | | const targetTheta = Common.normalizeAngle(theta - groupTheta) + groupTheta; |
| | | // group position |
| | | const pos = { |
| | | x: position?.[2] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_X, |
| | | y: position?.[1] * REAL_COMPARE_MAP_SCALE, |
| | | z: position?.[0] * REAL_COMPARE_MAP_SCALE + REAL_COMPARE_MAP_OFFSET_Z, |
| | | } |
| | | const pos = getMajorPos(position, targetTheta, offset); |
| | | |
| | | if (!Common.deepEqual(groupPos, pos) && props.position !== null) { |
| | | new TWEEN.Tween(groupPos) |
| | | .to(pos, INTERVAL_TIME) |
| | |
| | | |
| | | // group theta |
| | | if (groupTheta !== theta && props.theta !== null) { |
| | | const targetTheta = Common.normalizeAngle(theta - groupTheta) + groupTheta; |
| | | new TWEEN.Tween({ value: groupTheta }) |
| | | .to({ value: targetTheta }, INTERVAL_TIME) |
| | | .easing(TWEEN.Easing.Linear.None) |
| | |
| | | } |
| | | |
| | | // loader height |
| | | if (loaderHeight !== height && props.height !== null) { |
| | | if (loaderHeight !== height && props.height !== null && props.height > 1) { |
| | | new TWEEN.Tween({ value: loaderHeight }) |
| | | .to({ value: height }, INTERVAL_TIME) |
| | | .easing(TWEEN.Easing.Linear.None) |
| | |
| | | } |
| | | |
| | | // loader theta |
| | | const loaderTargetTheta = Common.normalizeAngle(loaderTheta + 90); |
| | | const loaderTargetTheta = Common.normalizeAngle(Number(props.loaderTheta?.toFixed(1)) + 90); |
| | | if (loaderAngle !== loaderTargetTheta && props.loaderTheta !== null) { |
| | | new TWEEN.Tween({ value: loaderAngle }) |
| | | .to({ value: loaderTargetTheta }, INTERVAL_TIME) |
| | |
| | | } |
| | | |
| | | // fork lenght |
| | | const forkLength = props.forkLength * 0.077; |
| | | // const forkLength = forkLengthFn(props.forkLength, loaderTargetTheta); |
| | | if (forkDis !== forkLength && props.forkLength !== null) { |
| | | const targetForkDis = getCorrectForkDis(Common.positiveAngle(loaderTargetTheta), forkLength); |
| | | new TWEEN.Tween({ value: forkDis }) |
| | |
| | | <primitive object={loaderModel} castShadow position={[0, 0, 0]} /> |
| | | <group position-z={forkDis}> |
| | | <primitive object={forkModel} castShadow position={[0, 6, 0]} /> |
| | | {(hasBox || getLoaderHasBox(loaderAngle, forkDis, finger1, finger2, finger3, finger4)) && <Box position={[0, 6, 0]} />} |
| | | {(hasBox || getLoaderHasBox(loaderAngle, inOutFlag, finger1, finger2, finger3, finger4)) && <Box position={[0, 6, 0]} />} |
| | | </group> |
| | | </group> |
| | | <group> |