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