Rangefinder

Functions for using the IR rangefinders. More...

Defines

#define IR1   6
 IR Rangefinder 1.
#define IR2   5
 IR Rangefinder 2.
#define IR3   4
 IR Rangefinder 3.
#define IR4   3
 IR Rangefinder 4.
#define IR5   2
 IR Rangefinder 5.
#define MIN_IR_ADC8   27
 smallest meaningful rangefinder reading (logarithmic scale)
#define MAX_IR_ADC8   98
 largest meaningful rangefinder reading (logarithmic scale)
#define MIN_IR_LINEAR   78
 smallest meaningful rangefinder reading (linear scale)
#define MAX_IR_LINEAR   327
 largest meaningful rangefinder reading (linear scale)

Functions

void range_init (void)
 Initialize the rangefinders.
void range_init_filter (int filter)
 Initialize the rangefinders with option to use filtering.
int range_read_distance (int range_id)
 Read the distance from a rangefinder.
int linearize_distance (int value)
 Convert logarithmic-scale distance readings to a linear scale.
void butter_init (void)
 Initialize the butterworth filter.
void butter_task (void)
 Task that reads rangefinders and sends the values to the filter.
int get_range_index (int range_id)
void butter_filter (int range_id, int val)
int range_read_filtered_distance (int range_id)
 Returns the most recent filtered reading of the rangefinder.
void butter_filter (int range_id, int16_t val)
 Puts a raw rangefinder value through the Butterworth filter.

Detailed Description

Functions for using the IR rangefinders.


Function Documentation

void butter_filter ( int  range_id,
int  val 
)

Puts the given value from the given rangefinder through the Butterworth filter. This function should be called every time a new value is read from a rangefinder.

The Butterworth filter has a cutoff frequency of 5Hz and an order of 3

Parameters:
range_id the rangefinder to use. This should be one of the constants IR1 - IR5.
the value read from that rangefinder

Definition at line 258 of file rangefinder.c.

References MAX_IR_LINEAR, and MIN_IR_LINEAR.

void butter_init ( void   ) 

Initialize the butterworth filter.

Initializes the butterworth filter.

int linearize_distance ( int  value  ) 

Convert logarithmic-scale distance readings to a linear scale.

Transforms distance readings from logarithmic to linear scale. This probably isn't the function you are looking for.

Note: pgm_read_word() needs additional testing

Parameters:
value the 8-bit analog value from rangefinder
Returns:
linearized distance reading from rangefinder (integer in [101,800])
void range_init ( void   ) 

Initialize the rangefinders.

Initializes the rangefinders. This must be called before range_read_distance. This function does not initialize the filter.

See also:
range_read_distance
void range_init_filter ( int  filter  ) 

Initialize the rangefinders with option to use filtering.

Initializes the rangefinders with an option to enable the Butterworth filtering.

As of 5/12/2010, the filter should only be used if you really know what you are doing. It was designed to be used with a task scheduler, which is not currently complete. This implementation uses the RTC and runs massive computations in the RTC interrupt.

Parameters:
filter 1 to enable the filter, 0 to leave it turned off
int range_read_distance ( int  range_id  ) 

Read the distance from a rangefinder.

Reads the distance measured by one of the rangefinders. This distance is in arbitrary units.

Parameters:
range_id the rangefinder to use. This should be one of the constants IR1 - IR5.
Returns:
the distance measured by the rangefinder
See also:
range_init
int range_read_filtered_distance ( int  range_id  ) 

Returns the most recent filtered reading of the rangefinder.

Returns the most recent filtered reading of the rangefinder. The raw rangefinder values have been run through a Butterworth filter.

If the filter was not initialized in rangefinder_init, will return the unfiltered value from the rangefinder.

Parameters:
range_id the rangefinder to use. This should be one of the constants IR1 - IR5.

Generated on Wed Feb 8 00:00:08 2012 for libdragonfly by  doxygen 1.6.1