Search in sources :

Example 16 with MesureResult

use of com.cas.circuit.util.MesureResult in project TeachingInSimulation by ScOrPiOzzy.

the class DCMotor method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    super.onReceivedLocal(terminal);
    int dir = 0;
    MesureResult result1 = R.matchRequiredVolt(Voltage.IS_DC, _24v, _0v, ratedVolt, 2);
    MesureResult result2 = R.matchRequiredVolt(Voltage.IS_DC, _0v, _24v, ratedVolt, 2);
    boolean tmp = workable;
    if (result1 != null) {
        dir = 1;
    } else if (result2 != null) {
        dir = -1;
    }
    if (dir == 0) {
        System.out.println("电压不满足工作条件!");
        workable = false;
    } else {
        int rotateDir = dir / Math.abs(dir);
        motorControl.setRotateDir(rotateDir);
        motorControl.setSpeed(wheelSpeed);
        if (trackControl != null) {
            trackControl.setDir(rotateDir);
            trackControl.setSpeed(trackSpeed);
        }
        workable = true;
    }
    if (tmp && !workable) {
        System.out.println("DCMotor.onReceivedLocal(电机停止转动)");
        motorControl.setEnabled(false);
        // 停止相关的履带运动
        trackControl.setEnabled(false);
    } else if (!tmp && workable) {
        System.out.println("DCMotor.onReceivedLocal(电机开始转动)");
        motorControl.setEnabled(true);
        // 带动相关的履带运动
        trackControl.setEnabled(true);
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult)

Example 17 with MesureResult

use of com.cas.circuit.util.MesureResult in project TeachingInSimulation by ScOrPiOzzy.

the class ElectroMotor method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    if (pe == terminal) {
        return;
    }
    // 分别测量u、v、w三者之间的电压情况
    MesureResult resultUV = R.matchRequiredVolt(Voltage.IS_AC, u, v, 380, 10);
    MesureResult resultVW = R.matchRequiredVolt(Voltage.IS_AC, v, w, 380, 10);
    MesureResult resultWU = R.matchRequiredVolt(Voltage.IS_AC, w, u, 380, 10);
    // 判断三者之间是否存在电势差
    boolean matchRequiredVolt = Util.notEmpty(resultUV) && Util.notEmpty(resultWU) && Util.notEmpty(resultVW);
    float rpm = 0;
    if (matchRequiredVolt) {
        assert resultUV.getFrequency() == resultVW.getFrequency() && resultWU.getFrequency() == resultVW.getFrequency();
        // 计算电机的转速
        // 电机的转速 = 频率 * 60 / 2 / 电机减速比(有正负)
        rpm = MathUtil.round(5, resultUV.getFrequency() * 60 / 2);
        // 计算电机本身的方向
        int dir = R.mesurePhase(u, v, w);
        if (dir == 0) {
            System.err.println("相位不对");
        } else {
            // 1:表示轴承正转
            // -1:表示轴承反转
            // if (dir < 0) {
            // System.out.println("电机反转");
            // } else {
            // System.out.println("电机正转");
            // }
            int rotateDir = (int) (dir * slowdown / Math.abs(dir) / Math.abs(slowdown));
            // if (rotateDir < 0) {
            // System.out.println("轴承反转");
            // } else {
            // System.out.println("轴承正转");
            // }
            motorControl.setRotateDir(rotateDir);
            // 轴承旋转速度
            // 转速/减速比,转化为弧度:得到弧度/MIN, 最后转化成弧度/s
            motorControl.setSpeed(Math.abs(rpm / slowdown * FastMath.TWO_PI / 60));
            if (trackControl != null) {
                trackControl.setDir(rotateDir);
                // 转速/减速比*每圈移动的距离:得到mm/min,然后转化为 m/s
                trackControl.setSpeed(Math.abs(rpm / slowdown * movePerCycle / 60000));
            }
        }
    }
    boolean tmp = workable;
    if (rpm > 0) {
        workable = true;
    } else {
        workable = false;
    }
    if (tmp && !workable) {
        // 电机停止转动
        motorControl.setEnabled(false);
        // 停止相关的履带运动
        if (trackControl != null) {
            // 停止相关的履带运动
            trackControl.setEnabled(false);
        }
        for (MotionEvent control : trackContrls) {
            control.setEnabled(false);
        }
    } else if (!tmp && workable) {
        // 电机开始转动
        motorControl.setEnabled(true);
        // 带动相关的履带运动
        if (trackControl != null) {
            // 带动相关的履带运动
            trackControl.setEnabled(true);
        }
        for (MotionEvent control : trackContrls) {
            control.setEnabled(true);
        }
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult) MotionEvent(com.jme3.cinematic.events.MotionEvent)

Example 18 with MesureResult

use of com.cas.circuit.util.MesureResult in project TeachingInSimulation by ScOrPiOzzy.

the class ServoMotor method onReceivedLocal.

@Override
protected void onReceivedLocal(Terminal terminal) {
    if (pe == terminal) {
        return;
    }
    // 分别测量u、v、w三者之间的电压情况
    MesureResult resultUV = R.matchRequiredVolt(Voltage.IS_AC, u, v, 380, 10);
    MesureResult resultVW = R.matchRequiredVolt(Voltage.IS_AC, v, w, 380, 10);
    MesureResult resultWU = R.matchRequiredVolt(Voltage.IS_AC, w, u, 380, 10);
    // 判断三者之间是否存在电势差
    boolean matchRequiredVolt = Util.notEmpty(resultUV) && Util.notEmpty(resultWU) && Util.notEmpty(resultVW);
    float rpm = 0;
    if (matchRequiredVolt) {
        assert resultUV.getFrequency() == resultVW.getFrequency() && resultWU.getFrequency() == resultVW.getFrequency();
        // 计算电机的转速
        // 5000Hz = 5000个/s
        // resolution = 10000个/圈
        // rpm = 5000Hz/resolution = 圈/s * 60 = 圈/min
        // 5000 -> 30圈/min
        rpm = MathUtil.round(5, resultUV.getFrequency() / resolution * 60);
        // String pulseAmount = resultUV.getData("pulseAmount");
        // System.out.println("ServoMotor.onReceivedLocal()" + rpm);
        // 计算方向
        int dir = R.mesurePhase(u, v, w);
        // System.out.println("_80YS25GY38Motor.onReceivedLocal(rotateDir): " + dir);
        if (dir == 0) {
            System.err.println("相位不对");
        } else {
            // 1:表示电机正转
            // -1:表示电机反转
            int rotateDir = dir / Math.abs(dir);
            motorControl.setRotateDir(rotateDir);
            if (trackControl != null) {
                trackControl.setDir(rotateDir);
            }
            // 轴承旋转速度
            // 转速/减速比,转化为弧度:得到弧度/MIN, 最后转化成弧度/s
            motorControl.setSpeed(Math.abs(rpm / slowdown * FastMath.TWO_PI / 60));
            if (trackControl != null) {
                trackControl.setDir(rotateDir);
                // 转速/减速比*每圈移动的距离:得到mm/min,然后转化为 m/s
                // 30圈/min/60 * 60mm / 1000
                trackControl.setSpeed(Math.abs(rpm / slowdown * movePerCycle / 60000));
            }
        }
    }
    boolean tmp = workable;
    if (rpm > 0) {
        workable = true;
    } else {
        workable = false;
    }
    if (tmp && !workable) {
        System.out.println("_80YS25GY38Motor.onReceivedLocal(电机停止转动)");
        // 电机停止转动
        // elecCompEnd();
        motorControl.setEnabled(false);
        if (trackControl != null) {
            // 停止相关的履带运动
            trackControl.setEnabled(false);
        }
    } else if (!tmp && workable) {
        System.out.println("_80YS25GY38Motor.onReceivedLocal(电机开始转动)");
        // 电机开始转动
        // elecCompStart();
        motorControl.setEnabled(true);
        if (trackControl != null) {
            // 带动相关的履带运动
            trackControl.setEnabled(true);
        }
    }
}
Also used : MesureResult(com.cas.circuit.util.MesureResult)

Aggregations

MesureResult (com.cas.circuit.util.MesureResult)18 R (com.cas.circuit.util.R)6 Jack (com.cas.circuit.vo.Jack)2 Terminal (com.cas.circuit.vo.Terminal)2 MotionEvent (com.jme3.cinematic.events.MotionEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConnectivityException (javafish.clients.opc.exception.ConnectivityException)1 Variant (javafish.clients.opc.variant.Variant)1