El micromouse sabe donde esta en todo momento

This commit is contained in:
Fernando 2024-08-08 20:18:50 -06:00
parent 03ff9c4ce6
commit d7a4f0cd7a
2 changed files with 33 additions and 1 deletions

View File

@ -77,6 +77,35 @@ void flood(struct maze* maze, struct mmstats* mmstats) {
} }
} }
void follow(struct maze maze, class mmstats mms) {
/* para que el micromouse siga el camino descendente
* se tienen que dar 16 estados, esta funcion lo reduce a 4
*/
int x = mms.x;
int y = mms.y;
int mht = maze.mhtn[x][y];
}
void updatepos(class mmstats* mms) {
/* cada que se ejecuta moveForward la funcion actualiza
* la posicion del micromouse en el valor correspondiente
*/
switch (mms->dir) {
case norte: mms->y++;
break;
case este: mms->x++;
break;
case sur: mms->y--;
break;
case oeste: mms->x--;
break;
}
log(mms->x);
log(mms->y);
log("");
}
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
log("Running..."); log("Running...");
@ -98,5 +127,6 @@ int main(int argc, char* argv[]) {
stats.turn(right); stats.turn(right);
} }
API::moveForward(); API::moveForward();
updatepos(&stats);
} }
} }

4
mms.h
View File

@ -10,7 +10,6 @@ struct dirnode {
class mmstats { class mmstats {
private: private:
dirnode* tail; dirnode* tail;
dirnode* head;
void addnode(int val) { void addnode(int val) {
dirnode* temp = new dirnode(val); dirnode* temp = new dirnode(val);
if (head != nullptr) { if (head != nullptr) {
@ -27,6 +26,7 @@ private:
} }
} }
public: public:
dirnode* head;
int y; int y;
int x; int x;
char dir; char dir;
@ -42,6 +42,7 @@ public:
head = head->next; head = head->next;
else head = head->prev; else head = head->prev;
dir = head->value; dir = head->value;
/*
switch (dir) { switch (dir) {
case norte: log("Norte"); case norte: log("Norte");
break; break;
@ -52,6 +53,7 @@ public:
case oeste: log("Oeste"); case oeste: log("Oeste");
break; break;
} }
*/
} }
}; };