Search in sources :

Example 6 with RoboContext

use of com.robo4j.core.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;
    if (args.length > 0) {
        startAngle = Float.parseFloat(args[0]);
        if (args.length > 1) {
            range = Float.parseFloat(args[1]);
            if (args.length > 2) {
                step = Float.parseFloat(args[2]);
            }
        }
    }
    Configuration controllerConfiguration = ConfigurationFactory.createEmptyConfiguration();
    controllerConfiguration.setFloat(LaserScannerTestController.CONFIG_KEY_START_ANGLE, startAngle);
    controllerConfiguration.setFloat(LaserScannerTestController.CONFIG_KEY_RANGE, range);
    controllerConfiguration.setFloat(LaserScannerTestController.CONFIG_KEY_STEP, step);
    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();
    InputStream settings = ServoUnitExample.class.getClassLoader().getResourceAsStream("lidarexample.xml");
    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<String> reference = ctx.getReference("controller");
    System.out.println("Starting scanning for ever\nPress enter to quit");
    reference.sendMessage("scan");
    System.in.read();
}
Also used : Configuration(com.robo4j.core.configuration.Configuration) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.core.RoboBuilder) RoboContext(com.robo4j.core.RoboContext) ServoUnitExample(com.robo4j.units.rpi.pwm.ServoUnitExample)

Example 7 with RoboContext

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

the class LF710PadExample method main.

public static void main(String[] args) throws RoboBuilderException, IOException {
    RoboBuilder builder = new RoboBuilder();
    InputStream settings = RoboClassLoader.getInstance().getResource("logitechF710.xml");
    if (settings == null) {
        System.out.println("Could not find the settings for the LogitechF710Pad!");
        System.exit(2);
    }
    builder.add(settings);
    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));
    System.out.println("Press enter to quit!");
    System.in.read();
    ctx.shutdown();
}
Also used : InputStream(java.io.InputStream) RoboBuilder(com.robo4j.core.RoboBuilder) RoboContext(com.robo4j.core.RoboContext)

Example 8 with RoboContext

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

the class CalibrationUtility method main.

public static void main(String[] args) throws RoboBuilderException, FileNotFoundException {
    InputStream settings = ServoUnitExample.class.getClassLoader().getResourceAsStream("servoexample.xml");
    if (args.length != 1) {
        System.out.println("No file specified, using default calibration.xml");
    } else {
        settings = new FileInputStream(args[0]);
    }
    RoboBuilder builder = new RoboBuilder();
    if (settings == null) {
        System.out.println("Could not find the settings for servo calibration test!");
        System.exit(2);
    }
    builder.add(settings);
    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));
    String lastCommand = "";
    Scanner scanner = new Scanner(System.in);
    System.out.println("Type the servo to control and how much to move the servo, between -1 and 1. For example:\npan -1.0\nType q and enter to quit!\n");
    while (!"q".equals(lastCommand = scanner.nextLine())) {
        lastCommand = lastCommand.trim();
        String[] split = lastCommand.split(" ");
        if (split.length != 2) {
            System.out.println("Could not parse " + lastCommand + ". Please try again!");
            continue;
        }
        RoboReference<Float> servoRef = ctx.getReference(split[0]);
        if (servoRef == null) {
            System.out.println("Could not find any robo unit named " + split[0] + ". Please try again!");
            continue;
        }
        try {
            float value = Float.parseFloat(split[1]);
            servoRef.sendMessage(value);
        } catch (Exception e) {
            System.out.println("Could not parse " + split[1] + " as a float number. Error message was: " + e.getMessage() + ". Please try again!");
            continue;
        }
    }
    ctx.shutdown();
    scanner.close();
}
Also used : Scanner(java.util.Scanner) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) RoboBuilder(com.robo4j.core.RoboBuilder) RoboContext(com.robo4j.core.RoboContext) FileInputStream(java.io.FileInputStream) RoboBuilderException(com.robo4j.core.RoboBuilderException) FileNotFoundException(java.io.FileNotFoundException)

Example 9 with RoboContext

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

the class HttpUnitHelperMain method testHttpRealServerTestWithClient.

public void testHttpRealServerTestWithClient() throws Exception {
    RoboBuilder builder = new RoboBuilder().add(RoboClassLoader.getInstance().getResource("robo_image_server.xml"));
    RoboContext roboSystem = builder.build();
    roboSystem.start();
    System.out.println("RoboSystem after start:");
    System.out.println(SystemUtil.printStateReport(roboSystem));
    System.in.read();
}
Also used : RoboBuilder(com.robo4j.core.RoboBuilder) RoboContext(com.robo4j.core.RoboContext)

Aggregations

RoboBuilder (com.robo4j.core.RoboBuilder)9 RoboContext (com.robo4j.core.RoboContext)9 InputStream (java.io.InputStream)6 RoboBuilderException (com.robo4j.core.RoboBuilderException)2 IOException (java.io.IOException)2 RoboReference (com.robo4j.core.RoboReference)1 RoboClassLoader (com.robo4j.core.client.util.RoboClassLoader)1 Configuration (com.robo4j.core.configuration.Configuration)1 SystemUtil (com.robo4j.core.util.SystemUtil)1 GPSEvent (com.robo4j.hw.rpi.serial.gps.GPSEvent)1 Float3D (com.robo4j.math.geometry.Float3D)1 ServoUnitExample (com.robo4j.units.rpi.pwm.ServoUnitExample)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 Scanner (java.util.Scanner)1