Adding proper examples

This commit is contained in:
Lukas Bachschwell 2017-12-12 14:30:03 +01:00
parent 22f78c4bad
commit a16edd7f20
5 changed files with 220 additions and 2 deletions

View File

@ -0,0 +1,42 @@
// Example of the LARS Movement library
#include <LARS.h>
LARS robot; // using default ESP32 pinning values for constructor
boolean walk_forward = false;
boolean walk_backward = false;
boolean hello = false;
boolean turn_left = false;
boolean turn_right = false;
boolean moonwalk = false;
boolean audience = false;
boolean omni = false;
boolean omni_left = false;
boolean dance = false;
boolean upDown = false;
boolean PushUp = false;
void setup() {
Serial.begin(115200);
robot.init();
delay(500);
}
void loop() {
if (walk_forward) robot.walk(0);
else if (walk_backward) robot.walk();
else if (hello) robot.hello();
else if (turn_left) robot.turnL(1, 550);
else if (turn_right) robot.turnR(1, 550);
else if (moonwalk) robot.moonwalk(1, 5000);
else if (audience) robot.wave(1);
else if (dance) robot.dance(1, 600);
else if (omni) robot.omniWalk(1, 600, true, 1);
else if (omni_left) robot.omniWalk(1, 600, false, 1);
else if (PushUp) robot.pushUp(1, 600);
else if (upDown) robot.upDown(1, 5000);
else robot.home();
}

View File

View File

@ -0,0 +1,176 @@
// Example of the LARS Movement library using the ESPUI Webinferface by Lukas Bachschwell
#include <WiFi.h>
#include <ESPUI.h>
#include <LARS.h>
LARS robot; // using default ESP32 pinning values for constructor
boolean walk_forward = false;
boolean walk_backward = false;
boolean hello = false;
boolean turn_left = false;
boolean turn_right = false;
boolean moonwalk = false;
boolean audience = false;
boolean omni = false;
boolean omni_left = false;
boolean dance = false;
boolean upDown = false;
boolean PushUp = false;
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_AP);
WiFi.setHostname("Lars");
WiFi.softAP("Lars");
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
ESPUI.pad("Walking Control", true, &walkingPad, COLOR_CARROT);
ESPUI.pad("Wave some legs", false, &wavePad, COLOR_CARROT);
ESPUI.button("Wave Button", &audienceWaveButton, COLOR_PETERRIVER);
ESPUI.button("MoonWalk Button", &moonWalkButton, COLOR_PETERRIVER);
ESPUI.button("Dance Button", &danceButton, COLOR_PETERRIVER);
ESPUI.button("PushUp Button", &pushUpButton, COLOR_PETERRIVER);
ESPUI.button("upDown Button", &upDownButton, COLOR_PETERRIVER);
ESPUI.button("Slow Turn Right", &slowTurnRight, COLOR_PETERRIVER);
ESPUI.button("Slow Turn left", &slowTurnLeft, COLOR_PETERRIVER);
ESPUI.begin("Crabby Control");
robot.init();
delay(1000);
}
void audienceWaveButton(Control c, int type) {
if (type == B_DOWN) {
audience = true;
}
else {
audience = false;
}
}
void moonWalkButton(Control c, int type) {
if (type == B_DOWN) {
moonwalk = true;
}
else {
moonwalk = false;
}
}
void danceButton(Control c, int type) {
if (type == B_DOWN) {
dance = true;
}
else {
dance = false;
}
}
void pushUpButton(Control c, int type) {
if (type == B_DOWN) {
PushUp = true;
}
else {
PushUp = false;
}
}
void upDownButton(Control c, int type) {
if (type == B_DOWN) {
upDown = true;
}
else {
upDown = false;
}
}
void slowTurnRight(Control c, int type) {
if (type == B_DOWN) {
omni = true;
}
else {
omni = false;
}
}
void slowTurnLeft(Control c, int type) {
if (type == B_DOWN) {
omni_left = true;
}
else {
omni_left = false;
}
}
void walkingPad(Control c, int value) {
switch (value) {
case P_LEFT_DOWN:
turn_left = true;
break;
case P_LEFT_UP:
turn_left = false;
break;
case P_RIGHT_DOWN:
turn_right = true;
break;
case P_RIGHT_UP:
turn_right = false;
break;
case P_FOR_DOWN:
walk_forward = true;
break;
case P_FOR_UP:
walk_forward = false;
break;
case P_BACK_DOWN:
walk_backward = true;
break;
case P_BACK_UP:
walk_backward = false;
break;
case P_CENTER_DOWN:
hello = true;
break;
case P_CENTER_UP:
hello = false;
break;
}
}
void wavePad(Control c, int value) {
switch (value) {
case P_LEFT_DOWN:
robot.wave(1);
break;
case P_RIGHT_DOWN:
robot.wave(2);
break;
case P_FOR_DOWN:
robot.wave(3);
break;
case P_BACK_DOWN:
robot.wave(4);
break;
}
}
void loop() {
if (walk_forward) robot.walk(0);
else if (walk_backward) robot.walk();
else if (hello) robot.hello();
else if (turn_left) robot.turnL(1, 550);
else if (turn_right) robot.turnR(1, 550);
else if (moonwalk) robot.moonwalk(1, 5000);
else if (audience) robot.wave(1);
else if (dance) robot.dance(1, 600);
else if (omni) robot.omniWalk(1, 600, true, 1);
else if (omni_left) robot.omniWalk(1, 600, false, 1);
else if (PushUp) robot.pushUp(1, 600);
else if (upDown) robot.upDown(1, 5000);
else robot.home();
}

View File

@ -16,7 +16,7 @@
*/
LARS::LARS(int FRH = 26, int FLH = 25, int BRH = 17, int BLH = 16, int FRL = 27, int FLL = 5, int BRL = 23, int BLL = 13): reverse{0, 0, 0, 0, 0, 0, 0, 0}, trim{0, 0, 0, 0, 0, 0, 0, 0} {
LARS::LARS(int FRH, int FLH, int BRH, int BLH, int FRL, int FLL, int BRL, int BLL): reverse{0, 0, 0, 0, 0, 0, 0, 0}, trim{0, 0, 0, 0, 0, 0, 0, 0} {
board_pins[FRONT_RIGHT_HIP] = FRH; // front right inner
board_pins[FRONT_LEFT_HIP] = FLH; // front left inner
board_pins[BACK_RIGHT_HIP] = BRH; // back right inner

View File

@ -24,7 +24,7 @@
class LARS {
public:
LARS(int FRH, int FLH, int BRH, int BLH, int FRL, int FLL, int BRL, int BLL);
LARS(int FRH = 26, int FLH = 25, int BRH = 17, int BLH = 16, int FRL = 27, int FLL = 5, int BRL = 23, int BLL = 13);
void init();
void walk(int dir = 1, float steps = 1, float T = 800); // T initial 400
void omniWalk(float steps, float T, bool side, float turn_factor);