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);
}
}
Aggregations