use of com.robo4j.RoboBuilder in project robo4j by Robo4J.
the class TankExampleTests method legoTankExampleTest.
@Test
@Disabled("rethink and remove dependency")
void legoTankExampleTest() throws Exception {
RoboBuilder builder = new RoboBuilder();
Configuration config = new ConfigurationBuilder().addString("target", ID_UNIT_CONTROLLER).addInteger("port", PORT).addString("packages", "com.robo4j.units.lego.example.codec").addString(RoboHttpUtils.PROPERTY_UNIT_PATHS_CONFIG, HttpPathConfigJsonBuilder.Builder().addPath(ID_UNIT_CONTROLLER, HttpMethod.GET).build()).build();
builder.add(HttpServerUnit.class, config, ID_HTTP);
builder.add(TankExampleController.class, new ConfigurationBuilder().addString("target", ID_PLATFORM).build(), ID_UNIT_CONTROLLER);
/* platform is listening to the bus */
config = new ConfigurationBuilder().addString("leftMotorPort", "B").addCharacter("leftMotorType", 'N').addString("rightMotorPort", "C").addCharacter("rightMotorType", 'N').build();
builder.add(SimpleTankTestUnit.class, config, ID_PLATFORM);
/* lcd is listening to the bus */
builder.add(LcdTestUnit.class, ID_LCD);
RoboContext context = builder.build();
context.start();
context.getReference(ID_LCD).sendMessage("Press <Enter> to quit!");
System.in.read();
context.shutdown();
}
use of com.robo4j.RoboBuilder 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.RoboBuilder 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.RoboBuilder 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.RoboBuilder 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();
}
Aggregations