-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathia.cpp
58 lines (51 loc) · 1.66 KB
/
ia.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
#include "ia.hpp"
#define LEFT_SIDE true
IA::IA(MotionBase *mb, Claw *claw){
this->mb = mb;
this->claw = claw;
}
void IA::addCommands(Command commandList[], short listSize){
for(char i = 0; i<listSize; i++){
protocol[i+protocolLenght]=commandList[i];
}
protocolLenght+=listSize;
}
void IA::update(){
//Serial.println(this->toString());
if(!mb->isBusy()/*&&!claw->isBusy()*/){
if(currentCommandIndex+1>=protocolLenght){
return;
}
currentCommandIndex++;
executeCommand(protocol[currentCommandIndex].commandType, protocol[currentCommandIndex].args);
Serial.println(this->toString());
}
}
String IA::toString(){
return "Current ActionType: "+String(protocol[currentCommandIndex].commandType)
+" | arg[0]: "+String(protocol[currentCommandIndex].args[0])
+" | currentCommandIndex: "+String(currentCommandIndex)
+" | maxCommandIndex: "+String(protocolLenght)
+" | mb->isBusy(): "+(mb->isBusy()?"true":"false")
+" | claw->isBusy(): "+(claw->isBusy()?"true":"false");
}
void IA::executeCommand(CommandType command, double args[3]){
// {forward, rotate, load, unload, stack}
if(command==CommandType::forward){
mb->translate(args[0]);
}else if(command==CommandType::rotate){
mb->rotate(args[0]);
}else if(command==CommandType::moveTo){
mb->moveTo(args[0], args[1], args[2]); //X, Y, TETA
}else if(command==CommandType::load){
claw->load();
}else if(command==CommandType::unload){
claw->unload();
}else if(command==CommandType::stack){
claw->stack();
}else if(command==CommandType::buldozer){
//claw.openWide();
}else if(command==CommandType::recalibrate){
mb->translate(args[0]);
}
}