use of com.robo4j.hw.rpi.Servo in project robo4j by Robo4J.
the class ServoTester method main.
public static void main(String[] args) throws IOException, InterruptedException {
System.out.print("Creating device...");
PWMPCA9685Device device = new PWMPCA9685Device();
device.setPWMFrequency(SERVO_FREQUENCY);
System.out.println("done!");
System.out.println("Type the id of the channel of the servo to control and how much to move the servo,\nbetween -1 and 1. For example:\nknown servos=0>15 -1.0\nType q and enter to quit!\n");
System.out.flush();
Scanner scanner = new Scanner(System.in);
String lastCommand;
printPrompt();
while (!"q".equals(lastCommand = scanner.nextLine())) {
lastCommand = lastCommand.trim();
String[] split = lastCommand.split(" ");
if (split.length != 2) {
System.out.println("Could not parse " + lastCommand + ". Please try again!");
continue;
}
int channel = Integer.parseInt(split[0]);
float position = Float.parseFloat(split[1]);
if (channel < 0 || channel > 15) {
System.out.println("Channel number " + channel + " is not allowed! Try again...");
continue;
}
Servo servo = SERVOS[channel];
if (servo == null) {
servo = new PCA9685Servo(device.getChannel(channel));
SERVOS[channel] = servo;
}
if (position < -1 || position > 1) {
System.out.println("Input " + position + " is not allowed! Try again...");
continue;
}
servo.setInput(position);
printPrompt();
}
scanner.close();
System.out.println("Bye!");
}
use of com.robo4j.hw.rpi.Servo 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.Servo 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.Servo 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);
}
Aggregations