2. http://robo4j.io
Robo4J
@robo4j
Robo4J
• Easy to use framework for quickly getting started writing Java
for hardware
• Pure Java framework
• Uses Pi4J for GPIO access
• Core components independently usable
5. http://robo4j.io
Robo4J
@robo4j
Hardware Example
public class HelloLcd {
public static void main(String[] args) throws Exception {
AdafruitLcd lcd = LcdFactory.createLCD();
lcd.setBacklight(Color.TEAL);
lcd.setText("Hello World!n-----Robo4J-----");
}
}
Adafruit LCD
6. http://robo4j.io
Robo4J
@robo4j
Robo4J Core
• Defines the core abstractions
• A RoboBuilder builds the RoboContext which is basically a ”robot”
• A RoboContext contains RoboReferences to RoboUnits, which are agents to
which messages can be sent
• Annotations on RoboUnits can change on which queue messages are sent
• Provides network services (autodiscovery, remote messaging)
• Is plain old Java
robo4j-core
10. http://robo4j.io
Robo4J
@robo4j
Typical Project
1. Add the units for your hardware to your configuration
2. Add your own units for controlling behaviour
3. Add a class with a main method where you initialize it all
through a RoboBuilder
4. Run the main method
11. http://robo4j.io
Robo4J
@robo4j
Example
public class LcdExampleDeclarativeMain {
public static void main(String[] args) throws RoboBuilderException, IOException {
RoboBuilder builder = new RoboBuilder().add(getResource("robo4j.xml"));
RoboContext ctx = builder.build();
ctx.start();
ctx.getReference("lcd").sendMessage(
new LcdMessage("Robo4J: Welcome!nPress Up/Down!"));
System.out.println("Press enter to quit!");
System.in.read();
ctx.shutdown();
}
…
}
23. http://robo4j.io
Robo4J
@robo4j
Robo4J Http Communication
• Want to communicate messages to the units over http
• Simply add HttpServerUnit or HttpClientUnit
• Communication is implemented using Java NIO
• Messages by default sent as Json
• Translate from/to Json and the message type accepted by the unit
• Define your codecs: @HttpProducer, @HttpDecoder, @HttpEncoder
24. http://robo4j.io
Robo4J
@robo4j
Robo4J REST
• Default get operation is listing all registered units with their states
• Default post operation for a unit is to send a message to it
• There must be a registered http codec for converting from Json to
the message type for the message to be received
HTTP GET: http://<ROBO4J_IP>:<ROBO4J_PORT>
HTTP POST: http://<ROBO4J_IP>:<ROBO4J_PORT>/units/<unit id>
25. http://robo4j.io
Robo4J
@robo4j
Robo4J Example Get
HTTP GET : http://127.0.0.1:8025
uid: 142d7167-7a43-477e-8dfd-75fdd711b6da,
response: [
{
id:"controller",
com.robo4j.LifecycleState:"STARTED“
},
{
id:"httpServer",
com.robo4j.LifecycleState:"STOPPED"
},
...
]
26. http://robo4j.io
Robo4J
@robo4j
Robo4J Example Post
Example: http://localhost:8025/units/controller
BODY:
{“message”: “push“}
Returns HTTP code 202, if message was deserialized properly and
put on the bus. Returns 404 if unit is not found. Returns 501 if, for
example, no codec is present for the type required by the unit.
29. http://robo4j.io
Robo4J
@robo4j
Robo4J and Lego
Robo4J supports LejOS 9.x on Java 8 and above
Hardware abstractions in robo4j-hw-lego
Units in robo4j-units-lego
Robo4J allows you to mix Lego functionality with other hardware
Turn On the robot named “Number42”
34. http://robo4j.io
Robo4J
@robo4j
Coff-E at JavaOne 2016
The embedded video on this page was removed due to presentation size restrictions.
We’ve uploaded the embedded video on youtube here:
https://www.youtube.com/watch?v=cNLlPGiBzqg
38. http://robo4j.io
Robo4J
@robo4j
Summary
• Robots are fun
• Java and Robo4J lets you build them quickly
• We have just started
(had a bit of a break the past year getting/tending to
babies/toddlers)…
• …but hopefully this helps someone
• Please give us feedback!
Also build a robot. You will not regret it! :)