-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_machine.cpp
47 lines (41 loc) · 1.35 KB
/
state_machine.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
#include "ros/ros.h"
#include "rt2_assignment1/Command.h"
#include "rt2_assignment1/Position.h"
#include "rt2_assignment1/RandomPosition.h"
bool start = false;
bool user_interface(rt2_assignment1::Command::Request &req, rt2_assignment1::Command::Response &res){
if (req.command == "start"){
start = true;
}
else {
start = false;
}
return true;
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "state_machine");
ros::NodeHandle n;
ros::ServiceServer service= n.advertiseService("/user_interface", user_interface);
ros::ServiceClient client_rp = n.serviceClient<rt2_assignment1::RandomPosition>("/position_server");
ros::ServiceClient client_p = n.serviceClient<rt2_assignment1::Position>("/go_to_point");
rt2_assignment1::RandomPosition rp;
rp.request.x_max = 5.0;
rp.request.x_min = -5.0;
rp.request.y_max = 5.0;
rp.request.y_min = -5.0;
rt2_assignment1::Position p;
while(ros::ok()){
ros::spinOnce();
if (start){
client_rp.call(rp);
p.request.x = rp.response.x;
p.request.y = rp.response.y;
p.request.theta = rp.response.theta;
std::cout << "\nGoing to the position: x= " << p.request.x << " y= " <<p.request.y << " theta = " <<p.request.theta << std::endl;
client_p.call(p);
std::cout << "Position reached" << std::endl;
}
}
return 0;
}