Search in sources :

Example 16 with RoboBuilder

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();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 17 with RoboBuilder

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();
}
Also used : SystemUtil(com.robo4j.util.SystemUtil) IOException(java.io.IOException) RoboContext(com.robo4j.RoboContext) RoboBuilder(com.robo4j.RoboBuilder) RoboBuilderException(com.robo4j.RoboBuilderException) InputStream(java.io.InputStream) RoboReference(com.robo4j.RoboReference) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 18 with RoboBuilder

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);
}
Also used : RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) GPSEvent(com.robo4j.hw.rpi.gps.GPSEvent)

Example 19 with RoboBuilder

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();
}
Also used : Tuple3f(com.robo4j.math.geometry.Tuple3f) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 20 with RoboBuilder

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();
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) RoboContext(com.robo4j.RoboContext) RoboBuilder(com.robo4j.RoboBuilder)

Aggregations

RoboBuilder (com.robo4j.RoboBuilder)45 RoboContext (com.robo4j.RoboContext)33 InputStream (java.io.InputStream)20 Configuration (com.robo4j.configuration.Configuration)18 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)17 Test (org.junit.jupiter.api.Test)13 FileInputStream (java.io.FileInputStream)5 HttpPathConfigJsonBuilder (com.robo4j.socket.http.util.HttpPathConfigJsonBuilder)4 RoboBuilderException (com.robo4j.RoboBuilderException)3 IOException (java.io.IOException)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 StringConsumer (com.robo4j.StringConsumer)2 BiColor (com.robo4j.hw.rpi.i2c.adafruitbackpack.BiColor)2 DataEvent3f (com.robo4j.hw.rpi.imu.bno.DataEvent3f)2 CameraMessage (com.robo4j.socket.http.codec.CameraMessage)2 BnoRequest (com.robo4j.units.rpi.imu.BnoRequest)2 FileNotFoundException (java.io.FileNotFoundException)2 Path (java.nio.file.Path)2 Scanner (java.util.Scanner)2