Skip to content

Gesture

Tiogaplanet edited this page Oct 9, 2018 · 3 revisions

These functions implement MiP's gesture mode.


enableGestureMode()

void enableGestureMode()

Description

Switches MiP's head mounted IR sensors into gesture detection mode. Once this mode is enabled, you can call availableGestureEvents() and readGestureEvent() to read gesture events as MiP detects them.

Parameters

None

Returns

Nothing

Notes

  • When enableGestureMode() is called, radar mode will be disabled. If you later enable radar mode, gesture mode will be disabled.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("Gesture.ino - Detect gesture and inform user as they occur."));

  Serial.println(F("Waiting for robot to be standing upright."));
  while (!mip.isUpright()) {
    // Waiting
  }
  mip.enableGestureMode();
}

void loop() {
  while (mip.availableGestureEvents() > 0) {
    MiPGesture gesture = mip.readGestureEvent();
    Serial.print(F("Detected "));
    switch (gesture) {
      case MIP_GESTURE_LEFT:
        Serial.println(F("Left gesture!"));
        break;
      case MIP_GESTURE_RIGHT:
        Serial.println(F("Right gesture!"));
        break;
      case MIP_GESTURE_CENTER_SWEEP_LEFT:
        Serial.println(F("Center Sweep Left gesture!"));
        break;
      case MIP_GESTURE_CENTER_SWEEP_RIGHT:
        Serial.println(F("Center Sweep Right gesture!"));
        break;
      case MIP_GESTURE_CENTER_HOLD:
        Serial.println(F("Center Hold gesture!"));
        break;
      case MIP_GESTURE_FORWARD:
        Serial.println(F("Forward gesture!"));
        break;
      case MIP_GESTURE_BACKWARD:
        Serial.println(F("Backward gesture!"));
        break;
      case MIP_GESTURE_INVALID:
        // This shouldn't really happen since mip.availableGestureEvents() returned > 0.
        Serial.println(F("INVALID gesture!"));
        break;
    }
  }
}

disableGestureMode()

void disableGestureMode()

Description

Switches MiP's head mounted IR sensors out of gesture detection mode.

Parameters

None

Returns

Nothing

Notes

  • Calling disableGestureMode() actually disables all IR sensing so it will also shutdown radar mode as well.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("GestureRadarMode.ino - Switches between gesture, radar, and default modes."));

  Serial.println(F("Calling mip.enableRadarMode()"));
  mip.enableRadarMode();
  Serial.print(F("mip.isRadarModeEnabled() = "));
  if (mip.isRadarModeEnabled()) {
    Serial.println(F("true - Pass"));
  } else {
    Serial.println(F("false - Failed"));
  }

  Serial.println(F("Calling mip.disableRadarMode()"));
  mip.disableRadarMode();
  Serial.print(F("mip.isRadarModeEnabled() = "));
  if (mip.isRadarModeEnabled()) {
    Serial.println(F("true - Failed"));
  } else {
    Serial.println(F("false - Pass"));
  }

  Serial.println(F("Calling mip.enableGestureMode()"));
  mip.enableGestureMode();
  Serial.print(F("mip.isGestureModeEnabled() = "));
  if (mip.isGestureModeEnabled()) {
    Serial.println(F("true - Pass"));
  } else {
    Serial.println(F("false - Failed"));
  }

  Serial.println(F("Calling mip.disableGestureMode()"));
  mip.disableGestureMode();
  Serial.print(F("mip.isGestureModeEnabled() = "));
  if (mip.isGestureModeEnabled()) {
    Serial.println(F("true - Failed"));
  } else {
    Serial.println(F("false - Pass"));
  }
  Serial.print(F("mip.areGestureAndRadarModesDisabled() = "));
  if (mip.areGestureAndRadarModesDisabled()) {
    Serial.println(F("true - Pass"));
  } else {
    Serial.println(F("false - Failed"));
  }

  Serial.println();
  Serial.println(F("Sample done."));
}

void loop() {
}

isGestureModeEnabled()

bool isGestureModeEnabled()

Description

Returns whether MiP's head mounted IR sensors are in gesture detection mode.

Parameters

None

Returns

  • true if MiP was successfully placed in gesture detection mode with a previous call to enableGestureMode().
  • false if MiP is not in gesture detection mode.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("GestureRadarMode.ino - Switches between gesture, radar, and default modes."));

  Serial.println(F("Calling mip.enableRadarMode()"));
  mip.enableRadarMode();
  Serial.print(F("mip.isRadarModeEnabled() = "));
  if (mip.isRadarModeEnabled()) {
    Serial.println(F("true - Pass"));
  } else {
    Serial.println(F("false - Failed"));
  }

  Serial.println(F("Calling mip.disableRadarMode()"));
  mip.disableRadarMode();
  Serial.print(F("mip.isRadarModeEnabled() = "));
  if (mip.isRadarModeEnabled()) {
    Serial.println(F("true - Failed"));
  } else {
    Serial.println(F("false - Pass"));
  }

  Serial.println(F("Calling mip.enableGestureMode()"));
  mip.enableGestureMode();
  Serial.print(F("mip.isGestureModeEnabled() = "));
  if (mip.isGestureModeEnabled()) {
    Serial.println(F("true - Pass"));
  } else {
    Serial.println(F("false - Failed"));
  }

  Serial.println(F("Calling mip.disableGestureMode()"));
  mip.disableGestureMode();
  Serial.print(F("mip.isGestureModeEnabled() = "));
  if (mip.isGestureModeEnabled()) {
    Serial.println(F("true - Failed"));
  } else {
    Serial.println(F("false - Pass"));
  }
  Serial.print(F("mip.areGestureAndRadarModesDisabled() = "));
  if (mip.areGestureAndRadarModesDisabled()) {
    Serial.println(F("true - Pass"));
  } else {
    Serial.println(F("false - Failed"));
  }

  Serial.println();
  Serial.println(F("Sample done."));
}

void loop() {
}

availableGestureEvents()

uint8_t availableGestureEvents()

Description

Returns the number of gesture detection events that the library currently has sitting in its queue, ready to be read by calling readGestureEvent(). MiP must have already been placed in gesture detection mode via a call to enableGestureMode() for new gesture detection events to be added to this queue.

Parameters

None

Returns

  • 0 if there are currently no gesture detection events ready for reading. Calling readGestureEvent() now would retun MIP_GESTURE_INVALID.
  • Non-zero value indicates the number of readGestureEvent() calls that can be made and successfully return a valid gesture detection event.

Notes

  • These gesture detection events will be suppressed while MiP is executing long running commands. Shorter commands like mipContinuousDrive() do allow MiP to make the gesture detections.
  • These gesture detection events will only be sent when MiP is actively balancing. They will be suppressed if MiP is laying back on its kickstand for example.
  • The maximum number of gesture detection events that can be queued up between calls to readGestureEvent() is 8. If this count is exceeded, the oldest events will be overwritten.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("Gesture.ino - Detect gesture and inform user as they occur."));

  Serial.println(F("Waiting for robot to be standing upright."));
  while (!mip.isUpright()) {
    // Waiting
  }
  mip.enableGestureMode();
}

void loop() {
  while (mip.availableGestureEvents() > 0) {
    MiPGesture gesture = mip.readGestureEvent();
    Serial.print(F("Detected "));
    switch (gesture) {
      case MIP_GESTURE_LEFT:
        Serial.println(F("Left gesture!"));
        break;
      case MIP_GESTURE_RIGHT:
        Serial.println(F("Right gesture!"));
        break;
      case MIP_GESTURE_CENTER_SWEEP_LEFT:
        Serial.println(F("Center Sweep Left gesture!"));
        break;
      case MIP_GESTURE_CENTER_SWEEP_RIGHT:
        Serial.println(F("Center Sweep Right gesture!"));
        break;
      case MIP_GESTURE_CENTER_HOLD:
        Serial.println(F("Center Hold gesture!"));
        break;
      case MIP_GESTURE_FORWARD:
        Serial.println(F("Forward gesture!"));
        break;
      case MIP_GESTURE_BACKWARD:
        Serial.println(F("Backward gesture!"));
        break;
      case MIP_GESTURE_INVALID:
        // This shouldn't really happen since mip.availableGestureEvents() returned > 0.
        Serial.println(F("INVALID gesture!"));
        break;
    }
  }
}

readGestureEvent()

MiPGesture readGestureEvent()

Description

Returns a gesture detection event from the library's queue. They will be returned in the order that MiP detected them. MiP must have already been placed in gesture detection mode via a call to enableGestureMode() for new gesture detection events to be added to this queue.

Parameters

None

Returns

  • MIP_GESTURE_INVALID if the gesture detection event queue is empty. availableGestureEvents() would return 0 in this scenario.
Other Valid Return Values
MIP_GESTURE_LEFT
MIP_GESTURE_RIGHT
MIP_GESTURE_CENTER_SWEEP_LEFT
MIP_GESTURE_CENTER_SWEEP_RIGHT
MIP_GESTURE_CENTER_HOLD
MIP_GESTURE_FORWARD
MIP_GESTURE_BACKWARD

Notes

  • These gesture detection events will be suppressed while MiP is executing long running commands. Shorter commands like mipContinuousDrive() do allow MiP to make the gesture detections.
  • These gesture detection events will only be sent when MiP is actively balancing. They will be suppressed if MiP is laying back on its kickstand for example.
  • The maximum number of gesture detection events that can be queued up between calls to readGestureEvent() is 8. If this count is exceeded, the oldest events will be overwritten.

Example

#include <mip_esp8266.h>

MiP     mip;

void setup() {
  bool connectResult = mip.begin();
  if (!connectResult) {
    Serial.println(F("Failed connecting to MiP!"));
    return;
  }

  Serial.println(F("Gesture.ino - Detect gesture and inform user as they occur."));

  Serial.println(F("Waiting for robot to be standing upright."));
  while (!mip.isUpright()) {
    // Waiting
  }
  mip.enableGestureMode();
}

void loop() {
  while (mip.availableGestureEvents() > 0) {
    MiPGesture gesture = mip.readGestureEvent();
    Serial.print(F("Detected "));
    switch (gesture) {
      case MIP_GESTURE_LEFT:
        Serial.println(F("Left gesture!"));
        break;
      case MIP_GESTURE_RIGHT:
        Serial.println(F("Right gesture!"));
        break;
      case MIP_GESTURE_CENTER_SWEEP_LEFT:
        Serial.println(F("Center Sweep Left gesture!"));
        break;
      case MIP_GESTURE_CENTER_SWEEP_RIGHT:
        Serial.println(F("Center Sweep Right gesture!"));
        break;
      case MIP_GESTURE_CENTER_HOLD:
        Serial.println(F("Center Hold gesture!"));
        break;
      case MIP_GESTURE_FORWARD:
        Serial.println(F("Forward gesture!"));
        break;
      case MIP_GESTURE_BACKWARD:
        Serial.println(F("Backward gesture!"));
        break;
      case MIP_GESTURE_INVALID:
        // This shouldn't really happen since mip.availableGestureEvents() returned > 0.
        Serial.println(F("INVALID gesture!"));
        break;
    }
  }
}