-
Notifications
You must be signed in to change notification settings - Fork 0
Motion
Use these functions to control MiP's movement.
- continuousDrive()
- distanceDrive()
- turnLeft()
- turnRight()
- driveForward()
- driveBackward()
- stop()
- fallForward()
- fallBackward()
- getUp()
void continuousDrive(int8_t velocity, int8_t turnRate)
Instruct MiP to drive in a particular direction.
- velocity is the forward/reverse velocity. This parameter can have a value between -32 and 32, where -32 is maximum reverse velocity and 32 is maximum forward velocity. A velocity of 0 indicates that no forward/reverse motion is desired at this time.
- turnRate is the amount of left/right turn rate. This parameter can have a value between -32 and 32, where -32 is maximum left turn rate and 32 is maximum right turn velocity. A turn rate of 0 indicates that no left/right turning is desired at this time.
Nothing
- This command must be sent at regular intervals to keep MiP moving in the desired direction. This interval should be ~50 milliseconds. If you send them faster than this interval, they will be ignored by the library so as not to overload MiP.
- When sent at longer intervals MiP's motion will become more jerky as it thinks that there will not be another motion command coming so it starts to stop all motion and then starts moving again once the next command does finally arrive.
- If your robot code is constantly sensing it's environment and using those ongoing sensor readings to make decisions on which direction the robot should be currently headed, then this command will be the most useful for updating MiP's motion in real time.
- Radar measurements and gesture detection events will still be generated by MiP when continuous drive commands are being sent to it.
#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("ContinuousDrive.ino - Use continuousDrive() function. Drive forward with right turn and then backward with left turn."));
}
void loop()
{
static enum States {
RIGHT_TURN,
LEFT_TURN,
DONE
} state = RIGHT_TURN;
static uint32_t startTime = millis();
uint32_t currentTime = millis();
uint32_t elapsedTime = currentTime - startTime;
switch (state) {
case RIGHT_TURN:
if (elapsedTime < 2000) {
// Drive forward at half-speed and turn right at quarter rate.
mip.continuousDrive(16, 8);
} else {
startTime = currentTime;
state = LEFT_TURN;
}
break;
case LEFT_TURN:
if (elapsedTime < 2000) {
// Drive backward at half-speed and turn left at quarter rate.
mip.continuousDrive(-16, -8);
} else {
Serial.println();
Serial.println(F("Sample done."));
state = DONE;
}
break;
default:
break;
}
}
void distanceDrive(MiPDriveDirection driveDirection, uint8_t cm, MiPTurnDirection turnDirection, uint16_t degrees)
Used to queue up a drive/turn command.
- driveDirection specifies the direction MiP should drive: MIP_DRIVE_FORWARD or MIP_DRIVE_BACKWARD.
- cm specifies the number of centimeters MiP should proceed in driveDirection. This parameter can have a value between 0 and 255 cm. Can be set to 0 if only a turn is desired.
- turnDirection specifies the direction MiP should turn: MIP_TURN_LEFT or MIP_TURN_RIGHT.
- degrees is the number of degrees MiP should turn. This parameter can have a value between 0 and 360 degrees. Can be set to 0 if only a forward/reverse drive is desired.
Nothing
- It is possible to queue up to 20 of these distance drive commands in MiP's memory.
- There is no way to specify the speed to be used for driving and/or turning.
- The distance travelled isn't super accurate. Usually it travels further than commanded.
#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("DistanceDrive.ino - Use distanceDrive function. Drive forward, turn 360 degrees in each direction and backward."));
// Queue up multiple commands to run in sequence.
mip.distanceDrive(MIP_DRIVE_FORWARD, 30, MIP_TURN_RIGHT, 0);
mip.distanceDrive(MIP_DRIVE_FORWARD, 0, MIP_TURN_LEFT, 360);
mip.distanceDrive(MIP_DRIVE_FORWARD, 0, MIP_TURN_RIGHT, 360);
mip.distanceDrive(MIP_DRIVE_BACKWARD, 30, MIP_TURN_RIGHT, 0);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void turnLeft(uint16_t degrees, uint8_t speed)
Commands MiP to turn left the desired number of degrees at the desired speed.
- degrees specifies the number of degrees MiP should turn. This parameter can have a value between 0 and 1275 degrees.
- speed is the speed at which the turn should take place. The speed can have a value between 0 and 24 with 0 being the slowest rate and 24 the fastest.
Nothing
#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("TurnLeftRight.ino - Use turnLeft & turnRight() functions. Turn 180 degrees to left and then 180 degrees to right."));
mip.turnLeft(180, 12);
delay(2000);
mip.turnRight(180, 12);
delay(2000);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void turnRight(uint16_t degrees, uint8_t speed)
Commands MiP to turn right the desired number of degrees at the desired speed.
- degrees specifies the number of degrees MiP should turn. This parameter can have a value between 0 and 1275 degrees.
- speed is the speed at which the turn should take place. The speed can have a value between 0 and 24 with 0 being the slowest rate and 24 the fastest.
Nothing
#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("TurnLeftRight.ino - Use turnLeft & turnRight() functions. Turn 180 degrees to left and then 180 degrees to right."));
mip.turnLeft(180, 12);
delay(2000);
mip.turnRight(180, 12);
delay(2000);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void driveForward(uint8_t speed, uint16_t time)
Commands MiP to drive forward.
- speed specifies the speed at which the motion should take place. The speed can have a value between 0 and 30 with 0 being the slowest rate and 30 the fastest.
- time specifies the time to drive forward in milliseconds. This parameter can have a value between 0 and 1785 milliseconds. MiP only supports a granularity of 7 milliseconds for this parameter.
Nothing
#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("DriveForwardBackward.ino - Use driveForward() & driveBackward() functions. Drive ahead and back, 1 second in each direction."));
mip.driveForward(15, 1000);
delay(2000);
mip.driveBackward(15, 1000);
delay(2000);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void driveBackward(uint8_t speed, uint16_t time)
Commands MiP to drive backward.
- speed specifies the speed at which the motion should take place. The speed can have a value between 0 and 30 with 0 being the slowest rate and 30 the fastest.
- time specifies the time to drive backward in milliseconds. This parameter can have a value between 0 and 1785 milliseconds. MiP only supports a granularity of 7 milliseconds for this parameter.
Nothing
#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("DriveForwardBackward.ino - Use driveForward() & driveBackward() functions. Drive ahead and back, 1 second in each direction."));
mip.driveForward(15, 1000);
delay(2000);
mip.driveBackward(15, 1000);
delay(2000);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void stop()
Interrupt and stop MiP's current motion.
None
Nothing
#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("Stop.ino - Use stop() function. Interrupt a 360 degree turn with stop()."));
mip.turnLeft(360, 6);
delay(1000);
mip.stop();
delay(1000);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void fallForward()
Have MiP fall forward.
None
Nothing
#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("FallDown.ino - Fall forward and backward.\n"));
Serial.println(F("Waiting for robot to be standing upright."));
while (!mip.isUpright()) {
// Waiting
}
delay(1000);
Serial.println(F("Falling forward."));
mip.fallForward();
delay(1000);
Serial.println(F("Waiting for robot to be standing upright again."));
while (!mip.isUpright()) {
// Waiting
}
delay(1000);
Serial.println(F("Falling backward."));
mip.fallBackward();
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void fallBackward()
Have MiP fall backward.
None
Nothing
#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("FallDown.ino - Fall forward and backward.\n"));
Serial.println(F("Waiting for MiP to be standing upright."));
while (!mip.isUpright()) {
// Waiting
}
delay(1000);
Serial.println(F("Falling forward."));
mip.fallForward();
delay(1000);
Serial.println(F("Waiting for MiP to be standing upright again."));
while (!mip.isUpright()) {
// Waiting
}
delay(1000);
Serial.println(F("Falling backward."));
mip.fallBackward();
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}
void getUp(MiPGetUp getup = MIP_GETUP_FROM_EITHER)
Attempt to get MiP back up and balancing after falling to the back or front.
- getup specifies in which direction should MiP attempt to get up from: MIP_GETUP_FROM_FRONT, MIP_GETUP_FROM_BACK, or MIP_GETUP_FROM_EITHER. MIP_GETUP_FROM_EITHER is the default if this parameter is omitted.
Nothing
- I haven't seen MiP actually be successful in accomplishing this operation.
#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("GetUp.ino - Use getUp(). Attempt to get up from a front fall."));
mip.fallForward();
delay(3000);
mip.getUp(MIP_GETUP_FROM_FRONT);
delay(3000);
Serial.println();
Serial.println(F("Sample done."));
}
void loop() {
}