RoombaJSSC is a JAVA library to control and/or read sensor values of a Roomba (500 & 600 series). This library implements (basically) all the commands and sensors specified in the iRobot Create 2 Open Interace Specification based on Roomba 600.
- Fully implemented iRobot specifications (for roomba 500/600 series)
- Uses the JSSC library for serial communication, which contains native libraries for many platforms:
- Windows (x86, x86-64)
- Linux(x86, x86-64, ARM soft & hard float)
- Solaris(x86, x86-64)
- Mac OS X(x86, x86-64, PPC, PPC64)
- JavaDoc on all methods describing commands & values as given in iRobot specifications.
<dependency>
<groupId>com.maschel</groupId>
<artifactId>roombajssc</artifactId>
<version>1.1.0</version>
</dependency>
You can download the (latest) releases here: Github releases
RoombaJSSC roomba = new RoombaJSSCSerial();
// Get available serial port(s) (not mandatory)
String[] ports = roomba.portList();
// Connect
roomba.connect("/dev/a/serial/port"); // Use portList() to get available ports.
// Make roomba ready for communication & control (safe mode)
roomba.startup();
// Send commands
roomba.clean(); // Roomba will start cleaning
roomba.digitLedsAscii('H', 'E', 'Y', '!'); // Shows message on digit leds
// Read sensors (until key is pressed)
while (System.in.available() == 0) {
roomba.updateSensors(); // Read sensor values from roomba
roomba.sleep(50); // Sleep for AT LEAST 50 ms
// Read sensors
if (roomba.wall())
System.out.println("Wall detected!");
}
// Return to normal (human control) mode
roomba.stop();
// Close serial connection
roomba.disconnect();
This command starts the OI. You must always send the Start command before sending any other commands to the OI.
This command starts the OI of the roomba and puts it in Safe mode which enables user control. Safe mode turns off all LEDs. This will run the 'start' and 'safe' commands.
Note: Wait at least 500ms before sending any commands.
This command stops the OI. All streams will stop and the robot will no longer respond to commands. Use this command when you are finished working with the robot.
This command powers down Roomba. The OI can be in Passive, Safe, or Full mode to accept this command.
Reset the Roomba after error, this will also run the 'start' and 'safe' commands.
This command resets the Roomba, as if you had removed and reinserted the battery.
Note: Wait at least 5000ms before sending any commands.
This command puts the OI into Safe mode, enabling user control of Roomba. It turns off all LEDs. The OI can be in Passive, Safe, or Full mode to accept this command. If a safety condition occurs Roomba reverts automatically to Passive mode.
This command gives you complete control over Roomba by putting the OI into Full mode, and turning off the cliff, wheel-drop and internal charger safety features. That is, in Full mode, Roomba executes any command that you send it, even if the internal charger is plugged in, or command triggers a cliff or wheel drop condition.
This command starts the default cleaning mode. This is the same as pressing Roomba’s Clean button, and will pause a cleaning cycle if one is already in progress.
This command starts the Max cleaning mode, which will clean until the battery is dead. This command will pause a cleaning cycle if one is already in progress.
This command starts the Spot cleaning mode. This is the same as pressing Roomba’s Spot button, and will pause a cleaning cycle if one is already in progress.
This command directs Roomba to drive onto the dock the next time it encounters the docking beams. This is the same as pressing Roomba’s Dock button, and will pause a cleaning cycle if one is already in progress.
public void schedule(boolean sun, boolean mon, boolean tue, boolean wed, boolean thu, boolean fri, boolean sat, int sun_hour, int sun_min, int mon_hour, int mon_min, int tue_hour, int tue_min, int wed_hour, int wed_min, int thu_hour, int thu_min, int fri_hour, int fri_min, int sat_hour, int sat_min) throws IllegalArgumentException
This command sends Roomba a new schedule. To disable scheduled cleaning, send all false and 0s.
- Parameters:
sun
— Enable Sunday schedulingmon
— Enable Monday schedulingtue
— Enable Tuesday schedulingwed
— Enable Wednesday schedulingthu
— Enable Thursday schedulingfri
— Enable Friday schedulingsat
— Enable Saturday schedulingsun_hour
— Sunday scheduled hoursun_min
— Sunday scheduled minutemon_hour
— Monday scheduled hourmon_min
— Monday scheduled minutetue_hour
— Tuesday scheduled hourtue_min
— Tuesday scheduled minutewed_hour
— Wednesday scheduled hourwed_min
— Wednesday scheduled minutethu_hour
— Thursday scheduled hourthu_min
— Thursday scheduled minutefri_hour
— Friday scheduled hourfri_min
— Friday scheduled minutesat_hour
— Saturday scheduled hoursat_min
— Saturday scheduled minute
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
This command sets Roomba’s clock.
- Parameters:
day
— Day number: 0 = Sunday, 1 = Monday ... 6 = Saturdayhour
— Hour in 24hour format 0-23minute
— Minute 0-59
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
This command controls Roomba’s drive wheels.
- Parameters:
-
velocity
— The average velocity of the drive wheels in millimeters per second (mm/s)A positive velocity makes the roomba drive forward, a negative velocity
makes it drive backwards.
min: -500mm/s max: 500mm/s
-
radius
— The radius in millimeters at which Roomba will turnThe longer radii make Roomba drive straighter, while the shorter radii make Roomba turn more.
The radius is measured from the center of the turning circle to the center of Roomba.
min: -2000mm max: 2000mm
Special cases:
- Straight = 32767 or 32768
- Turn in place clockwise = -1
- Turn in place counter-clockwise = 1
-
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
This command lets you control the forward and backward motion of Roomba’s drive wheels independently. A positive velocity makes that wheel drive forward, while a negative velocity makes it drive backward.
- Parameters:
rightVelocity
— Right wheel velocity min: -500 mm/s, max: 500 mm/sleftVelocity
— Left wheel velocity min: -500 mm/s, max: 500 mm/s
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
This command lets you control the raw forward and backward motion of Roomba’s drive wheels independently. A positive PWM makes that wheel drive forward, while a negative PWM makes it drive backward. The PWM values are percentages: 100% is full power forward, -100% is full power reverse.
- Parameters:
rightPWM
— Right wheel PWM (min: -100%, max: 100%)leftPWM
— Left wheel PWM (min: -100%, max: 100%)
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
public void motors(boolean sideBrush, boolean vacuum, boolean mainBrush, boolean sideBrushClockwise, boolean mainBrushOutward)
This command lets you control the forward and backward motion of Roomba’s main brush, side brush, and vacuum independently. Motor velocity cannot be controlled with this command, all motors will run at maximum speed when enabled. The main brush and side brush can be run in either direction. The vacuum only runs forward.
- Parameters:
sideBrush
— Turns on side brushvacuum
— Turns on vacuummainBrush
— Turns on main brushsideBrushClockwise
— if true the side brush will turn clockwise (default: counterclockwise)mainBrushOutward
— if true the side brush will turn outward (default: inward)
public void motorsPWM(int mainBrushPWM, int sideBrushPWM, int vacuumPWM) throws IllegalArgumentException
This command lets you control the speed of Roomba’s main brush, side brush, and vacuum independently. The main brush and side brush can be run in either direction. The vacuum only runs forward. Positive speeds turn the motor in its default (cleaning) direction. Default direction for the side brush is counterclockwise. Default direction for the main brush/flapper is inward. The PWM values are percentages: 100% is full power forward, -100% is full power reverse.
- Parameters:
mainBrushPWM
— Main brush PWM (min: -100%, max: 100%)sideBrushPWM
— Side brush PWM (min: -100%, max: 100%)vacuumPWM
— Vacuum PWM (min: 0%, max: 100%)
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
public void relativeLeds(boolean debris, boolean spot, boolean dock, boolean check_robot, int powerColor, int powerIntensity) throws IllegalArgumentException
This command controls the LEDs common to all models of Roomba 600.
- Parameters:
-
debris
— Turns on the debris LED -
spot
— Turns on the spot LED -
dock
— Turns on the dock LED -
check_robot
— Turns on the check robot LED -
powerColor
— Controls the power LED red color relative to green: 0% = green, 100% = red.Intermediate values are intermediate colors (orange, yellow, etc).
-
powerIntensity
— Controls the intensity of the power led. 0% = off, 100% = full intensity.Intermediate values are intermediate intensities.
-
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
public void leds(boolean debris, boolean spot, boolean dock, boolean check_robot, int powerColor, int powerIntensity) throws IllegalArgumentException
This command controls the LEDs common to all models of Roomba 600.
- Parameters:
-
debris
— Turns on the debris LED -
spot
— Turns on the spot LED -
dock
— Turns on the dock LED -
check_robot
— Turns on the check robot LED -
powerColor
— Controls the power LED color: 0 = green, 255 = red.Intermediate values are intermediate colors (orange, yellow, etc).
-
powerIntensity
— Controls the intensity of the power led. 0 = off, 255 = full intensity.Intermediate values are intermediate intensities.
-
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
public void schedulingLeds(boolean sun, boolean mon, boolean tue, boolean wed, boolean thu, boolean fri, boolean sat, boolean colon, boolean pm, boolean am, boolean clock, boolean schedule)
This command controls the state of the scheduling LEDs present on the Roomba 560 and 570.
- Parameters:
sun
— Turn on scheduling Sunday LEDmon
— Turn on scheduling Monday LEDtue
— Turn on scheduling Tuesday LEDwed
— Turn on scheduling Wednesday LEDthu
— Turn on scheduling Thursday LEDfri
— Turn on scheduling Friday LEDsat
— Turn on scheduling Saturday LEDcolon
— Turn on scheduling Colon LEDpm
— Turn on scheduling PM LEDam
— Turn on scheduling AM LEDclock
— Turn on scheduling clock LEDschedule
— Turn on scheduling schedule LED
public void digitLedsAscii(char char0, char char1, char char2, char char3) throws IllegalArgumentException
This command controls the four 7 segment displays on the Roomba 560 and 570 using ASCII character codes. Because a 7 segment display is not sufficient to display alphabetic characters properly, all characters are an approximation, and not all ASCII codes are implemented. Note: Use a space for an empty character
- Parameters:
char0
— First characterchar1
— Second characterchar2
— Third characterchar3
— Fourth character
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
public void buttons(boolean clean, boolean spot, boolean dock, boolean minute, boolean hour, boolean day, boolean schedule, boolean clock)
This command lets you push Roomba’s buttons. The buttons will automatically release after 1/6th of a second.
- Parameters:
clean
— Presses the clean buttonspot
— Presses the spot buttondock
— Presses the dock buttonminute
— Presses the minute buttonhour
— Presses the hour buttonday
— Presses the day buttonschedule
— Presses the schedule buttonclock
— Presses the clock button
// Fur Elise - Beethoven
RoombaSongNote[] notes = {
new RoombaSongNote(RoombaNote.E2, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.D2Sharp, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.E2, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.D2Sharp, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.E2, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.B1, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.D2, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.C2, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.A1, RoombaNoteDuration.QuarterNote),
new RoombaSongNote(RoombaNote.Pause, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.C1, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.E1, RoombaNoteDuration.
new RoombaSongNote(RoombaNote.A1, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.B1, RoombaNoteDuration.QuarterNote),
new RoombaSongNote(RoombaNote.Pause, RoombaNoteDuration.EightNote),
new RoombaSongNote(RoombaNote.E1, RoombaNoteDuration.EightNote)
};
// Save to song number 0, tempo (in BPM) 125
roomba.song(0, notes, 125);
// Play song 0
roomba.play(0);
This command lets you specify up to four songs to the OI that you can play at a later time. Each song is associated with a song number. The Play command uses the song number to identify your song selection. Each song can contain up to sixteen notes.
- Parameters:
songNumber
— Song number (0-4)notes
— Array of RoombaSongNote (max. 16)tempo
— Tempo in BPM (min. 60 BPM, max. 800 BPM)
- Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
This command lets you select a song to play from the songs added to Roomba using the Song command. You must add one or more songs to Roomba using the Song command in order for the Play command to work.
- Parameters:
songNumber
— Song number (0-4) - Exceptions:
IllegalArgumentException
— One of the arguments is out of bounds.
This command requests new sensor data from the roomba.
Note: Don't invoke this method more than once per 50ms, this will possibly corrupt the sensor data received from the roomba.
- Exceptions:
RuntimeException
— If sensor data updates are requested more than once per 50ms.
Get value of right bumper sensor.
- Returns: True if bumped right
Get value of left bumper sensor.
- Returns: True if bumped left
Get value of right wheel drop sensor.
- Returns: True if wheel drops right
Get value of left wheel drop sensor.
- Returns: True if wheel drops left
Get value of wall sensor.
- Returns: True if wall is seen
Get value of cliff left sensor.
- Returns: True if cliff is seen on left side
Get value of cliff front left sensor.
- Returns: True if cliff is seen on front left
Get value of cliff front right sensor.
- Returns: True if cliff is seen on front right
Get value of cliff right sensor.
- Returns: True if cliff is seen on right side
Get value of virtual wall sensor.
- Returns: True if a virtual wall is detected
Get value of side brush overcurrent sensor.
- Returns: True if side brush overcurrent
Get value of main brush overcurrent sensor.
- Returns: True if main brush overcurrent
Get value of right wheel overcurrent sensor.
- Returns: True if right wheel overcurrent
Get value of left wheel overcurrent sensor.
- Returns: True if left wheel overcurrent
Get the level of the dirt detect sensor.
- Returns: Dirt level (0-255)
Get the character currently received by the omnidirectional receiver.
- Returns: Received character (0-255)
Get the character currently received by the left receiver.
- Returns: Received character (0-255)
Get the character currently received by the right receiver.
- Returns: Received character (0-225)
Check if the clean button is pressed.
- Returns: True if pressed
Check if the spot button is pressed.
- Returns: True if pressed
Check if the dock button is pressed.
- Returns: True if pressed
Check if the minute button is pressed.
- Returns: True if pressed
Check if the hour button is pressed.
- Returns: True if pressed
Check if the day button is pressed.
- Returns: True if pressed
Check if the schedule button is pressed.
- Returns: True if pressed
Check if the clock button is pressed.
- Returns: True if pressed
Get distance travelled in mm since the last sensor data request.
Note: if the sensor data is not polled frequently enough this value is capped at its minimum or maximum (-32768, 32767)
- Returns: Distance travelled in mm since last sensor data request
Get the angle turned in degrees since the last sensor data request. Counter-clockwise angles are positive, clockwise angles are negative.
Note: if the sonsor data is not polled requently enough this value is capped at its minimum or maximum (-32768, 32767)
- Returns: Angle turned in degrees since last sensor data request
Get current charging state
States:
- 0 = Not charging
- 1 = Reconditioning charging
- 2 = Full charging
- 3 = Trickle Charging
- 4 = Waiting
- 5 = Charging Fault condition
- Returns: Charging state (0-5)
Get the voltage of the battery in millivolt (mV)
- Returns: battery voltage (0 - 65535 mV)
Get the current in milliamps (mA) flowing into or out of roomba's battery. Negative currents indicate that the current is flowing out of the battery, as during normal running. Positive currents indicate that the current is flowing into the battery, as during charging.
- Returns: Current in milliamps (-32768, 32768 mA)
Get the temperature of Roomba's battery in degrees Celsius.
- Returns: Battery temperature in degrees Celsius (-128, 127)
Get the estimated charge of the roomba's battery in milliamp-hours (mAh).
- Returns: Estimated battery charge (0 - 65535 mAh)
Get the estimated charge capacity of roomba's battery in milliamp-hours (mAh)
- Returns: Estimated charge capacity (0 - 65535 mAh)
Get the strength of the wall signal.
- Returns: Strength of wall signal (0-1023)
Get the strength of the cliff left signal.
- Returns: Strength of cliff left signal(0-4095)
Get the strength of the cliff front left signal.
- Returns: Strength of cliff front left signal(0-4095)
Get the strength of the cliff front right signal.
- Returns: Strength of cliff front left signal(0-4095)
Get the strength of the cliff right signal.
- Returns: Strength of cliff right signal(0-4095)
Check if the internal charger is present and powered.
- Returns: True if present and powered.
Check if the homebase charger is present and powered.
- Returns: True if present and powered.
Get the current OI mode.
OI modes:
- 0 = Off
- 1 = Passive
- 2 = Safe
- 3 = Full
- Returns: Current OI mode (0-3)
Get the currently selected song.
- Returns: Selected song number (0-15)
Check if a song is playing.
- Returns: True if a song is playing.
Get the velocity most recently requested with a Drive command.
- Returns: Requested velocity (-500 - 500mm/s)
Get the radius most recently requested with a Drive command.
- Returns: Requested radius (-32768 - 32767mm)
Get the right wheel velocity most recently requested with a Drive Direct command.
- Returns: Requested right wheel velocity (-500 - 500mm/s)
Get the left wheel velocity most recently requested with a Drive Direct command.
- Returns: Requested left wheel velocity (-500 - 500mm/s)
Get the (cumulative) number of raw left encoder counts.
Note: This number will roll over to 0 after it passes 65535.
- Returns: Cumulative left encoder counts (0-65535)
Get the (cumulative) number of raw right encoder counts.
Note: This number will roll over to 0 after it passes 65535.
- Returns: Cumulative right encoder counts (0-65535)
Check if the left light bumper detects an obstacle.
- Returns: True on obstacle
Check if the front left light bumper detects an obstacle.
- Returns: True on obstacle
Check if the center left light bumper detects an obstacle.
- Returns: True on obstacle
Check if the center right light bumper detects an obstacle.
- Returns: True on obstacle
Check if the front right light bumper detects an obstacle.
- Returns: True on obstacle
Check if the right light bumper detects an obstacle.
- Returns: True on obstacle
Get the strength of the light bumper left signal.
- Returns: Signal strength (0-4095)
Get the strength of the light bumper front left signal.
- Returns: Signal strength (0-4095)
Get the strength of the light bumper center left signal.
- Returns: Signal strength (0-4095)
Get the strength of the light bumper center right signal.
- Returns: Signal strength (0-4095)
Get the strength of the light bumper front right signal.
- Returns: Signal strength (0-4095)
Get the strength of the light bumper right signal.
- Returns: Signal strength (0-4095)
Get the current being drawn by the left wheel motor in milli Ampere (mA).
- Returns: Motor current in mA (-32768 - 32767 mA)
Get the current being drawn by the right wheel motor in milli Ampere (mA).
- Returns: Motor current in mA (-32768 - 32767 mA)
Get the current being drawn by the main brush motor in milli Ampere (mA).
- Returns: Motor current in mA (-32768 - 32767 mA)
Get the current being drawn by the side brush motor in milli Ampere (mA).
- Returns: Motor current in mA (-32768 - 32767 mA)
Check if the roomba is making forward progress.
Note: this method returns false when the roomba is turning, driving backward, or is not driving.
- Returns: True if making forward progress
MIT LICENSE - Copyright (c) 2016 Geoffrey Mastenbroek