Skip to content
Tiogaplanet edited this page Jul 28, 2018 · 4 revisions

Use these functions to employ MiP's radar.


enableRadarMode()

void enableRadarMode()

Description

Switches the MiP robot'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.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;
  }
}

disableRadarMode()

void disableRadarMode()

Description

Switches the MiP robot'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.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 the MiP robot's head mounted IR sensors are in radar mode.

Parameters

None

Returns

  • true if the MiP robot was successfully placed in radar mode with a previous call to enableRadarMode().
  • false if it is not in radar mode.

Example

#include <mip.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 the MiP robot's head mounted IR sensors are inactive, not performing radar measurements or gesture detection.

Parameters

None

Returns

  • true if the MiP robot is not in gesture detection or radar measurement mode.
  • false if it is in gesture detection or radar measurement mode.

Example

#include <mip.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 the MiP robot's head mounted IR sensors. The MiP robot 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 the MiP's head.
  • MIP_RADAR_10CM_30CM if an object has been detected between 10cm and 30cm in front of the MiP's head.
  • MIP_RADAR_0CM_10CM if an object has been detected at less than 10cm in front of the MiP's head.
  • MIP_RADAR_INVALID if the MiP robot hasn't sent back a radar measurement. This could happen for a few reasons:
    • You just called enableRadarMode() and the MiP robot hasn't had a chance to make its first reading yet.
    • The MiP robot 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 the serial monitor in the Arduino IDE that the MiP's radar measurements are getting dropped. See Limitations section above.

Notes

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

Example

#include <mip.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;
  }
}

Clone this wiki locally