-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle_planner.cpp
More file actions
49 lines (41 loc) · 1.03 KB
/
circle_planner.cpp
File metadata and controls
49 lines (41 loc) · 1.03 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
#include "circle_planner.h"
CirclePlanner::CirclePlanner(string paramfile, string logpath)
: MyPlanner(paramfile, logpath)
{
}
int CirclePlanner::initialize()
{
/* Create the logging file */
if (start_log())
return -1;
/* read the parameter file, logging any errors */
string path = read_config(_param_file);
if (path == "error")
return -1;
// handle last action
this->last.resize(2);
this->last[0] = 0.0;
this->last[1] = 0.0;
return 0;
}
vector<float> CirclePlanner::get_action()
{
// ok, we've updated belief. Now pick action
float ax = -cos(_bearing_max * M_PI/180.0);
float ay = sin(_bearing_max * M_PI/180.0);
// prevent circle from switching directions
// if dot product is negative from last attempt, direction is different
if (ax*last[0] + ay*last[1] < 0.0)
{
ax = -ax;
ay = -ay;
}
vector<float>commands (3);
commands[0] = _uav.max_step * ay;
commands[1] = _uav.max_step * ax;
commands[2] = 0.0;
// preserve current action as last to check for direction
last[0] = ax;
last[1] = ay;
return commands;
}