root / branches / ir_branch / code / projects / libdragonfly / encoders.h @ 1572
History | View | Annotate | Download (1.99 KB)
1 | 868 | justin | /**
|
---|---|---|---|
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 | 1371 | chihsiuh | /** @brief Left wheel **/
|
24 | 868 | justin | #define LEFT 0 |
25 | #endif
|
||
26 | #ifndef RIGHT
|
||
27 | 1371 | chihsiuh | /** @brief Right wheel **/
|
28 | 868 | justin | #define RIGHT 1 |
29 | #endif
|
||
30 | |||
31 | 1418 | chihsiuh | /** @brief Max value of valid encoder reading. **/
|
32 | #define ENCODER_MAX 1024 |
||
33 | |||
34 | 868 | justin | /** @brief Magnet misaligned - likely distance from encoder problem. **/
|
35 | #define ENCODER_MAGNET_FAILURE 1025 |
||
36 | /** @brief Encoder misaligned - likely on XY plane. **/
|
||
37 | #define ENCODER_MISALIGNED 1027 |
||
38 | /** @brief Not enough time has passed - encoders not initialized in hardware. **/
|
||
39 | #define ENCODER_DATA_NOT_READY 1026 |
||
40 | |||
41 | 1371 | chihsiuh | /** @brief delay_ms argument after a full read is complete **/
|
42 | 868 | justin | #define ENCODER_DELAY 20 |
43 | |||
44 | //Data invalid flags (hardware failure):
|
||
45 | #define OCF _BV(4) |
||
46 | #define COF _BV(3) |
||
47 | |||
48 | //Data invalid alarm (May be invalid):
|
||
49 | #define LIN _BV(2) |
||
50 | |||
51 | #define MagINCn _BV(1) |
||
52 | #define MagDECn _BV(0) |
||
53 | |||
54 | 1371 | chihsiuh | /** @brief Buffer size **/
|
55 | 1418 | chihsiuh | #define BUFFER_SIZE 46 |
56 | 868 | justin | |
57 | 1418 | chihsiuh | #define ERR_VEL 1024 |
58 | |||
59 | 868 | justin | /** @brief Initialize encoders. **/
|
60 | 1496 | jsexton | void encoders_init(void); |
61 | 868 | justin | /** @brief Read instantaneous encoder value. **/
|
62 | int encoder_read(char encoder); |
||
63 | |||
64 | 1418 | chihsiuh | /** @brief Get total distance traveled.
|
65 | * @note Simply calls encoder_get_dx.
|
||
66 | **/
|
||
67 | int encoder_get_x(char encoder); |
||
68 | |||
69 | /** @brief Get instantaneous velocity. **/
|
||
70 | int encoder_get_v(char encoder); |
||
71 | |||
72 | 868 | justin | /** @brief Get total distance traveled. **/
|
73 | int encoder_get_dx(char encoder); |
||
74 | /** @brief Reset distance counter. **/
|
||
75 | 1496 | jsexton | void encoder_rst_dx(char encoder); |
76 | 868 | justin | /** @brief Get time count: The number of encoder reads that have occurred. **/
|
77 | int encoder_get_tc(void); |
||
78 | /** @brief Reset the time count. **/
|
||
79 | 1496 | jsexton | void encoder_rst_tc(void); |
80 | 868 | justin | |
81 | /** @brief Waits for the next n encoder reading, then returns. **/
|
||
82 | 1496 | jsexton | void encoder_wait( int nReadings ); |
83 | 868 | justin | |
84 | /**@}**/ //end group |
||
85 | |||
86 | #endif |