Search in sources :

Example 1 with SensorProvider

use of com.robo4j.hw.lego.provider.SensorProvider in project robo4j by Robo4J.

the class BasicSonicUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    target = configuration.getString("target", null);
    if (target == null) {
        throw ConfigurationException.createMissingConfigNameException("target");
    }
    String sensorType = configuration.getString("sonicSensorPort", DigitalPortEnum.S3.getType());
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, DigitalPortEnum.getByType(sensorType), SensorTypeEnum.SONIC);
    String servoPort = configuration.getString("sonicServoPort", AnalogPortEnum.A.getType());
    Character servoType = configuration.getCharacter("sonicServoType", MotorTypeEnum.MEDIUM.getType());
    MotorProvider motorProvider = new MotorProvider();
    servo = new MotorWrapper<>(motorProvider, AnalogPortEnum.getByType(servoPort), MotorTypeEnum.getByType(servoType));
    unitActive.set(true);
    servoRight.set(true);
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) MotorProvider(com.robo4j.hw.lego.provider.MotorProvider)

Example 2 with SensorProvider

use of com.robo4j.hw.lego.provider.SensorProvider in project robo4j by Robo4J.

the class BasicSonicServoUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    target = configuration.getString("target", null);
    if (target == null) {
        throw ConfigurationException.createMissingConfigNameException("target");
    }
    String sensorType = configuration.getString("sonicSensorPort", DigitalPortEnum.S3.getType());
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, DigitalPortEnum.getByType(sensorType), SensorTypeEnum.SONIC);
    String servoPort = configuration.getString("sonicServoPort", AnalogPortEnum.A.getType());
    Character servoType = configuration.getCharacter("sonicServoType", MotorTypeEnum.MEDIUM.getType());
    MotorProvider motorProvider = new MotorProvider();
    servo = new MotorWrapper<>(motorProvider, AnalogPortEnum.getByType(servoPort), MotorTypeEnum.getByType(servoType));
    unitActive.set(true);
    servoRight.set(true);
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) MotorProvider(com.robo4j.hw.lego.provider.MotorProvider)

Example 3 with SensorProvider

use of com.robo4j.hw.lego.provider.SensorProvider in project robo4j by Robo4J.

the class InfraSensorUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    scanInitialDelay = configuration.getInteger(PROPERTY_SCAN_INIT_DELAY, VALUE_SCAN_INIT_DELAY);
    scanPeriod = configuration.getInteger(PROPERTY_SCAN_PERIOD, VALUE_SCAN_PERIOD);
    String port = configuration.getString(PROPERTY_SENSOR_PORT, null);
    DigitalPortEnum sensorPort = DigitalPortEnum.getByType(port);
    target = configuration.getString(PROPERTY_TARGET, null);
    if (sensorPort == null) {
        throw new ConfigurationException("infraRed sensor port required: {S1,S2,S3,S4}");
    }
    if (target == null) {
        throw new ConfigurationException("infraRed sensor target required");
    }
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, sensorPort, SensorTypeEnum.INFRA);
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) ConfigurationException(com.robo4j.ConfigurationException) DigitalPortEnum(com.robo4j.hw.lego.enums.DigitalPortEnum)

Example 4 with SensorProvider

use of com.robo4j.hw.lego.provider.SensorProvider in project robo4j by Robo4J.

the class TouchMotorUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    target = configuration.getString("target", null);
    if (target == null) {
        throw ConfigurationException.createMissingConfigNameException("target");
    }
    String sensorPort = configuration.getString("touchSensorPort", DigitalPortEnum.S1.getType());
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, DigitalPortEnum.getByType(sensorPort), SensorTypeEnum.TOUCH);
    sensorActive.set(true);
    currentState = MotorRotationEnum.STOP;
    runTouchSensor();
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider)

Example 5 with SensorProvider

use of com.robo4j.hw.lego.provider.SensorProvider in project robo4j by Robo4J.

the class SonicSensorUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    setState(LifecycleState.UNINITIALIZED);
    scanInitialDelay = configuration.getInteger(PROPERTY_SCAN_INIT_DELAY, VALUE_SCAN_INIT_DELAY);
    scanPeriod = configuration.getInteger(PROPERTY_SCAN_PERIOD, VALUE_SCAN_PERIOD);
    String port = configuration.getString(PROPERTY_SENSOR_PORT, null);
    DigitalPortEnum sensorPort = DigitalPortEnum.getByType(port);
    target = configuration.getString(PROPERTY_TARGET, null);
    if (sensorPort == null) {
        throw new ConfigurationException("sonic sensor port required: {S1,S2,S3,S4}");
    }
    if (target == null) {
        throw new ConfigurationException("sonic sensor target required");
    }
    SensorProvider provider = new SensorProvider();
    sensor = new SensorWrapper<>(provider, sensorPort, SensorTypeEnum.SONIC);
    setState(LifecycleState.INITIALIZED);
}
Also used : SensorProvider(com.robo4j.hw.lego.provider.SensorProvider) ConfigurationException(com.robo4j.ConfigurationException) DigitalPortEnum(com.robo4j.hw.lego.enums.DigitalPortEnum)

Aggregations

SensorProvider (com.robo4j.hw.lego.provider.SensorProvider)6 ConfigurationException (com.robo4j.ConfigurationException)3 DigitalPortEnum (com.robo4j.hw.lego.enums.DigitalPortEnum)2 MotorProvider (com.robo4j.hw.lego.provider.MotorProvider)2