root / scout / libscout / src / behaviors / Odometry.cpp @ f34d6221
History | View | Annotate | Download (1.21 KB)
1 |
|
---|---|
2 |
#include "Odometry.h" |
3 |
|
4 |
using namespace std; |
5 |
|
6 |
/** Set up the odometry node and prepare communcations over ROS */
|
7 |
Odometry::Odometry(string scoutname):Behavior(scoutname)
|
8 |
{ |
9 |
scout_pos = new pos;
|
10 |
} |
11 |
|
12 |
/** Query encoders and estimate position based on encoder reading */
|
13 |
void Odometry::get_position()
|
14 |
{ |
15 |
float left_dist, right_dist, total_dist, theta;
|
16 |
// float left_vel, right_vel;
|
17 |
|
18 |
/* TODO: Get current encoder ticks */
|
19 |
encoder_readings scout_enc = encoders->query(); |
20 |
motor_fl_dist = scout_enc.fl_ticks; |
21 |
motor_fr_dist = scout_enc.fr_ticks; |
22 |
motor_bl_dist = scout_enc.bl_ticks; |
23 |
motor_br_dist = scout_enc.br_ticks; |
24 |
|
25 |
// msg_time_in = ros::WallTime::now();
|
26 |
|
27 |
left_dist = DIST_PER_TICK*(motor_fl_dist + motor_bl_dist)/2;
|
28 |
right_dist = DIST_PER_TICK*(motor_fr_dist + motor_br_dist)/2;
|
29 |
|
30 |
// left_vel = left_dist/msg_time_iin;
|
31 |
// right_vel = right_dist/msg_time_in;
|
32 |
|
33 |
total_dist = (left_dist+right_dist)/2;
|
34 |
theta = (right_dist - left_dist)/WHEEL_BASE; |
35 |
|
36 |
scout_pos->x = total_dist*sin(theta); |
37 |
scout_pos->y = total_dist*cos(theta); |
38 |
|
39 |
/* TODO: Publish x and y pos */
|
40 |
return;
|
41 |
} |
42 |
|
43 |
void Odometry::run()
|
44 |
{ |
45 |
while(ok())
|
46 |
{ |
47 |
get_position(); |
48 |
ROS_INFO("Scout is at x: %f y: %f \n", scout_pos->x, scout_pos->y);
|
49 |
} |
50 |
} |