use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class AccelerometerExample method main.
public static void main(String[] args) throws RoboBuilderException, IOException {
RoboBuilder builder = new RoboBuilder();
InputStream settings = Thread.currentThread().getContextClassLoader().getResourceAsStream("accelerometerexample.xml");
if (settings == null) {
System.out.println("Could not find the settings for the GyroExample!");
System.exit(2);
}
builder.add(settings);
builder.add(AccelerometerProcessor.class, ID_PROCESSOR);
RoboContext ctx = builder.build();
System.out.println("State before start:");
System.out.println(SystemUtil.printStateReport(ctx));
ctx.start();
System.out.println("State after start:");
System.out.println(SystemUtil.printStateReport(ctx));
RoboReference<AccelerometerRequest> accelerometer = ctx.getReference("accelerometer");
RoboReference<AccelerometerEvent> processor = ctx.getReference(ID_PROCESSOR);
System.out.println("Press <Enter> to start!");
System.in.read();
accelerometer.sendMessage(new AccelerometerRequest(processor, true, (Float3D) -> true));
System.out.println("Will report angular changes indefinitely.\nPress <Enter> to quit!");
System.in.read();
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class GPSExample method main.
public static void main(String[] args) throws RoboBuilderException, IOException {
RoboBuilder builder = new RoboBuilder();
builder.add(MtkGPSUnit.class, ID_GPS);
builder.add(GPSProcessor.class, ID_PROCESSOR);
RoboContext ctx = builder.build();
System.out.println("State before start:");
System.out.println(SystemUtil.printStateReport(ctx));
ctx.start();
System.out.println("State after start:");
System.out.println(SystemUtil.printStateReport(ctx));
RoboReference<GPSRequest> gps = ctx.getReference(ID_GPS);
RoboReference<GPSEvent> processor = ctx.getReference(ID_PROCESSOR);
System.out.println("Press <Enter> to start requesting events, then press enter again to stop requesting events!");
System.in.read();
System.out.println("Requesting GPS events! Press <Enter> to stop!");
gps.sendMessage(new GPSRequest(processor, Operation.REGISTER));
System.in.read();
System.out.println("Ending requesting GPS events...");
gps.sendMessage(new GPSRequest(processor, Operation.UNREGISTER));
// Note that we can still get a few more events after this, and that is
// quite fine. ;)
System.out.println("All done! Press <Enter> to quit!");
System.in.read();
System.out.println("Exiting! Bye!");
ctx.shutdown();
// Seems Pi4J keeps an executor with non-daemon threads around after
// we've used the serial port, even after closing it. :/
System.exit(0);
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class GyroExample method main.
public static void main(String[] args) throws RoboBuilderException, IOException {
RoboBuilder builder = new RoboBuilder();
InputStream settings = GyroExample.class.getClassLoader().getResourceAsStream("gyroexample.xml");
if (settings == null) {
System.out.println("Could not find the settings for the GyroExample!");
System.exit(2);
}
builder.add(settings);
builder.add(GyroProcessor.class, ID_PROCESSOR);
RoboContext ctx = builder.build();
System.out.println("State before start:");
System.out.println(SystemUtil.printStateReport(ctx));
ctx.start();
System.out.println("State after start:");
System.out.println(SystemUtil.printStateReport(ctx));
RoboReference<GyroRequest> gyro = ctx.getReference("gyro");
RoboReference<GyroEvent> processor = ctx.getReference(ID_PROCESSOR);
System.out.println("Let the gyro unit be absolutely still, then press enter to calibrate and start!");
System.in.read();
gyro.sendMessage(new GyroRequest(processor, GyroAction.CONTINUOUS, new Tuple3f(1.0f, 1.0f, 1.0f)));
System.out.println("Will report angular changes indefinitely.\nPress <Enter> to quit!");
System.in.read();
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class AdafruitAlphanumericUnitExample method main.
public static void main(String[] args) throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
InputStream settings = AdafruitBiColor24BackpackExample.class.getClassLoader().getResourceAsStream("alphanumericexample.xml");
RoboContext ctx = new RoboBuilder().add(settings).build();
ctx.start();
RoboReference<AlphaNumericMessage> alphaUnit = ctx.getReference("alphanumeric");
AtomicInteger textPosition = new AtomicInteger();
executor.scheduleAtFixedRate(() -> {
if (textPosition.getAndIncrement() >= MESSAGE.length - 1) {
textPosition.set(0);
}
alphaUnit.sendMessage(AlphaNumericMessage.MESSAGE_CLEAR);
byte currentChar = MESSAGE[textPosition.get()];
adjustBuffer(currentChar);
alphaUnit.sendMessage(new AlphaNumericMessage(BackpackMessageCommand.PAINT, BUFFER.clone(), new boolean[4], 0));
alphaUnit.sendMessage(AlphaNumericMessage.MESSAGE_DISPLAY);
}, 1, 500, TimeUnit.MILLISECONDS);
System.out.println("Press enter to quit\n");
System.in.read();
alphaUnit.sendMessage(AlphaNumericMessage.MESSAGE_CLEAR);
alphaUnit.sendMessage(AlphaNumericMessage.MESSAGE_DISPLAY);
executor.shutdown();
ctx.shutdown();
}
use of com.robo4j.RoboContext in project robo4j by Robo4J.
the class LaserScannerExample method main.
public static void main(String[] args) throws RoboBuilderException, IOException {
float startAngle = -45.0f;
float range = 90.0f;
float step = 1.0f;
InputStream settings;
switch(args.length) {
case 1:
settings = Files.newInputStream(Paths.get(args[0]));
break;
case 3:
startAngle = Float.parseFloat(args[0]);
range = Float.parseFloat(args[1]);
step = Float.parseFloat(args[2]);
default:
settings = ServoUnitExample.class.getClassLoader().getResourceAsStream("lidarexample.xml");
}
Configuration controllerConfiguration = new ConfigurationBuilder().addFloat(LaserScannerTestController.CONFIG_KEY_START_ANGLE, startAngle).addFloat(LaserScannerTestController.CONFIG_KEY_RANGE, range).addFloat(LaserScannerTestController.CONFIG_KEY_STEP, step).build();
System.out.println(String.format("Running scans with startAngle=%2.1f, range=%2.1f and step=%2.1f", startAngle, range, step));
RoboBuilder builder = new RoboBuilder();
if (settings == null) {
System.out.println("Could not find the settings for the LaserScannerExample!");
System.exit(2);
}
builder.add(settings).add(LaserScannerTestController.class, controllerConfiguration, "controller").add(LaserScanProcessor.class, "processor");
RoboContext ctx = builder.build();
RoboReference<Float> tiltServo = ctx.getReference("laserscanner.tilt");
tiltServo.sendMessage(Float.valueOf(0));
RoboReference<String> reference = ctx.getReference("controller");
ctx.start();
System.out.println("Starting scanning for ever\nPress <Enter> to quit");
reference.sendMessage("scan");
System.in.read();
}
Aggregations