mirror of
https://github.com/modelec/odo_STM32.git
synced 2026-01-18 16:27:25 +01:00
read multiple waypoints from USB
This commit is contained in:
@@ -116,12 +116,27 @@ void USB_Comm_Process(void) {
|
||||
USB_Comm_Send("OK;PID\n");
|
||||
}
|
||||
else if (strcmp(token, "WAYPOINT") == 0) {
|
||||
int id = atoi(strtok(NULL, ";"));
|
||||
int type = atoi(strtok(NULL, ";"));
|
||||
float x = atof(strtok(NULL, ";"));
|
||||
float y = atof(strtok(NULL, ";"));
|
||||
float t = atof(strtok(NULL, ";"));
|
||||
Comm_AddWaypoint(id, type, x, y, t);
|
||||
|
||||
while (true) {
|
||||
|
||||
char* idTok = strtok(nullptr, ";");
|
||||
char* typeTok = strtok(nullptr, ";");
|
||||
char* xTok = strtok(nullptr, ";");
|
||||
char* yTok = strtok(nullptr, ";");
|
||||
char* tTok = strtok(nullptr, ";");
|
||||
|
||||
if (!idTok || !typeTok || !xTok || !yTok || !tTok) {
|
||||
break;
|
||||
}
|
||||
|
||||
int id = atoi(idTok);
|
||||
int type = atoi(typeTok);
|
||||
float x = atof(xTok);
|
||||
float y = atof(yTok);
|
||||
float theta = atof(tTok);
|
||||
|
||||
Comm_AddWaypoint(id, type, x, y, theta);
|
||||
}
|
||||
USB_Comm_Send("OK;WAYPOINT\n");
|
||||
}
|
||||
else if (strcmp(token, "START") == 0) {
|
||||
|
||||
@@ -78,21 +78,17 @@ void DiffBot::update(float dt) {
|
||||
while (angleError > M_PI) angleError -= 2*M_PI;
|
||||
while (angleError < -M_PI) angleError += 2*M_PI;
|
||||
|
||||
|
||||
/* CHECK IF ON POS THERE
|
||||
* IF final target check if every things is on purpose like x, y, theta
|
||||
* IF not final target check if x AND y are close and if so index++
|
||||
*/
|
||||
|
||||
switch (targets[index].getState()) {
|
||||
case StatePoint::FINAL:
|
||||
|
||||
if (fabs(dx) < 0.005 && fabs(dy) < 0.005 && fabs(angleError) < 0.08 /* 5deg */) {
|
||||
stop(true);
|
||||
|
||||
char log[128];
|
||||
char log[32];
|
||||
sprintf(log, "SET;WAYPOINT;%d\n", index);
|
||||
CDC_Transmit_FS((uint8_t*)log, strlen(log));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -110,7 +106,7 @@ void DiffBot::update(float dt) {
|
||||
while (angleError > M_PI) angleError -= 2*M_PI;
|
||||
while (angleError < -M_PI) angleError += 2*M_PI;
|
||||
|
||||
char log[128];
|
||||
char log[32];
|
||||
sprintf(log, "SET;WAYPOINT;%d\n", index);
|
||||
CDC_Transmit_FS((uint8_t*)log, strlen(log));
|
||||
}
|
||||
@@ -146,7 +142,7 @@ void DiffBot::addTarget(int id, int type, float x, float y, float theta) {
|
||||
targets[id].setState(type == 1 ? StatePoint::FINAL : StatePoint::INTERMEDIAIRE);
|
||||
|
||||
// if (type == StatePoint::FINAL) index = 0;
|
||||
index = 0;
|
||||
if (id <= index) index = 0;
|
||||
|
||||
arrive = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user