Project

General

Profile

Revision 1372

Moved prototype for linearize_distance and constants MIN_IR_ADC8 and
MAX_IR_ADC8 from rangefinder.c to rangefinder.h. Added Doxy comments for these
items. Realize that linearize_distance was probably intended to be hidden from
the average user, but doxy errors compelled me to act.

View differences:

trunk/code/projects/libdragonfly/rangefinder.c
68 68

  
69 69
  NOTE:
70 70
  The Sharp GD2D02 returns values on a decreasing logrithmic scale.
71
  So higher values correspond to closer distances.  Use linearize_distance to convert to normal centimeter scale.  Also, when reading distances closer than 8cm, the Sharp GD2D02 will return lower values than the values at 8cm.
71
  So higher values correspond to closer distances.  Use linearize_distance to convert to normal centimeter scale.
72
  Also, when reading distances closer than 8cm, the Sharp GD2D02 will return lower values than the values at 8cm.
72 73
  At this point, we are only reading from one rangefinder [RANGE_IN0].
73 74
*/
74 75

  
......
85 86
   10cm from the detector.  See the datasheet for more information.
86 87
*/
87 88

  
88
#define MIN_IR_ADC8 20
89
#define MAX_IR_ADC8 133
90

  
91 89
static int IR_dist_conversion[114] = {
92 90
  800,791,751,714,681,651,623,597,574,552,531,512,494,478,462,447
93 91
  ,434,421,408,397,386,375,365,356,347,338,330,322,315,307,301,294
......
99 97
  ,102,101
100 98
};
101 99

  
102
int linearize_distance(int value);
103

  
104 100
/**
105 101
 * @defgroup rangefinder Rangefinder
106 102
 * @brief Functions for using the IR rangefinders
......
132 128
 *
133 129
 * @see range_init
134 130
 **/
135
int range_read_distance (int range_id) {
131
int range_read_distance(int range_id) {
136 132
  return linearize_distance(analog8(range_id));
137 133
}
138 134

  
139
/** @} **/ //end defgroup
140

  
135
/**
136
 * Transforms distance readings from logarithmic to linear scale.
137
 * This probably isn't the function you are looking for.
138
 *
139
 * @param value the 8-bit analog value from rangefinder
140
 *
141
 * @return linearized distance reading from rangefinder (integer in [101,800])
142
 **/
141 143
int linearize_distance(int value) {
142 144
  if(value < MIN_IR_ADC8) {
143 145
    return -1;
......
147 149
    return IR_dist_conversion[value - MIN_IR_ADC8];
148 150
  }
149 151
}
152

  
153
/** @} **/ //end defgroup
trunk/code/projects/libdragonfly/rangefinder.h
52 52
#define IR4 3
53 53
/** @brief IR Rangefinder 5 **/
54 54
#define IR5 2
55
/** @brief smallest meaningful rangefinder reading (logarithmic scale) **/
56
#define MIN_IR_ADC8 20
57
/** @brief largest meaningful rangefinder reading (logarithmic scale) **/
58
#define MAX_IR_ADC8 133
55 59

  
56 60
/** @brief Initialize the rangefinders **/
57 61
void range_init(void);
58 62
/** @brief Read the distance from a rangefinder **/
59 63
int range_read_distance(int range_id);
64
/** @brief Convert logarithmic-scale distance readings to a linear scale **/
65
int linearize_distance(int value);
60 66

  
61 67
/** @} **/ //end addtogroup
62 68

  

Also available in: Unified diff