FlapSensor & FlapState


level_6


FlapSensor

A FlapSensor represents a sensor associated with a flap that can be open or closed.

See also API doc: FlapSensor.

FlapState

A FlapState is a structure grouping the flap state of a FlapSensor (open or not) and the last time this state changed.

See also API doc: FlapState.

How to use it

Retrieving the charging flap sensor

Pepper is equipped with a charging flap at his back. When his charging flap is open, all autonomous wheel motion is disabled, which makes it useful for the application developer to retrieve the charging flap state. The Power service exposes a flap sensor object representing that charging flap.

val power: Power = qiContext.power
val chargingFlap: FlapSensor? = power.chargingFlap
Power power = qiContext.getPower();
FlapSensor chargingFlap = power.getChargingFlap();

Warning

power.chargingFlap returns null if the robot does not have a charging flap.

Reading a flap state

To read the FlapState of a FlapSensor, use the getState() method:

val flapSensor: FlapSensor = ...
val flapState: FlapState = flapSensor.state
FlapSensor flapSensor = ...;
FlapState flapState = flapSensor.getState();

Listening to flap state changes

To be notified when a FlapSensor is open/closed, use the related FlapSensor.OnStateChangedListener:

val flapSensor: FlapSensor = ...
flapSensor.addOnStateChangedListener { flapState ->
    Log.i(TAG, "Sensor " + (if (flapState.open ) "open" else "closed") + " at ${flapState.time}")
}
FlapSensor flapSensor = ...;
flapSensor.addOnStateChangedListener(flapState -> {
    Log.i(TAG, "Sensor " + (flapState.getOpen() ? "open" : "closed") + " at " + flapState.getTime());
});

See also API doc: FlapSensor.OnStateChangedListener and Timestamps.