-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcallbacks.cpp
More file actions
executable file
·69 lines (51 loc) · 1.72 KB
/
callbacks.cpp
File metadata and controls
executable file
·69 lines (51 loc) · 1.72 KB
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
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
typedef std::function<std::vector<double>(double, double)> CallbackFunction;
class robot {
public:
CallbackFunction m_planner;
// robot(const CallbackFunction &callback) : m_planner(callback) {}
void executePlan(std::vector<double> trajectory) {
std::cout << "robot is traversing the generated trajectory:" << std::endl;
for (const auto &p : trajectory)
std::cout << p << std::endl;
}
void move(double start, double goal) {
std::vector<double> trajectory = m_planner(start, goal);
executePlan(trajectory);
}
};
std::vector<double> planer1(double start, double goal) {
return {start, (start + goal) / 2, goal};
}
std::vector<double> planer2(double start, double goal) {
double step = (goal - start) / 20;
std::vector<double> values;
for (double value = start; value < goal; value += step)
values.push_back(value);
return values;
}
int main() {
std::function<std::vector<double>(double, double)> planer1_ptr =
std::bind(&planer1, std::placeholders::_1, std::placeholders::_2);
// robot myrobot(planer1_ptr);
double start, goal;
start = 1;
goal = 5;
robot myrobot;
myrobot.m_planner = planer1;
myrobot.move(start, goal);
std::function<std::vector<double>(double, double)> planer2_ptr =
std::bind(&planer2, std::placeholders::_1, std::placeholders::_2);
myrobot.m_planner = planer2_ptr;
myrobot.move(start, goal);
auto planer_lambda = [](double start, double goal) {
return std::vector<double>(10, 2);
};
myrobot.m_planner = planer_lambda;
myrobot.move(start, goal);
// robot::m_planner(std::bind(&robot::m_planner, planer2, start, goal));
// myrobot.move(start, goal);
}