Skip to content

rob interface library

Tami-32 edited this page Jul 28, 2021 · 3 revisions

Rob Interface library

If there is a base module in the ROBOBO Framework, it is the ROB Interface Module. It provides the connection between the smartphone and the Robobo Base.

The Robobo Base robotic platform has the next set of sensors and actuators:

  • 8 IR sensors for obstacle detection.
  • Simultaneous two wheel movement.
  • Pan/Tilt movement for the smartphone.
  • 7 LED lights.

Situated as shown in the next figure:

This module provides an interface to control those sensors and actuators. It does so by implementing a custom Bluetooth serial protocol that allows the smartphone to talk with the Robobo Base and viceversa. Furthermore, it provides a simplified movement module to perform basic movements with the Robobo Base.

In order to use these modules it is required to import the next library in your App:

compile 'com.mytechia:robobo-rob-module:x.x.x'

And also import the modules in the "modules.properties" file:

robobo.module.0=com.mytechia.robobo.rob.BluetoothRobInterfaceModule
robobo.module.1=com.mytechia.robobo.rob.movement.DefaultRobMovementModule

For debugging purposes there is a "fake" version of the ROB Interface Module, called "DummyRobInterfaceModule" that does not required the Robobo Base, and only outputs the operations executed as text in the console. It can be useful to debug or test applications without a physical Robobo Base. It can be used by setting the "modules.properties" as next:

robobo.module.0=com.mytechia.robobo.rob.DummyRobInterfaceModule
robobo.module.1=com.mytechia.robobo.rob.movement.DefaultRobMovementModule

The interface of IRob is the following:

public interface IRob {

    void setLEDColor(int led, Color color) throws CommunicationException, IllegalArgumentException;

    void setLEDsMode(LEDsModeEnum mode) throws CommunicationException;

    void moveMT(int angVelR, int angleR, int angVelL, int angleL) throws CommunicationException;

    void moveMT(int angVelR, int angVelL, long time) throws CommunicationException ;

    void movePan(int angVel, int angle) throws CommunicationException;

    void moveTilt(int angVel, int angle) throws CommunicationException;

    void setOperationMode(byte operationMode) throws CommunicationException;

    void resetPanTiltOffset() throws CommunicationException;

    List<MotorStatus> getLastStatusMotors();

    List<IRSensorStatus> getLastStatusIRs();

    List<GapStatus> getLastGapsStatus();

    List<FallStatus> getLastStatusFalls();

    List<BumpStatus> getLastStatusBumps();

    List<ObstacleSensorStatus> getLastStatusObstacles();

    BatteryStatus getLastStatusBattery();

    StopWarningType getLastStopWarning();

    void setRobStatusPeriod(int period) throws CommunicationException;

    void addRobStatusListener(IRobStatusListener listener);

    void addStopWarningListener(IStopWarningListener listener);

    void addRobErrorListener(IRobErrorListener listener);

    void removeStopWarningListener(IStopWarningListener listener);

    void removeRobStatusListener(IRobStatusListener listener);

    void removeRobErrorListener(IRobErrorListener listener);

    void configureInfrared(byte infraredId, byte commandCode, byte dataByteLow, byte dataByteHigh) throws CommunicationException;

    void maxValueMotors(int m1Tension, int m1Time,
                    int m2Tension, int m2Time, int panTension, int panTime,
                    int tiltTension, int tiltTime) throws CommunicationException;

    void resetRob() throws CommunicationException;

    void changeRobBTName(String name) throws CommunicationException;

    void resetRobBTName() throws CommunicationException;

    void resetWheelEncoders(RobMotorEnum motor) throws CommunicationException;

}

setLEDColor() and setLEDsMode() are used to change the color of the leds and their behavior respectively.

moveMT() is used to move the two wheels of the Robobo base and has two overcharged implementations, one to move the motorsby time and anothe to ove by degrees.

movePan() and moveTilt() are used to move the PAN/TILT system of the robobo base.

setOperationMode() allows to put the robobo base in different predefined modes, such as the secure navigation mode mentioned before.

resetPanTiltOffset() can be used to force the execution of the pan/tilt calibration.

setRobStatusPeriod() is used to set up the desired interval of the status sent by the robobo base.

changeRobBTName() is used to change the bluetooth identifier of the rob base resetRobBTName() is used to revert it to its factory settings.

resetWheelEncoders() can be used to reset the count of the wheels

The simplified version is the IRobMovementModule and this is its interface:

public interface IRobMovementModule extends IModule {


    public void moveForwardsTime(int velocity, long time) throws InternalErrorException;

    public void moveForwardsAngle(int velocity, int angle) throws InternalErrorException;
    
    public void moveBackwardsTime(int velocity, long time) throws InternalErrorException;
    
    public void moveBackwardsAngle(int velocity, int angle) throws InternalErrorException;

    public void stop() throws InternalErrorException;

    public void turnLeftTime(int velocity, long time) throws InternalErrorException;
    
    public void turnLeftAngle(int velocity, int angle) throws InternalErrorException;

    public void turnRightTime(int velocity, long time) throws InternalErrorException;
    
    public void turnRightAngle(int velocity, int angle) throws InternalErrorException;

    public void turnLeftBackwardsTime(int velocity, long time) throws InternalErrorException;
    
    public void turnRightBackwardsTime(int velocity, long time) throws InternalErrorException;
    
    public void movePan(int velocity, int angle) throws InternalErrorException;

    public void moveTilt(int velocity, int angle) throws InternalErrorException;

    public void movePanTilt(int velocitypan, int anglepan ,int velocitytilt, int angletilt) throws InternalErrorException;

}

This module has methods that help to move the robot in a more high level way. All of the above methods can be substituted with the IRob moveMT() method.

Once the modules are imported in the App, and the framework has been initialized as documented in Howto build ROBOBO Apps, the next step is to request instances of the modules:

try {

       //easy-to-use platform movement module
       this.robMovement = this.roboboManager.getModuleInstance(IRobMovementModule.class);

       //low-level platform control module
       this.robModule = this.roboboManager.getModuleInstance(IRobInterfaceModule.class);
       //get the instance of the ROB interface
       this.rob = this.robModule.getRobInterface();

} catch (ModuleNotFoundException e) {
    showErrorDialog(e.getMessage());
}

And start using them.

The actuators, basically the motors and LEDs, can be controlled by simple calls to operations of the ROB Interface Module like:

//moving the rob forwards with the simplified movement module
this.robMovement.moveForwardsTime(100, 5000);

//turning the rob to the left with the simplified movement module
this.robMovement.turnLeftAngle(50, 720);

//moving the rob forwards in a circle with different values for each wheel motor
//left: velocity-100, 2000ms | right: velocity-50, 2000ms
this.rob.moveMT(2000, 50, 3000); 

//changing rob status reception period
this.rob.setRobStatusPeriod(500); //500 ms

The sensors information is accessed by a listener object that is called periodically with new information. This period is configurable by the programmer:

//listening to periodic rob status messages
this.rob.addRobStatusListener(new IRobStatusListener() {
            @Override
            public void statusMotorsMT(MotorStatus leftMotor, MotorStatus rightMotor) {
                 //MotorStatus objects contain real-time information of the wheel motors
                 //like angular velocity and angle moved since last status
            }

            @Override
            public void statusMotorPan(MotorStatus pan) {
                 //motor status information of the Pan motor
            }

            @Override
            public void statusMotorTilt(MotorStatus tilt) {
                 //motor status information of the Tilt motor
            }

            @Override
            public void statusGaps(Collection<GapStatus> gapStatus) {
                 //Information about "gaps" in the floor detected by the Robobo Base
            }

            @Override
            public void statusFalls(Collection<FallStatus> fallStatus) {
                 //Notifies that the Robobo Base is detecting a possible "fall" with its IR sensors
                 //it monitors 4 possible positions for falling, 2 in the front and 2 in the back
            }

            @Override
            public void statusBattery(BatteryStatus batteryStatus) {
                 //battery status information

            @Override
            public void statusWallConnectionStatus(WallConnectionStatus wallConnectionStatus) {
                 //is the battery charger connected?
            }

            @Override
            public void robCommunicationError(InternalErrorException ex) {
                 //notifies if there was a connection error between the smartphone and the Robobo Base
            }

            @Override
            public void statusIRSensorStatus(final Collection<IRSensorStatus> irSensorStatus) {
                 //raw real-time values of the IR sensors
            }
        });

Currently the Robobo Base has some limits in the values of angular velocity of the wheels and angles supported by the Pan/Tilt. With the last version of the rob-inteface librabray (0.2.8), if you specify a value higher that the limits, it will use the maximum value.

Currently the limits are:

  • Angular velocity for the wheels: -100:100 rpm
  • Pan angle: 10:345 degres
  • Tilt angle: 5:105 degrees

The javadoc documentation of this module can be found here

Clone this wiki locally