forked from NoLookPassRobot/NoLookPass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmasterRouteEstimationNode.cpp~
137 lines (100 loc) · 2.58 KB
/
masterRouteEstimationNode.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
#include <ros/ros.h>
#include <no_look_pass_robot/estimation.h>
#include <no_look_pass_robot/master.h>
#include <sstream>
#include <cmath>
#include <deque>
#define DATA_SIZE 10
using namespace std;
no_look_pass_robot::estimation estimation_msg;
struct masterPosition
{
double x;
double y;
};
typedef struct masterPosition masterPos;
class routeEstimation
{
private:
deque <masterPos> masterPos_deque;
double master_path;
public:
routeEstimation()
{
}
~routeEstimation()
{
}
void estimationfunc(no_look_pass_robot::master master_position);
};
void routeEstimation::estimationfunc(no_look_pass_robot::master master_position)
{
masterPos push_temp;
push_temp.x = master_position.x;
push_temp.y = master_position.y;
masterPos_deque.push_back(push_temp);
if(masterPos_deque.size() > DATA_SIZE)
{
double x1, x2, y1, y2, next_x, next_y;
x1 = masterPos_deque.at(masterPos_deque.size() - 2).x;
x2 = masterPos_deque.at(masterPos_deque.size() - 1).x;
y1 = masterPos_deque.at(masterPos_deque.size() - 2).y;
y2 = masterPos_deque.at(masterPos_deque.size() - 1).y;
master_path = (y2 - y1) / (x2 - x1);
next_x = 2*x2 - x1;
next_y = master_path * next_x + y1 - master_path * x1;
estimation_msg.x = next_x;
estimation_msg.y = next_y;
masterPos_deque.pop_front();
}
}
class masterRouteEstimationSubscriber
{
private:
ros::NodeHandle _nh;
ros::Subscriber _submasterRoute;
routeEstimation* estimation;
public:
masterRouteEstimationSubscriber()
{
_submasterRoute = _nh.subscribe(
"/master", 10, &masterRouteEstimationSubscriber::masterRouteEstimation, this
);
estimation = new routeEstimation();
}
void masterRouteEstimation(const no_look_pass_robot::master& masterPositionData);
};
void masterRouteEstimationSubscriber::masterRouteEstimation(const no_look_pass_robot::master& masterPositionData)
{
estimation->estimationfunc(masterPositionData);
}
class masterRouteEstimationPublisher
{
private:
ros::NodeHandle _nh;
ros::Publisher _pub;
public:
masterRouteEstimationPublisher()
{
_pub = _nh.advertise<no_look_pass_robot::estimation>("/estimation_msg", 100, this);
}
void publish();
};
void masterRouteEstimationPublisher::publish()
{
ros::Rate rate(10);
while(ros::ok())
{
ros::spinOnce();
_pub.publish(estimation_msg);
rate.sleep();
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "masterRouteEstimation_node");
masterRouteEstimationSubscriber* subscriber = new masterRouteEstimationSubscriber();
masterRouteEstimationPublisher* publisher = new masterRouteEstimationPublisher();
publisher->publish();
return 0;
}