-
Notifications
You must be signed in to change notification settings - Fork 0
Gesture
These functions implement MiP's gesture mode.
- enableGestureMode()
- disableGestureMode()
- isGestureModeEnabled()
- areGestureAndRadarModesDisabled()
- availableGestureEvents()
- readGestureEvent()
void enableGestureMode()
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.
None
Nothing
- When enableGestureMode() is called, radar mode will be disabled. If you later enable radar mode, gesture 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("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;
}
}
}
void disableGestureMode()
Switches MiP's head mounted IR sensors out of gesture detection mode.
None
Nothing
- Calling disableGestureMode() actually disables all IR sensing so it will also shutdown radar 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 isGestureModeEnabled()
Returns whether MiP's head mounted IR sensors are in gesture detection mode.
None
- 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.
#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() {
}
uint8_t availableGestureEvents()
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.
None
- 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.
- 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.
#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;
}
}
}
MiPGesture readGestureEvent()
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.
None
- 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 |
- 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.
#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;
}
}
}