@Test public void testHalfStepsLoop() throws Exception { SimulatedStepperMotor dut = new SimulatedStepperMotor(getBuilderFor(buildProperty().setStepsPerRotation(1024))); byte[] half_step_sequence = new byte[8]; half_step_sequence[0] = (byte) 0b0001; half_step_sequence[1] = (byte) 0b0011; half_step_sequence[2] = (byte) 0b0010; half_step_sequence[3] = (byte) 0b0110; half_step_sequence[4] = (byte) 0b0100; half_step_sequence[5] = (byte) 0b1100; half_step_sequence[6] = (byte) 0b1000; half_step_sequence[7] = (byte) 0b1001; for (int i = 0; i < 1024+1; i++) { doStep(dut, true, half_step_sequence, PinState.HIGH, PinState.LOW); } assertPosition(360.0, dut); }
private void doStep() { Long currentTime = SimulatedTime.INST.getRequestingTime(); byte currentBinaryState = getBinaryState(); if (logger.isTraceEnabled()) logger.info("Do Step : previous["+previousBinaryState+"] current["+currentBinaryState+"] @ "+currentTime); if (single_step_sequence.containsKey(previousBinaryState) && single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if (previousBinaryState == 0 ) { logger.info("Stepping from init" ); previousBinaryState = currentBinaryState; if (single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } } }
SimulatedStepperMotor implements GpioCompHwEmulation, SimulatedTimeListerner { private void doStep() { Long currentTime = SimulatedTime.INST.getRequestingTime(); byte currentBinaryState = getBinaryState(); if (logger.isTraceEnabled()) logger.info("Do Step : previous["+previousBinaryState+"] current["+currentBinaryState+"] @ "+currentTime); if (single_step_sequence.containsKey(previousBinaryState) && single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if (previousBinaryState == 0 ) { logger.info("Stepping from init" ); previousBinaryState = currentBinaryState; if (single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } } } }
SimulatedStepperMotor implements GpioCompHwEmulation, SimulatedTimeListerner { private void doStep() { Long currentTime = SimulatedTime.INST.getRequestingTime(); byte currentBinaryState = getBinaryState(); if (logger.isTraceEnabled()) logger.info("Do Step : previous["+previousBinaryState+"] current["+currentBinaryState+"] @ "+currentTime); if (single_step_sequence.containsKey(previousBinaryState) && single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if (previousBinaryState == 0 ) { logger.info("Stepping from init" ); previousBinaryState = currentBinaryState; if (single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } } } SimulatedStepperMotor(HardwareBuilder builder);  SimulatedStepperMotor();  SimulatedStepperMotor(org.raspinloop.config.PinState onState, org.raspinloop.config.PinState offState); }
SimulatedStepperMotor implements GpioCompHwEmulation, SimulatedTimeListerner { private void doStep() { Long currentTime = SimulatedTime.INST.getRequestingTime(); byte currentBinaryState = getBinaryState(); if (logger.isTraceEnabled()) logger.info("Do Step : previous["+previousBinaryState+"] current["+currentBinaryState+"] @ "+currentTime); if (single_step_sequence.containsKey(previousBinaryState) && single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if (previousBinaryState == 0 ) { logger.info("Stepping from init" ); previousBinaryState = currentBinaryState; if (single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } } } SimulatedStepperMotor(HardwareBuilder builder);  SimulatedStepperMotor();  SimulatedStepperMotor(org.raspinloop.config.PinState onState, org.raspinloop.config.PinState offState); boolean enterInitialize(); boolean exitInitialize(); void terminate(); void reset(); List<Double> getReal(List<Integer> refs); List<Integer> getInteger(List<Integer> refs); List<Boolean> getBoolean(List<Integer> refs); boolean setReal(Map<Integer, Double> ref_values); boolean setInteger(Map<Integer, Integer> ref_values); boolean setBoolean(Map<Integer, Boolean> ref_values); boolean isTerminated(); List<Fmi2ScalarVariable> getModelVariables(); int registerBaseref(int baseref); @Override String getType(); @Override PinState getState(Pin pin); @Override void setState(Pin pin, PinState state); @Override void onRequestingSleep(long requestedNanos); @Override boolean usePin(Pin pin); org.raspinloop.config.Pin getPin(Pin pin); @Override String getHWGuid(); }
SimulatedStepperMotor implements GpioCompHwEmulation, SimulatedTimeListerner { private void doStep() { Long currentTime = SimulatedTime.INST.getRequestingTime(); byte currentBinaryState = getBinaryState(); if (logger.isTraceEnabled()) logger.info("Do Step : previous["+previousBinaryState+"] current["+currentBinaryState+"] @ "+currentTime); if (single_step_sequence.containsKey(previousBinaryState) && single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if (previousBinaryState == 0 ) { logger.info("Stepping from init" ); previousBinaryState = currentBinaryState; if (single_step_sequence.containsKey(currentBinaryState)) { if (doStep(single_step_sequence.get(previousBinaryState), single_step_sequence.get(currentBinaryState), single_step_sequence.size())){ logger.info("Stepping in single_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( double_step_sequence.containsKey(previousBinaryState) && double_step_sequence.containsKey(currentBinaryState)) { if (doStep(double_step_sequence.get(previousBinaryState), double_step_sequence.get(currentBinaryState), double_step_sequence.size())){ logger.info("Stepping in double_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } else if ( half_step_sequence.containsKey(previousBinaryState) && half_step_sequence.containsKey(currentBinaryState)) { if (doStep(half_step_sequence.get(previousBinaryState), half_step_sequence.get(currentBinaryState), half_step_sequence.size())){ logger.info("Stepping in half_step_sequence"+previousBinaryState+"->"+currentBinaryState+" @"+currentTime ); previousBinaryState = currentBinaryState; previousChangeTime = currentTime; } } } } SimulatedStepperMotor(HardwareBuilder builder);  SimulatedStepperMotor();  SimulatedStepperMotor(org.raspinloop.config.PinState onState, org.raspinloop.config.PinState offState); boolean enterInitialize(); boolean exitInitialize(); void terminate(); void reset(); List<Double> getReal(List<Integer> refs); List<Integer> getInteger(List<Integer> refs); List<Boolean> getBoolean(List<Integer> refs); boolean setReal(Map<Integer, Double> ref_values); boolean setInteger(Map<Integer, Integer> ref_values); boolean setBoolean(Map<Integer, Boolean> ref_values); boolean isTerminated(); List<Fmi2ScalarVariable> getModelVariables(); int registerBaseref(int baseref); @Override String getType(); @Override PinState getState(Pin pin); @Override void setState(Pin pin, PinState state); @Override void onRequestingSleep(long requestedNanos); @Override boolean usePin(Pin pin); org.raspinloop.config.Pin getPin(Pin pin); @Override String getHWGuid();  }