-
Notifications
You must be signed in to change notification settings - Fork 0
Radar
Tiogaplanet edited this page Oct 9, 2018
·
2 revisions
Use these functions to employ MiP's radar.
- enableRadarMode()
- disableRadarMode()
- isRadarModeEnabled()
- areGestureAndRadarModesDisabled()
- readRadar()
void enableRadarMode()
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.
None
Nothing
- When enableRadarMode() is called, gesture mode will be disabled. If you later enable gesture mode, radar mode will be disabled.
#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;
}
}
void disableRadarMode()
Switches MiP's head mounted IR sensors out of radar mode.
None
Nothing
- Calling disableRadarMode() actually disables all IR sensing so it will also shutdown gesture mode as well.
#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() {
}
bool isRadarModeEnabled()
Returns whether MiP's head mounted IR sensors are in radar mode.
None
- true if MiP was successfully placed in radar mode with a previous call to enableRadarMode().
- false if it is not in radar mode.
#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() {
}
bool areGestureAndRadarModesDisabled()
Returns whether MiP's head mounted IR sensors are inactive, not performing radar measurements or gesture detection.
None
- true if MiP is not in gesture detection or radar measurement mode.
- false if MiP is in gesture detection or radar measurement mode.
#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() {
}
MiPRadar readRadar()
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().
None
- 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.
- 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.
#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;
}
}