Search in sources :

Example 1 with RoboClawRCTank

use of com.robo4j.hw.rpi.pwm.roboclaw.RoboClawRCTank in project robo4j by Robo4J.

the class RoboClawRCTankUnit method onInitialization.

@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
    super.onInitialization(configuration);
    PWMPCA9685Device pcaDevice = I2CRegistry.createAndRegisterIfAbsent(getBus(), getAddress(), () -> PWMPCA9685Device.createDevice(getBus(), getAddress()));
    int leftChannel = configuration.getInteger(CONFIGURATION_KEY_LEFT_CHANNEL, -1);
    if (leftChannel == -1) {
        throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_LEFT_CHANNEL);
    }
    int rightChannel = configuration.getInteger(CONFIGURATION_KEY_RIGHT_CHANNEL, -1);
    if (rightChannel == -1) {
        throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_RIGHT_CHANNEL);
    }
    boolean leftInvert = configuration.getBoolean(CONFIGURATION_KEY_LEFT_INVERTED, false);
    boolean rightInvert = configuration.getBoolean(CONFIGURATION_KEY_RIGHT_INVERTED, false);
    PCA9685Servo leftServo = new PCA9685Servo(pcaDevice.getChannel(leftChannel));
    leftServo.setInverted(leftInvert);
    PCA9685Servo rightServo = new PCA9685Servo(pcaDevice.getChannel(rightChannel));
    rightServo.setInverted(rightInvert);
    try {
        tank = new RoboClawRCTank(leftServo, rightServo);
    } catch (IOException e) {
        throw new ConfigurationException("Could not initiate device!", e);
    }
}
Also used : ConfigurationException(com.robo4j.ConfigurationException) PWMPCA9685Device(com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device) IOException(java.io.IOException) RoboClawRCTank(com.robo4j.hw.rpi.pwm.roboclaw.RoboClawRCTank) PCA9685Servo(com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo)

Aggregations

ConfigurationException (com.robo4j.ConfigurationException)1 PCA9685Servo (com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo)1 PWMPCA9685Device (com.robo4j.hw.rpi.i2c.pwm.PWMPCA9685Device)1 RoboClawRCTank (com.robo4j.hw.rpi.pwm.roboclaw.RoboClawRCTank)1 IOException (java.io.IOException)1