Project

General

Profile

Statistics
| Branch: | Revision:

root / scout / libscout / src / behaviors / Odometry.cpp @ 5755691e

History | View | Annotate | Download (1.56 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, "odometry")
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
  motor_fl_dist = scout_enc.fl_ticks - motor_fl_ticks;
26
  motor_fr_dist = scout_enc.fr_ticks - motor_fr_ticks;
27
  motor_bl_dist = scout_enc.bl_ticks - motor_bl_ticks;
28
  motor_br_dist = scout_enc.br_ticks - motor_br_ticks;
29
**/
30

    
31
  left_dist = DIST_PER_TICK*(motor_fl_dist + motor_bl_dist)/2;
32
  right_dist = DIST_PER_TICK*(motor_fr_dist + motor_br_dist)/2;
33

    
34
  total_dist = (left_dist+right_dist)/2;
35
  theta = (right_dist - left_dist)/WHEEL_BASE;
36

    
37
  scout_pos->x = total_dist*sin(theta);
38
  scout_pos->y = total_dist*cos(theta);
39
  scout_pos->theta = theta;
40

    
41
/**
42
  //Save state for next time in.
43
  motor_fl_ticks = scout_enc.fl_ticks;
44
  motor_fr_ticks = scout_enc.fr_ticks;
45
  motor_bl_ticks = scout_enc.bl_ticks;
46
  motor_br_ticks = scout_enc.br_ticks;
47
**/
48
 return;
49
}
50

    
51
void Odometry::run()
52
{
53
  while(ok())
54
  {
55
    get_position();
56
    //TODO publish position
57
    ROS_INFO("Scout is at x: %f  y: %f theta: %f\n", scout_pos->x, scout_pos->y, scout_pos->theta);
58
  }
59
}