Project

General

Profile

Statistics
| Revision:

root / branches / encoders / code / projects / libdragonfly / encoders.h @ 854

History | View | Annotate | Download (1.75 KB)

1
/**
2
 * 
3
 * @file encoders.h
4
 * @brief Contains functions for reading encoder values.
5
 *
6
 * Contains high and low level functions for reading encoders
7
 * including reading out total distance covered, and 
8
 * eventually velocity.
9
 *        
10
 * @author Colony Project, CMU Robotics Club
11
*/
12

    
13
#ifndef __ENCODERS_H__
14
#define __ENCODERS_H__
15

    
16

    
17
#ifndef LEFT
18
        #define LEFT 0
19
#endif
20
#ifndef RIGHT
21
        #define RIGHT 1
22
#endif
23

    
24
/** @brief Magnet misaligned - likely distance from encoder problem. **/
25
#define ENCODER_MAGNET_FAILURE 1025
26
/** @brief Encoder misaligned - likely on XY plane. **/
27
#define ENCODER_MISALIGNED 1027
28
/** @brief Not enough time has passed - encoders not initialized in hardware. **/
29
#define ENCODER_DATA_NOT_READY 1026
30

    
31
//delay_ms argument after a full read is complete
32
#define ENCODER_DELAY 20
33

    
34
#define MIN_V (-100)
35
#define MAX_V 100
36

    
37
//Data invalid flags (hardware failure):
38
#define OCF _BV(4)
39
#define COF _BV(3)
40

    
41
//Data invalid alarm (May be invalid):
42
#define LIN _BV(2)
43

    
44
#define MagINCn _BV(1)
45
#define MagDECn _BV(0)
46

    
47
#define BUFFER_SIZE 23
48

    
49
/** @brief Initialize encoders. **/
50
void encoders_init(void);
51
/** @brief Read instantaneous encoder value. **/
52
int encoder_read(char encoder);
53
/** @brief Currently a stub - DO NOT Use. **/
54
char encoder_direction(char encoder);
55

    
56
/** @brief Get total distance traveled. **/
57
int encoder_get_dx(char encoder);
58
/** @brief Reset distance counter. **/
59
void encoder_rst_dx(char encoder);
60
/** @brief Get time count: The number of encoder reads that have occurred. **/
61
int encoder_get_tc(void);
62
/** @brief Reset the time count. **/
63
void encoder_rst_tc(void);
64

    
65
/** @brief Still untested, so use at your own risk. **/
66
int encoder_get_v(char encoder);
67

    
68
/** @brief Waits for the next encoder reading, then returns. **/
69
void encoder_wait( int nReadings );
70

    
71
#endif