root / trunk / code / projects / libdragonfly / encoders.h @ 1462
History | View | Annotate | Download (3.15 KB)
1 |
/**
|
---|---|
2 |
* Copyright (c) 2007 Colony Project
|
3 |
*
|
4 |
* Permission is hereby granted, free of charge, to any person
|
5 |
* obtaining a copy of this software and associated documentation
|
6 |
* files (the "Software"), to deal in the Software without
|
7 |
* restriction, including without limitation the rights to use,
|
8 |
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
* copies of the Software, and to permit persons to whom the
|
10 |
* Software is furnished to do so, subject to the following
|
11 |
* conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be
|
14 |
* included in all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18 |
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19 |
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20 |
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21 |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23 |
* OTHER DEALINGS IN THE SOFTWARE.
|
24 |
**/
|
25 |
|
26 |
|
27 |
/**
|
28 |
* @file encoders.h
|
29 |
* @brief Contains functions for reading encoder values.
|
30 |
*
|
31 |
* Contains high and low level functions for reading encoders
|
32 |
* including reading out total distance covered, and
|
33 |
* eventually velocity.
|
34 |
*
|
35 |
* @author Colony Project, CMU Robotics Club
|
36 |
*/
|
37 |
|
38 |
/**
|
39 |
* @addtogroup encoders
|
40 |
* @{
|
41 |
**/
|
42 |
|
43 |
#ifndef __ENCODERS_H__
|
44 |
#define __ENCODERS_H__
|
45 |
|
46 |
|
47 |
#ifndef LEFT
|
48 |
/** @brief Left wheel **/
|
49 |
#define LEFT 0 |
50 |
#endif
|
51 |
#ifndef RIGHT
|
52 |
/** @brief Right wheel **/
|
53 |
#define RIGHT 1 |
54 |
#endif
|
55 |
|
56 |
/** @brief Max value of valid encoder reading. **/
|
57 |
#define ENCODER_MAX 1024 |
58 |
|
59 |
/** @brief Magnet misaligned - likely distance from encoder problem. **/
|
60 |
#define ENCODER_MAGNET_FAILURE 1025 |
61 |
/** @brief Encoder misaligned - likely on XY plane. **/
|
62 |
#define ENCODER_MISALIGNED 1027 |
63 |
/** @brief Not enough time has passed - encoders not initialized in hardware. **/
|
64 |
#define ENCODER_DATA_NOT_READY 1026 |
65 |
|
66 |
/** @brief delay_ms argument after a full read is complete **/
|
67 |
#define ENCODER_DELAY 20 |
68 |
|
69 |
//Data invalid flags (hardware failure):
|
70 |
#define OCF _BV(4) |
71 |
#define COF _BV(3) |
72 |
|
73 |
//Data invalid alarm (May be invalid):
|
74 |
#define LIN _BV(2) |
75 |
|
76 |
#define MagINCn _BV(1) |
77 |
#define MagDECn _BV(0) |
78 |
|
79 |
#ifdef BUFFER_SIZE
|
80 |
#error BUFFER_SIZE already defined!
|
81 |
#endif
|
82 |
|
83 |
/** @brief Buffer size **/
|
84 |
#define BUFFER_SIZE 46 |
85 |
|
86 |
#define ERR_VEL 1024 |
87 |
|
88 |
/** @brief Initialize encoders. **/
|
89 |
int encoders_init(void); |
90 |
/** @brief Read instantaneous encoder value. **/
|
91 |
int encoder_read(char encoder); |
92 |
|
93 |
/** @brief Get total distance traveled.
|
94 |
* @note Simply calls encoder_get_dx.
|
95 |
**/
|
96 |
int encoder_get_x(char encoder); |
97 |
|
98 |
/** @brief Get instantaneous velocity. **/
|
99 |
int encoder_get_v(char encoder); |
100 |
|
101 |
/** @brief Get total distance traveled. **/
|
102 |
int encoder_get_dx(char encoder); |
103 |
/** @brief Reset distance counter. **/
|
104 |
int encoder_rst_dx(char encoder); |
105 |
/** @brief Get time count: The number of encoder reads that have occurred. **/
|
106 |
int encoder_get_tc(void); |
107 |
/** @brief Reset the time count. **/
|
108 |
int encoder_rst_tc(void); |
109 |
|
110 |
/** @brief Waits for the next n encoder reading, then returns. **/
|
111 |
int encoder_wait( int nReadings ); |
112 |
|
113 |
/**@}**/ //end group |
114 |
|
115 |
#endif
|