root / branches / simulator / projects / libdragonfly / include / encoders.h @ 891
History | View | Annotate | Download (3.66 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 |
* @file encoders.h
|
28 |
* @brief Contains functions for reading encoder values.
|
29 |
*
|
30 |
* Contains high and low level functions for reading encoders
|
31 |
* including reading out total distance covered, and
|
32 |
* eventually velocity.
|
33 |
*
|
34 |
* @author Colony Project, CMU Robotics Club
|
35 |
**/
|
36 |
|
37 |
/**
|
38 |
* @defgroup encoders Encoders
|
39 |
*
|
40 |
* @brief Handles the encoders.
|
41 |
*
|
42 |
* Functions to read from the encoders, which tell
|
43 |
* the distance the robot has travelled.
|
44 |
*
|
45 |
* @{
|
46 |
**/
|
47 |
|
48 |
#ifndef __ENCODERS_H__
|
49 |
#define __ENCODERS_H__
|
50 |
|
51 |
#ifndef LEFT
|
52 |
#define LEFT 0 |
53 |
#endif
|
54 |
#ifndef RIGHT
|
55 |
#define RIGHT 1 |
56 |
#endif
|
57 |
|
58 |
/** @brief Magnet misaligned - likely distance from encoder problem. **/
|
59 |
#define ENCODER_MAGNET_FAILURE 1025 |
60 |
/** @brief Encoder misaligned - likely on XY plane. **/
|
61 |
#define ENCODER_MISALIGNED 1027 |
62 |
/** @brief Not enough time has passed - encoders not initialized in hardware. **/
|
63 |
#define ENCODER_DATA_NOT_READY 1026 |
64 |
|
65 |
//delay_ms argument after a full read is complete
|
66 |
#define ENCODER_DELAY 20 |
67 |
|
68 |
#define MIN_V (-100) |
69 |
#define MAX_V 100 |
70 |
|
71 |
//Data invalid flags (hardware failure):
|
72 |
#define OCF _BV(4) |
73 |
#define COF _BV(3) |
74 |
|
75 |
//Data invalid alarm (May be invalid):
|
76 |
#define LIN _BV(2) |
77 |
|
78 |
#define MagINCn _BV(1) |
79 |
#define MagDECn _BV(0) |
80 |
|
81 |
#define BUFFER_SIZE 23 |
82 |
|
83 |
/**
|
84 |
* @brief Initialize encoders.
|
85 |
*
|
86 |
* Initializes encoder variables and the hardware interface.
|
87 |
**/
|
88 |
void encoders_init(void); |
89 |
|
90 |
/**
|
91 |
* @brief Read instantaneous encoder value.
|
92 |
*
|
93 |
* @param encoder this is the encoder that you want to read. Valid arguments
|
94 |
* are LEFT and RIGHT
|
95 |
*
|
96 |
* @return the value of the specified encoder
|
97 |
**/
|
98 |
int encoder_read(char encoder); |
99 |
|
100 |
/**
|
101 |
* @brief Get total distance traveled.
|
102 |
*
|
103 |
* Gets the total distance covered by the specified encoder (in encoder clicks)
|
104 |
*
|
105 |
* @param encoder the encoder that you want to read, use LEFT or RIGHT
|
106 |
*
|
107 |
* @return The distance covered by the specified encoder.
|
108 |
**/
|
109 |
int encoder_get_dx(char encoder); |
110 |
|
111 |
/**
|
112 |
* @brief Reset distance counter.
|
113 |
*
|
114 |
* Resets the distance accumulator for the specified
|
115 |
* encoder.
|
116 |
*
|
117 |
* @param encoder the encoder that you want to reset distance for
|
118 |
**/
|
119 |
void encoder_rst_dx(char encoder); |
120 |
|
121 |
/**
|
122 |
* @brief Returns the number of encoder reads that have occurred.
|
123 |
*
|
124 |
* Returns the number of encoder reads that have occurred.
|
125 |
*
|
126 |
* @return The time count.
|
127 |
*/
|
128 |
int encoder_get_tc(void); |
129 |
|
130 |
/**
|
131 |
* @brief Resets the encoder read counter.
|
132 |
*/
|
133 |
void encoder_rst_tc(void); |
134 |
|
135 |
/**
|
136 |
* @brief Waits until n encoder reads have occurred.
|
137 |
*
|
138 |
* Waits until n encoder reads have occurred.
|
139 |
* Counter is reset on function's exit.
|
140 |
*
|
141 |
* @param n
|
142 |
*/
|
143 |
void encoder_wait( int nReadings ); |
144 |
|
145 |
/**@}**/ //end group |
146 |
|
147 |
#endif
|
148 |
|