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();
}
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!");
}
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();
}
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);
}
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();
}
Aggregations