root / trunk / code / projects / libdragonfly / encoders.h @ 1371
History | View | Annotate | Download (1.7 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 |
/**
|
14 |
* @addtogroup encoders
|
15 |
* @{
|
16 |
**/
|
17 |
|
18 |
#ifndef __ENCODERS_H__
|
19 |
#define __ENCODERS_H__
|
20 |
|
21 |
|
22 |
#ifndef LEFT
|
23 |
/** @brief Left wheel **/
|
24 |
#define LEFT 0 |
25 |
#endif
|
26 |
#ifndef RIGHT
|
27 |
/** @brief Right wheel **/
|
28 |
#define RIGHT 1 |
29 |
#endif
|
30 |
|
31 |
/** @brief Magnet misaligned - likely distance from encoder problem. **/
|
32 |
#define ENCODER_MAGNET_FAILURE 1025 |
33 |
/** @brief Encoder misaligned - likely on XY plane. **/
|
34 |
#define ENCODER_MISALIGNED 1027 |
35 |
/** @brief Not enough time has passed - encoders not initialized in hardware. **/
|
36 |
#define ENCODER_DATA_NOT_READY 1026 |
37 |
|
38 |
/** @brief delay_ms argument after a full read is complete **/
|
39 |
#define ENCODER_DELAY 20 |
40 |
|
41 |
//Data invalid flags (hardware failure):
|
42 |
#define OCF _BV(4) |
43 |
#define COF _BV(3) |
44 |
|
45 |
//Data invalid alarm (May be invalid):
|
46 |
#define LIN _BV(2) |
47 |
|
48 |
#define MagINCn _BV(1) |
49 |
#define MagDECn _BV(0) |
50 |
|
51 |
/** @brief Buffer size **/
|
52 |
#define BUFFER_SIZE 23 |
53 |
|
54 |
/** @brief Initialize encoders. **/
|
55 |
void encoders_init(void); |
56 |
/** @brief Read instantaneous encoder value. **/
|
57 |
int encoder_read(char encoder); |
58 |
|
59 |
/** @brief Get total distance traveled. **/
|
60 |
int encoder_get_dx(char encoder); |
61 |
/** @brief Reset distance counter. **/
|
62 |
void encoder_rst_dx(char encoder); |
63 |
/** @brief Get time count: The number of encoder reads that have occurred. **/
|
64 |
int encoder_get_tc(void); |
65 |
/** @brief Reset the time count. **/
|
66 |
void encoder_rst_tc(void); |
67 |
|
68 |
/** @brief Waits for the next n encoder reading, then returns. **/
|
69 |
void encoder_wait( int nReadings ); |
70 |
|
71 |
/**@}**/ //end group |
72 |
|
73 |
#endif
|