/** * Sets the internal value of this YoEnum to the current value of the passed YoEnum. * * @param value YoEnum value to set this variable's value to * @param notifyListeners boolean determining whether or not to call {@link #notifyVariableChangedListeners()} * @return boolean whether or not internal state differed from the passed value */ @Override public boolean setValue(YoEnum<T> value, boolean notifyListeners) { return set(value.getEnumValue(), notifyListeners); }
public FiniteStateMachineYoVariableTrigger(final FiniteStateMachine<?, ?, ?> stateMachine, String name, YoVariableRegistry registry, final Class<E> enumType) { final YoEnum<E> yoVariable = new YoEnum<>(name, registry, enumType, true); yoVariable.set(null); // Attach a change listener, firing state machine events for every callback. yoVariable.addVariableChangedListener(new VariableChangedListener() { @Override public void notifyOfVariableChange(YoVariable<?> v) { if (yoVariable.getEnumValue() != null) { stateMachine.trigger(enumType, yoVariable.getEnumValue()); // Reset to null to be ready for another event. yoVariable.set(null); } } }); } }
/** * Creates a new YoEnum with the same parameters as this one, and registers it to the passed {@link YoVariableRegistry}. * * @param newRegistry YoVariableRegistry to duplicate this YoEnum to * @return the newly created and registered YoEnum */ @Override public YoEnum<T> duplicate(YoVariableRegistry newRegistry) { YoEnum<T> retVar = new YoEnum<>(getName(), getDescription(), newRegistry, getEnumType(), getAllowNullValue()); retVar.set(getEnumValue()); return retVar; }
public void doTransitionAction() { requestedState.set(null); } };
@Override public void starting(SimulationConstructionSet scs, Robot robot, YoVariableRegistry registry) { registry.addChild(sliderBoardRegistry); final SliderBoardConfigurationManager sliderBoardConfigurationManager = new SliderBoardConfigurationManager(scs); for (StepprStandPrepSetpoints setpoint : StepprStandPrepSetpoints.values) { StandPrepVariables variables = new StandPrepVariables(setpoint, registry); StepprJoint aJoint = setpoint.getJoints()[0]; sliderBoardConfigurationManager.setKnob(1, selectedJointPair, 0, StepprJoint.values.length); sliderBoardConfigurationManager.setSlider(1, variables.tau_d, -100.0, 100.0); sliderBoardConfigurationManager.setSlider(3, variables.damping, 0, 5 * aJoint.getRatio() * aJoint.getRatio()); sliderBoardConfigurationManager.saveConfiguration(setpoint.toString()); allSetpoints.put(setpoint, variables); } selectedJointPair.addVariableChangedListener(new VariableChangedListener() { @Override public void notifyOfVariableChange(YoVariable<?> v) { sliderBoardConfigurationManager.loadConfiguration(selectedJointPair.getEnumValue().toString()); } }); selectedJointPair.set(StepprStandPrepSetpoints.HIP_Y); StepprDashboard.createDashboard(scs, registry); scs.getDataBuffer().attachIndexChangedListener(this); }
@Override public boolean testCondition(double time) { return footConstraintType.getEnumValue() == FootControlModule.ConstraintType.SWING; } }
/** * Create a new YoEnum. This will call {@link YoEnum(String, YoVariableRegistry, Class)} with the given values. * * @param name String uniquely identifying this YoEnum * @param registry YoVariableRegistry for this YoEnum to register itself to after initialization * @param enumType the class representing the type of the enum */ public static <T extends Enum<T>> YoEnum<T> create(String name, Class<T> enumType, YoVariableRegistry registry) { return new YoEnum<>(name, registry, enumType); }
selectedJoint = new YoEnum<>("selectedJoint", "", registry, false, jointNameArray); System.out.println(Arrays.toString(selectedJoint.getEnumValuesAsString())); previousSelectedJoint = new YoEnum<>("previousSelectedJoint", "", registry, true, jointNameArray); previousSelectedJoint.set(YoEnum.NULL_VALUE); secondaryJoint = new YoEnum<>("secondaryJoint", "", registry, true, jointNameArray); secondaryJoint.set(YoEnum.NULL_VALUE); selectedJoint.addVariableChangedListener(new VariableChangedListener() selectedJoint.notifyVariableChangedListeners();
private void addGoalMarkerRobot() { goalMarkerRobot.setGravity(0.0); environmentRobots.add(goalMarkerRobot); YoVariableRegistry robotsYoVariableRegistry = goalMarkerRobot.getRobotsYoVariableRegistry(); YoEnum<GoalMarkerLocation> goalMarkerLocationYoEnum = YoEnum.create("DesiredGoalMarkerLocation", GoalMarkerLocation.class, robotsYoVariableRegistry); goalMarkerLocationYoEnum.addVariableChangedListener(new GoalMarkerLocationUpdater()); goalMarkerLocationYoEnum.set(GoalMarkerLocation.TOP_OF_STAIRS); }
@Override public void actionPerformed(ActionEvent e) { int newOrdinal = fromComboBoxIndexToEnumOrdinalMap.get(requestControlModeComboBox.getSelectedIndex()); int currentOrdinal = requestHighLevelControlMode.getOrdinal(); if (newOrdinal != currentOrdinal) { requestHighLevelControlMode.set(newOrdinal); } } });
@Override void setToString(String valueString) { if("null".equalsIgnoreCase(valueString)) { this.value.set(YoEnum.NULL_VALUE); return; } for(int i = 0; i < this.value.getEnumValuesAsString().length; i++) { if(this.value.getEnumValuesAsString()[i].equals(valueString)) { this.value.set(i); return; } } throw new RuntimeException("Cannot set enum value to " + valueString + ", undefined enum constant"); }
YoArtifactPolygon captureRegionArtifact = new YoArtifactPolygon("CaptureRegion", yoCaptureRegion, Color.BLACK, false); yoGraphicsListRegistry.registerArtifact("Capture", captureRegionArtifact); final YoEnum<RobotSide> yoSupportSide = new YoEnum<>("supportSide", registry, RobotSide.class); final YoDouble swingTimeRemaining = new YoDouble("swingTimeRemaining", registry); final YoFramePoint2D yoICP = new YoFramePoint2D("ICP", worldFrame, registry); swingTimeRemaining.addVariableChangedListener(variableChangedListener); yoICP.attachVariableChangedListener(variableChangedListener); yoSupportSide.addVariableChangedListener(variableChangedListener);
private static <T extends Enum<T>> String getFormattedEnumYoVariable(final YoEnum<T> yoEnum) { String enumValueName = yoEnum.getEnumValue() != null ? yoEnum.getEnumValue().name() : "null"; return yoEnum.getName() + ":" + enumValueName; }
public void registerWithVariableChangedListener(VariableChangedListener changedListener) { toggleMode.addVariableChangedListener(changedListener); }
case ENUM: yoVariableDefinition.setType(YoType.EnumYoVariable); if (((YoEnum<?>) variable).isBackedByEnum()) yoVariableDefinition.setEnumType(getOrAddEnumType(((YoEnum<?>) variable).getEnumType().getCanonicalName(), ((YoEnum<?>) variable).getEnumValuesAsString())); yoVariableDefinition.setEnumType(getOrAddEnumType(variable.getFullNameWithNameSpace() + ".EnumType", ((YoEnum<?>) variable).getEnumValuesAsString())); yoVariableDefinition.setAllowNullValues(((YoEnum<?>) variable).getAllowNullValue()); break; default:
private TrajectoryColorType getCurrentColorType() { return TrajectoryColorType.values[currentColorType.getOrdinal()]; }
/** * Calls {@link #set(T, boolean)} with the given value and true. * * @param enumValue enum to set this YoEnum's internal enum state to */ public void set(T enumValue) { set(enumValue, true); }
selectedJoint.addVariableChangedListener(new VariableChangedListener() selectedJoint.set(WandererJoint.RIGHT_KNEE_Y);
@Override public boolean testCondition(double timeInState) { return footConstraintType.getEnumValue() == ConstraintType.SWING; } }