use of com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo in project robo4j by Robo4J.
the class PCA9685Example method main.
public static void main(String[] args) throws IOException, InterruptedException {
System.out.println("Creating device...");
PWMPCA9685Device device = new PWMPCA9685Device();
device.setPWMFrequency(SERVO_FREQUENCY);
Servo servo0 = new PCA9685Servo(device.getChannel(0));
Servo servo1 = new PCA9685Servo(device.getChannel(1));
PWMChannel motor0 = device.getChannel(2);
PWMChannel motor1 = device.getChannel(3);
System.out.println("Setting start conditions...");
servo0.setInput(0);
servo1.setInput(0);
motor0.setPWM(0, MOTOR_MIN);
motor1.setPWM(0, MOTOR_MIN);
System.out.println("Press <Enter> to run loop!");
System.in.read();
System.out.println("Running perpetual loop...");
while (true) {
servo0.setInput(-1);
servo1.setInput(-1);
motor0.setPWM(0, MOTOR_MEDIUM);
motor1.setPWM(0, MOTOR_MEDIUM);
Thread.sleep(500);
servo0.setInput(1);
;
servo1.setInput(1);
;
motor0.setPWM(0, MOTOR_MAX);
motor1.setPWM(0, MOTOR_MAX);
Thread.sleep(500);
servo0.setInput(0);
servo1.setInput(0);
motor0.setPWM(0, MOTOR_MIN);
motor1.setPWM(0, MOTOR_MIN);
Thread.sleep(1000);
}
}
use of com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo in project robo4j by Robo4J.
the class PCA9685TruckPlatformExample method testMotor.
public static void testMotor(float throttle, float steering, float leg, float shift, int duration) throws IOException, InterruptedException {
System.out.println(String.format("Running for %d ms with throttle %f, steering %f, leg %f, shift %f", duration, throttle, steering, leg, shift));
PWMPCA9685Device device = new PWMPCA9685Device();
device.setPWMFrequency(SERVO_FREQUENCY);
Servo throttleEngine = new PCA9685Servo(device.getChannel(SERVO_THROTTLE));
Servo steeringEngine = new PCA9685Servo(device.getChannel(SERVO_STEERING));
Servo legEngine = new PCA9685Servo(device.getChannel(SERVO_LEG));
Servo shiftEngine = new PCA9685Servo(device.getChannel(SERVO_SHIFT));
VehiclePlatform vehicle = new VehiclePlatform(0, throttleEngine, steeringEngine, legEngine, shiftEngine);
vehicle.setThrottle(throttle);
vehicle.setSteering(steering);
vehicle.setLeg(leg);
vehicle.setShift(shift);
Thread.sleep(duration);
vehicle.setThrottle(0);
vehicle.setSteering(0);
vehicle.setLeg(0);
vehicle.setShift(0);
}
use of com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo in project robo4j by Robo4J.
the class RoboClawRCTankTest method testEngine.
public static void testEngine(float speed, float direction, int duration) throws IOException, InterruptedException {
System.out.println(String.format("Running for %d ms with speed %f and direction %f.", duration, speed, direction));
PWMPCA9685Device device = new PWMPCA9685Device();
device.setPWMFrequency(SERVO_FREQUENCY);
Servo leftEngine = new PCA9685Servo(device.getChannel(6));
Servo rightEngine = new PCA9685Servo(device.getChannel(7));
RoboClawRCTank tank = new RoboClawRCTank(leftEngine, rightEngine);
tank.setDirection(direction);
tank.setSpeed(speed);
Thread.sleep(duration);
tank.setSpeed(0);
}
use of com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo in project robo4j by Robo4J.
the class PCA9685ServoUnit method onInitialization.
/**
* @param configuration
* unit configuration
* @throws ConfigurationException
* exception
*/
@Override
protected void onInitialization(Configuration configuration) throws ConfigurationException {
super.onInitialization(configuration);
PWMPCA9685Device pcaDevice = I2CRegistry.createAndRegisterIfAbsent(getBus(), getAddress(), () -> PWMPCA9685Device.createDevice(getBus(), getAddress()));
channel = configuration.getInteger(CONFIGURATION_KEY_CHANNEL, -1);
if (channel == -1) {
throw ConfigurationException.createMissingConfigNameException(CONFIGURATION_KEY_CHANNEL);
}
servo = new PCA9685Servo(pcaDevice.getChannel(channel));
servo.setTrim(configuration.getFloat(CONFIGURATION_KEY_TRIM, 0f));
servo.setInverted(configuration.getBoolean(CONFIGURATION_KEY_INVERTED, false));
servo.setDualRate(configuration.getFloat(CONFIGURATION_KEY_DUAL_RATE, 1.0f));
servo.setExpo(configuration.getFloat(CONFIGURATION_KEY_EXPO, 0.0f));
shutdownValue = configuration.getFloat(CONFIGURATION_KEY_SHUTDOWN_VALUE, null);
}
use of com.robo4j.hw.rpi.i2c.pwm.PCA9685Servo 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