Search in sources :

Example 21 with RoboBuilder

use of com.robo4j.RoboBuilder 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();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.RoboBuilder) RoboContext(com.robo4j.RoboContext)

Example 22 with RoboBuilder

use of com.robo4j.RoboBuilder 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 23 with RoboBuilder

use of com.robo4j.RoboBuilder 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 24 with RoboBuilder

use of com.robo4j.RoboBuilder 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 25 with RoboBuilder

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

the class RoboHttpPingPongTest method configurePongSystem.

// Private Methods
private RoboContext configurePongSystem(int totalMessageNumber) throws Exception {
    RoboBuilder builder = new RoboBuilder();
    final HttpPathConfigJsonBuilder pathBuilder = HttpPathConfigJsonBuilder.Builder().addPath(CONTROLLER_PING_PONG, HttpMethod.POST);
    Configuration config = new ConfigurationBuilder().addInteger(PROPERTY_SOCKET_PORT, PORT).addString("packages", PACKAGE_CODECS).addString(PROPERTY_UNIT_PATHS_CONFIG, pathBuilder.build()).build();
    builder.add(HttpServerUnit.class, config, ID_HTTP_SERVER);
    config = new ConfigurationBuilder().addInteger(StringConsumer.PROP_TOTAL_NUMBER_MESSAGES, totalMessageNumber).build();
    builder.add(StringConsumer.class, config, REQUEST_CONSUMER);
    config = new ConfigurationBuilder().addString("target", REQUEST_CONSUMER).build();
    builder.add(HttpCommandTestController.class, config, CONTROLLER_PING_PONG);
    return builder.build();
}
Also used : ConfigurationBuilder(com.robo4j.configuration.ConfigurationBuilder) Configuration(com.robo4j.configuration.Configuration) HttpPathConfigJsonBuilder(com.robo4j.socket.http.util.HttpPathConfigJsonBuilder) 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