forked from Maramall/MUR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgv2
More file actions
32 lines (30 loc) · 757 Bytes
/
algv2
File metadata and controls
32 lines (30 loc) · 757 Bytes
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
#include <murAPI.hpp>
int main()
{
const int toSet = 70;
const int kP = 7;
int curs = 1, v = -30;
mur.addDetectorToList(Object::RECTANGLE, 0);
bool isLineDetected = false;
while (true){
int yaw = mur.getYaw();
int u =((540-yaw+curs)%360-180);
mur.setPortA(v-u);
mur.setPortB(v+u);
int depth = mur.getInputAOne();
int power = (depth - toSet) * kP * (-1);
mur.setPortC(power);
if(!isLineDetected)
for(auto obj : mur.getDetectedObjectsList(0)) {
if(obj.type == Object::RECTANGLE){
if(obj.angle <90){
curs +=obj.angle;
}else{
curs -=obj.angle - 90;
}
isLineDetected = true;
}
}
}
return 0;
}