-
Notifications
You must be signed in to change notification settings - Fork 2
/
interface.cpp
203 lines (190 loc) · 7.05 KB
/
interface.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include <ros/ros.h>
#include <iostream>
#include <stdlib.h>
#include <termios.h>
#include <string>
#include <unistd.h>
#include <signal.h>
#define KEYCODE_1 0x31
#define KEYCODE_2 0X32
#define KEYCODE_3 0x33
#define KEYCODE_4 0x34
#define KEYCODE_5 0x35
#define KEYCODE_6 0x36
#define KEYCODE_7 0x37
#define KEYCODE_8 0x38
#define KEYCODE_9 0x39
#define KEYCODE_Q 0X71
static struct termios new1, old;
/* initializes the terminal to new input settings */
void initTermios(int echo)
{
tcgetattr(0, &old); /* grab old terminal i/o settings */
new1 = old; /* make new settings same as old settings */
new1.c_lflag &= ~ICANON; /* disable buffered i/o */
new1.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
tcsetattr(0, TCSANOW, &new1); /* use these new terminal i/o settings now */
}
/* Restore old terminal i/o settings */
void resetTermios()
{
tcsetattr(0, TCSANOW, &old);
}
/* quit the program cleanly and close ros */
void quit()
{
resetTermios(); /* reset the terminal to old settings */
ros::shutdown(); /*shutdown ros */
exit(1); /* exit the system */
}
/* Handles top level control as usual */
int main(int argc, char **argv)
{
/* initialize the ros node */
ros::init(argc, argv, "RosAria_interface");
ros::NodeHandle nh;
/* change the terminal input settings */
initTermios(0);
/* greet user and display selection options */
std::cout
<< "******************************************************************" << std::endl
<< "* ROSARIA CLIENT INTERFACE *" << std::endl
<< "* *" << std::endl
<< "* Welcome to the RosAria client interface! *" << std::endl
<< "* *" << std::endl
<< "* [1] go_three_second *" << std::endl
<< "* [2] spin_clockwise 90' *" << std::endl
<< "* [3] spin_counterclockwise 90' *" << std::endl
<< "* [4] teleop *" << std::endl
<< "* [5] enable/disable print_state *" << std::endl
<< "* [6] enable_motors *" <<
std::endl
<< "* [7] go back, turn left *" <<
std::endl
<< "* [8] go back, turn right *" <<
std::endl
<< "* [9] GPS test *" <<
std::endl
<< "* Press [Q] to close the interface *" << std::endl
<< "******************************************************************" << std::endl;
char select,a,b; /* vars to be used in switch statement */
/* loop to handle user input */
while(ros::ok()){
std::cout << "Please select a program to run, or hit q to quit: "<< std::endl; /* prompt user at start of every loop */
std::cin >> select; /* use standard input to select program to run */
switch(select)
{
case KEYCODE_1:
{
pid_t pid; /*gets the pid */
switch(pid = fork()) /* forks the process */
{
case 0: /* when pid == 0, we have the child process */
b = system("rosrun rosaria_client print_state"); /*run the print_state function */
exit(1); /* exit the child process */
break;
}
a = system("rosrun rosaria_client go_three_second"); /* run option 1*/
a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
}
break;
case KEYCODE_2:
{
pid_t pid; /*gets the pid */
switch(pid = fork()) /* forks the process */
{
case 0: /* when pid == 0, we have the child process */
b = system("rosrun rosaria_client print_state"); /*run the print_state function */
exit(1); /* exit the child process */
break;
}
a = system("rosrun rosaria_client spin_clockwise"); /* run option 2 */
a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
break;
}
case KEYCODE_3:
{
pid_t pid; /*gets the pid */
switch(pid = fork()) /* forks the process */
{
case 0: /* when pid == 0, we have the child process */
b = system("rosrun rosaria_client print_state"); /*run the print_state function */
exit(1); /* exit the child process */
break;
}
a = system("rosrun rosaria_client spin_counterclockwise"); /* run option 3 */
a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
break;
}
case KEYCODE_4:
{
pid_t pid; /*gets the pid */
switch(pid = fork()) /* forks the process */
{
case 0: /* when pid == 0, we have the child process */
b = system("rosrun rosaria_client print_state"); /*run the print_state function */
exit(1); /* exit the child process */
break;
}
a = system("rosrun rosaria_client teleop"); /* run option 4 */
a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
break;
}
case KEYCODE_5:
break;
case KEYCODE_6:
a = system("rosrun rosaria_client enable_motors"); /* run option 6 */
break;
case KEYCODE_7:
{
pid_t pid; /*gets the pid */
switch(pid = fork()) /* forks the process */
{
case 0: /* when pid == 0, we have the child process */
b = system("rosrun rosaria_client print_state"); /*run the print_state function */
exit(1); /* exit the child process */
break;
}
a = system("rosrun rosaria_client go_back_turn_left"); /* run option 7*/
a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
}
break;
case KEYCODE_8:
{
pid_t pid; /*gets the pid */
switch(pid = fork()) /* forks the process */
{
case 0: /* when pid == 0, we have the child process */
b = system("rosrun rosaria_client print_state"); /*run the print_state function */
exit(1); /* exit the child process */
break;
}
a = system("rosrun rosaria_client go_back_turn_right"); /* run option 8*/
a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
}
break;
/* case KEYCODE_9:
{
pid_t pid; /*gets the pid */
/* switch(pid = fork()) /* forks the process */
/* {
case 0: /* when pid == 0, we have the child process */
/* b = system("rosrun rosaria_client print_state"); /*run the print_state function */
/* exit(1); /* exit the child process */
/* break;
/* }
a = system("rosrun rosaria_client gpsExample"); /* run option 9*/
/* a = system("rosnode kill /print_aria_state "); /*kill the ros print_state node */
/* }
break;*/
case KEYCODE_Q: /* quit the interface program */
quit(); /* reset the terminal, then quit + exit the program */
return false;
break;
default: /* in case of user not entering selection from list */
std::cout << "Please enter a number from the list or Q to quit." << std::endl;
break;
}
}
return 1;
}