irobotcreate is my attempt to create a Command-based API written in Java for the iRobot Create.
My testing device is a raspberry pi connected to the irobot create via the UART over USB.
I have also tested the API on a Lenovo Laptop connected to the irobot create via UART
- Connect the serial usb cable from computer to robot.
- Build the api source code, go to irobotcreate-api directory and
mvn clean install
- Build the shell source code, go to irobotcreate-shell directory and
mvn clean package
- Run the shell
java -jar target/irobotcreate-shell-1.0-SNAPSHOT-jar-with-dependencies.jar
- Choose which serial port to use.
- The first command to be sent should be
start
followed bysafe
orfull
moveto 2000 100
moves the robot 2000mm forward with 100mm/sec velocityturn 180 50
Turn-around using 50mm/sec velocity- And many more.
-
Import maven dependency to your project
<dependency> <groupId>com.kapre</groupId> <artifactId>irobotcreate-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>com.kapre</groupId> <artifactId>irobotcreate-shell</artifactId> <version>1.0-SNAPSHOT</version> </dependency>
-
In your code, create an instance of the SerialPortConnection (to your serial port), and the IRobotCreate.
Connection connection = new SerialPortConnection("/dev/ttyUSB0", DEFAULT_TIMEOUT); IRobotCreate executor = new IRobotCreate(connection); executor.init()
-
Create command instance and execute it (always start with start and setFull).
Command start = CommandFactory.start(); Command setFull = CommandFactory.setFull(); Command moveTo = CommandFactory.moveTo(2000, 100); executor.execute(start); executor.execute(setFull); executor.execute(moveTo);
-
The
CommandFactory
is a factory class for all primitive commands supported byiRobot's Create
. You can also create composite commands (commands made up of several primitives). Check theMoveToCommand
class for an example on how to create a composite command.