-
Notifications
You must be signed in to change notification settings - Fork 0
/
OA_Navigation.cpp
140 lines (113 loc) · 3.55 KB
/
OA_Navigation.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <iostream>
#include <alerror/alerror.h>
#include <alproxies/alautonomousmovesproxy.h>
#include <alproxies/alsonarproxy.h>
#include <alproxies/almotionproxy.h>
#include <alproxies/almemoryproxy.h>
#include <alproxies/alledsproxy.h>
using namespace std;
string pip;
int pport;
void parsingArguments(int argc, char* argv[]);
void moveForward();
void rotateLeft();
void rotateRight();
void initMotors();
void stopMotors();
void moveBackward();
int main(int argc, char* argv[]){
parsingArguments(argc,argv);
AL::ALSonarProxy sonarproxy(pip,pport);
AL::ALMemoryProxy memproxy(pip,pport);
//AL::ALMotionProxy motion(pip,pport);
//sonarproxy.subscribe("myApp");
while(true){
AL::ALValue isFrontTouchedVal = memproxy.getData("FrontTactilTouched");
AL::ALValue isMiddleTouchedVal = memproxy.getData("MiddleTactilTouched");
char c;
if(isFrontTouchedVal == AL::ALValue(1.0)){
while(isMiddleTouchedVal != AL::ALValue(1.0)){
AL::ALValue sonarLeftValue = memproxy.getData("SonarLeftDetected");
AL::ALValue sonarRightValue = memproxy.getData("SonarRightDetected");
// isMiddleTouchedVal = memproxy.getData("MiddleTactilTouched");
cout << "left ::" << memproxy.getData("SonarLeftDetected").toString() << endl;
cout << "Right::" << memproxy.getData("SonarRightDetected").toString()<< endl;
qi::os::sleep(1);
/* if( !(sonarLeftValue < AL::ALValue(0.2)) && !(sonarRightValue < AL::ALValue(0.2)) ){
if(c == 'l'){
motion.moveToward(0,0.2,0);
qi::os::sleep(5);
}
if(c == 'r'){
motion.moveToward(0,-0.2,0);
qi::os::sleep(5);
}
motion.moveToward(0.2,0,0);
c = '.';
}
if(sonarLeftValue < AL::ALValue(0.2) ){
std::cout << "obstacle*" <<endl;
motion.stopMove();
motion.moveToward(-0.2,0,0);
qi::os::sleep(5);
c= 'l';
}
if(sonarRightValue < AL::ALValue(0.2) ){
std::cout << "obstacle**" <<endl;
motion.stopMove();
motion.moveToward(-0.2,0,0);
qi::os::sleep(5);
c='r';
}*/
}
}
}
//sonarproxy.unsubscribe("myApp");
return 0;
}
void parsingArguments(int argc, char* argv[]){
// command line parse option
// check the number of arguments
if (argc != 1 && argc != 3 && argc != 5)
{
std::cerr << "Wrong number of arguments!" << std::endl;
std::cerr << "Usage: mymodule [--pip robot_ip] [--pport port]" << std::endl;
exit(2);
}
// if there is only one argument it should be IP or PORT
if (argc == 3)
{
if (std::string(argv[1]) == "--pip")
pip = argv[2];
else if (std::string(argv[1]) == "--pport")
pport = atoi(argv[2]);
else
{
std::cerr << "Wrong number of arguments!" << std::endl;
std::cerr << "Usage: mymodule [--pip robot_ip] [--pport port]" << std::endl;
exit(2);
}
}
// Sepcified IP or PORT for the connection
if (argc == 5)
{
if (std::string(argv[1]) == "--pport"
&& std::string(argv[3]) == "--pip")
{
pport = atoi(argv[2]);
pip = argv[4];
}
else if (std::string(argv[3]) == "--pport"
&& std::string(argv[1]) == "--pip")
{
pport = atoi(argv[4]);
pip = argv[2];
}
else
{
std::cerr << "Wrong number of arguments!" << std::endl;
std::cerr << "Usage: mymodule [--pip robot_ip] [--pport port]" << std::endl;
exit(2);
}
}
}