-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreadrobot.cpp
63 lines (48 loc) · 1.35 KB
/
threadrobot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "threadrobot.h"
threadrobot::threadrobot(Map *m, Robot *rbt, int t)
{
Myrobot = rbt;
mp = m;
time =t;
}
void threadrobot::run(){
int robox,roboy;
double ang,angrobot,dif;
while(true){
robox=(int) mp->convert2map(Myrobot->getXPos(),1);
roboy=(int) mp->convert2map(Myrobot->getYPos(),0);
ang= mp->angpotencial(robox,roboy);
angrobot= Myrobot->robot.getTh();
mp->vez(robox,roboy);
mp->putPath(robox,roboy);
dif = (ang-angrobot);
//dif = fmod((dif+180+360),360) - 180;
// dif = (ang-angrobot);
// if (dif <-190)
// ang+=360;
// else if(dif>190)
// ang-=360;
// dif = (ang-angrobot);
cout<< ang << " " << angrobot<< " "<< dif<<endl;
if(dif <= 90){
dif = dif * (PI/180);
Myrobot->robot.setVel2(50-50*sin(dif),50+50*sin(dif));
}else{
dif = dif * (PI/180);
Myrobot->robot.setVel2(10-20*sin(dif),10+20*sin(dif));
}
//if(dif>5 || dif<-5){
// if (dif>0 && dif<90)
// Myrobot->rotaciona(-50,1);
// else if(dif>0 && dif>= 90)
// Myrobot->rotaciona(-50,0);
// else if (dif<0 && dif>-90)
// Myrobot->rotaciona(50,1);
// else if (dif<0 && dif<=-90)
// Myrobot->rotaciona(50,0);
// }
// else
// Myrobot->Move(80,80);
QThread::msleep(time);
}
}