Search in sources :

Example 21 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class LF710PadExample method main.

public static void main(String[] args) throws RoboBuilderException, IOException {
    InputStream settings = Thread.currentThread().getContextClassLoader().getResourceAsStream("logitechF710.xml");
    if (settings == null) {
        System.out.println("Could not find the settings for the Gamepad!");
        System.exit(2);
    }
    RoboBuilder builder = new RoboBuilder();
    builder.add(settings);
    RoboContext sytem = builder.build();
    System.out.println("... Gamepad buttons Example ...");
    sytem.start();
    System.out.println(SystemUtil.printStateReport(sytem));
    System.out.println("Press <Enter> to quit!");
    System.in.read();
    sytem.shutdown();
    System.out.println("Bye!");
}
Also used : InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 22 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class ServoUnitExample method main.

public static void main(String[] args) throws RoboBuilderException {
    RoboBuilder builder = new RoboBuilder();
    InputStream settings = ServoUnitExample.class.getClassLoader().getResourceAsStream("servoexample.xml");
    if (settings == null) {
        System.out.println("Could not find the settings for the ServoUnitExample!");
        System.exit(2);
    }
    builder.add(settings);
    RoboContext ctx = builder.build();
    RoboReference<Float> panRef = ctx.getReference("pan");
    RoboReference<Float> tiltRef = ctx.getReference("tilt");
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            float panDirection = 1.0f;
            while (!stop) {
                for (int tiltStep = 0; tiltStep < TILT_STEPS; tiltStep++) {
                    // Just move the tilt a quarter of max positive.
                    float tilt = tiltStep / (TILT_STEPS * 4.0f);
                    tiltRef.sendMessage(tilt);
                    for (int panStep = 0; panStep < PAN_STEPS; panStep++) {
                        if (stop) {
                            break;
                        }
                        float pan = (panStep * 2.0f / PAN_STEPS - 1.0f) * panDirection;
                        panRef.sendMessage(pan);
                        sleep(50);
                    }
                    panDirection *= -1;
                }
            }
        }
    });
    thread.setDaemon(true);
    thread.start();
    System.out.println("Press <Enter> to quit!");
    try {
        System.in.read();
    } catch (IOException e) {
        e.printStackTrace();
    }
    stop = true;
    ctx.shutdown();
}
Also used : InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) IOException(java.io.IOException)

Example 23 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class InfraPushTankPlatformExample method main.

public static void main(String[] args) throws Exception {
    final String robo4jSystem = "robo4jSystem.xml";
    final String robo4jConfig = "robo4jInfraPushTankPlatformExample.xml";
    final InputStream systemSystem = InfraSensorExample.class.getClassLoader().getResourceAsStream(robo4jSystem);
    InputStream settings = GripperSonicTankPlatformExample.class.getClassLoader().getResourceAsStream(robo4jConfig);
    if (args.length != 1) {
        System.out.println(String.format("No file specified, using default %s", robo4jConfig));
    } else {
        settings = new FileInputStream(args[0]);
    }
    final RoboBuilder builder = new RoboBuilder(systemSystem);
    if (settings == null) {
        System.out.println("Could not find the settings for test!");
        System.exit(2);
    }
    builder.add(settings);
    RoboContext system = builder.build();
    System.out.println(SystemUtil.printStateReport(system));
    system.start();
    RoboReference<String> lcd = system.getReference("lcd");
    lcd.sendMessage("Robo4J.io");
    RoboReference<String> infraSensor = system.getReference("infraSensor");
    infraSensor.sendMessage("start");
    RoboReference<String> touchUnit = system.getReference("touchUnit");
    touchUnit.sendMessage("START TOUCH");
    shutdown(system);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext) FileInputStream(java.io.FileInputStream)

Example 24 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class RoboDatagramClientTest method datagramClientServerTest.

@Test
void datagramClientServerTest() throws Exception {
    RoboContext producerSystem = RoboContextUtils.loadRoboContextByXml("robo_datagram_client_request_producer_text.xml");
    RoboContext consumerSystem = RoboContextUtils.loadRoboContextByXml("robo_datagram_client_request_consumer_text.xml");
    consumerSystem.start();
    producerSystem.start();
    System.out.println("consumer: State after start:");
    System.out.println(SystemUtil.printStateReport(consumerSystem));
    System.out.println("producer: State after start:");
    System.out.println(SystemUtil.printStateReport(producerSystem));
    RoboReference<Integer> decoratedProducer = producerSystem.getReference("decoratedProducer");
    decoratedProducer.sendMessage(MAX_NUMBER);
    RoboReference<String> stringConsumerProducer = consumerSystem.getReference(StringConsumer.NAME);
    CountDownLatch countDownLatchStringProducer = stringConsumerProducer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get(DEFAULT_TIMEOUT, TimeUnit.MINUTES);
    countDownLatchStringProducer.await(TIMEOUT, TIME_UNIT);
    final int consumerTotalNumber = stringConsumerProducer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get(DEFAULT_TIMEOUT, TimeUnit.MINUTES);
    producerSystem.shutdown();
    consumerSystem.shutdown();
    assertNotNull(consumerTotalNumber);
}
Also used : RoboContext(com.robo4j.RoboContext) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 25 with RoboContext

use of com.robo4j.RoboContext in project robo4j by Robo4J.

the class RoboHttpPingPongTest method pingPongTest.

@Test
void pingPongTest() throws Exception {
    RoboContext systemPong = configurePongSystem(MESSAGES);
    RoboContext systemPing = configurePingSystem();
    systemPong.start();
    System.out.println("systemPong: State after start:");
    System.out.println(SystemUtil.printStateReport(systemPong));
    systemPing.start();
    System.out.println("systemPing: State after start:");
    System.out.println(SystemUtil.printStateReport(systemPing));
    System.out.println("systemPing: send messages");
    RoboReference<Object> decoratedProducer = systemPing.getReference(DECORATED_PRODUCER);
    decoratedProducer.sendMessage(MESSAGES);
    RoboReference<String> pongConsumer = systemPong.getReference(REQUEST_CONSUMER);
    CountDownLatch attributeFuture = pongConsumer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_LATCH).get();
    attributeFuture.await(TIMEOUT, TIME_UNIT);
    System.out.println("systemPing : Going Down!");
    systemPing.stop();
    systemPing.shutdown();
    System.out.println("systemPong : Going Down!");
    final int number = pongConsumer.getAttribute(StringConsumer.DESCRIPTOR_MESSAGES_TOTAL).get();
    systemPong.stop();
    assertEquals(MESSAGES, number);
    System.out.println("PingPong is down!");
    systemPong.shutdown();
}
Also used : RoboContext(com.robo4j.RoboContext) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

RoboContext (com.robo4j.RoboContext)50 RoboBuilder (com.robo4j.RoboBuilder)33 Test (org.junit.jupiter.api.Test)20 InputStream (java.io.InputStream)17 Configuration (com.robo4j.configuration.Configuration)10 ConfigurationBuilder (com.robo4j.configuration.ConfigurationBuilder)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 FileInputStream (java.io.FileInputStream)5 RoboReference (com.robo4j.RoboReference)4 RoboBuilderException (com.robo4j.RoboBuilderException)3 ServerPathConfig (com.robo4j.socket.http.units.ServerPathConfig)3 List (java.util.List)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 HttpMethod (com.robo4j.socket.http.HttpMethod)2 CameraMessage (com.robo4j.socket.http.codec.CameraMessage)2 HttpPathMethodDTO (com.robo4j.socket.http.dto.HttpPathMethodDTO)2