Skip to content
Tiogaplanet edited this page Oct 9, 2018 · 2 revisions

Use these functions to employ MiP's radar.


enableRadarMode()

void enableRadarMode()

Description

Switches MiP's head mounted IR sensors into radar mode. Once this mode is enabled, your code can call readRadar() to read the radar measurements.

Parameters

None

Returns

Nothing

Notes

  • When enableRadarMode() is called, gesture mode will be disabled. If you later enable gesture mode, radar 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("Radar.ino - Display current radar readings to user."));

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

void loop() {
  static MiPRadar lastRadar = MIP_RADAR_INVALID;
  MiPRadar        currentRadar = mip.readRadar();

  if (currentRadar != MIP_RADAR_INVALID && lastRadar != currentRadar) {
    Serial.print(F("Radar = "));
    switch (currentRadar) {
      case MIP_RADAR_NONE:
        Serial.println(F("None"));
        break;
      case MIP_RADAR_10CM_30CM:
        Serial.println(F("10cm - 30cm"));
        break;
      case MIP_RADAR_0CM_10CM:
        Serial.println(F("0cm - 10cm"));
        break;
      default:
        break;
    }
    lastRadar = currentRadar;
  }
}

disableRadarMode()

void disableRadarMode()

Description

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

Parameters

None

Returns

Nothing

Notes

  • Calling disableRadarMode() actually disables all IR sensing so it will also shutdown gesture 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() {
}

isRadarModeEnabled()

bool isRadarModeEnabled()

Description

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

Parameters

None

Returns

  • true if MiP was successfully placed in radar mode with a previous call to enableRadarMode().
  • false if it is not in radar 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() {
}

areGestureAndRadarModesDisabled()

bool areGestureAndRadarModesDisabled()

Description

Returns whether MiP's head mounted IR sensors are inactive, not performing radar measurements or gesture detection.

Parameters

None

Returns

  • true if MiP is not in gesture detection or radar measurement mode.
  • false if MiP is in gesture detection or radar measurement 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() {
}

readRadar()

MiPRadar readRadar()

Description

Reads the current radar measurement from MiP's head mounted IR sensors. MiP must have already been placed in radar mode via a call to enableRadarMode().

Parameters

None

Returns

  • MIP_RADAR_NONE if no object has been detected in front of MiP's head.
  • MIP_RADAR_10CM_30CM if an object has been detected between 10cm and 30cm in front of MiP's head.
  • MIP_RADAR_0CM_10CM if an object has been detected at less than 10cm in front of MiP's head.
  • MIP_RADAR_INVALID if MiP hasn't sent back a radar measurement. This could happen for a few reasons:
    • You just called enableRadarMode() and MiP hasn't had a chance to make its first reading yet.
    • MiP isn't currently in radar mode. Call enableRadarMode() to let it know that it should start taking these measurements.
    • You are spending so much time sending output back to a serial monitor that MiP's radar measurements are getting dropped. See Limitations section above.

Notes

  • These radar measurements will be suppressed while MiP is executing long running commands. Shorter commands like mipContinuousDrive() do allow MiP to make the measurements.
  • These radar measurements will only be sent when MiP is actively balancing. They will be suppressed if MiP is laying back on its kickstand for example.

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("Radar.ino - Display current radar readings to user."));

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

void loop() {
  static MiPRadar lastRadar = MIP_RADAR_INVALID;
  MiPRadar        currentRadar = mip.readRadar();

  if (currentRadar != MIP_RADAR_INVALID && lastRadar != currentRadar) {
    Serial.print(F("Radar = "));
    switch (currentRadar) {
      case MIP_RADAR_NONE:
        Serial.println(F("None"));
        break;
      case MIP_RADAR_10CM_30CM:
        Serial.println(F("10cm - 30cm"));
        break;
      case MIP_RADAR_0CM_10CM:
        Serial.println(F("0cm - 10cm"));
        break;
      default:
        break;
    }
    lastRadar = currentRadar;
  }
}