Project

General

Profile

Revision 437

Added by Kevin Woo about 16 years ago

Cleaned up analog.c code. Recompiled library. Mostly commenting and
documentation fixes. No changes made to actual code.

View differences:

trunk/code/lib/include/libdragonfly/math.h
30 30
 * @brief Contains math function(s)
31 31
 * 
32 32
 * @author Colony Project, CMU Robotics Club, James Kong
33
*/
33
 */
34 34

  
35 35
#ifndef _MATH_H_
36 36
#define _MATH_H_
trunk/code/lib/include/libdragonfly/lights.h
73 73
void orb_init(void);
74 74
/** @brief Set both orbs to a specified color **/
75 75
void orb_set(unsigned char red_led, unsigned char green_led,
76
	unsigned char blue_led);
76
	     unsigned char blue_led);
77 77
/** @brief Set orb1 to a specified color **/
78 78
void orb1_set(unsigned char red_led, unsigned char green_led,
79
	unsigned char blue_led); 
79
	      unsigned char blue_led); 
80 80
/** @brief Set orb2 to a specified color **/
81 81
void orb2_set(unsigned char red_led, unsigned char green_led,
82
	unsigned char blue_led);
82
	      unsigned char blue_led);
83 83

  
84 84
/** @brief Set both orbs to a specified color **/
85 85
void orb_set_color(int col);
trunk/code/lib/include/libdragonfly/analog.h
37 37
	
38 38
 * @author Colony Project, CMU Robotics Club, based on firefly
39 39
 * code by Tom Lauwers
40
*/
40
 */
41 41

  
42 42
#ifndef _ANALOG_H
43 43
#define _ANALOG_H
......
98 98

  
99 99
/** @brief Struct to hold the value of a particular analog port */
100 100
typedef struct {
101
	uint8_t adc8;
102
	uint16_t adc10;
101
  uint8_t adc8;
102
  uint16_t adc10;
103 103
} adc_t;
104 104

  
105 105

  
106 106
/** @brief Initialize analog ports. Will start running a loop
107
	 if start_conversion is ADC_START.**/
107
    if start_conversion is ADC_START.**/
108 108
void analog_init(int start_conversion);
109 109
/** @brief starts the analog loop. Doesn't do anything if the loop is already running. **/
110 110
void analog_start_loop(void);
trunk/code/lib/include/libdragonfly/dio.h
39 39
#define _DIO_H
40 40

  
41 41
/*
42
these are ALL the pins
43
don't use unless you know what you're doing
42
  these are ALL the pins
43
  don't use unless you know what you're doing
44 44
*/
45 45

  
46 46
/*
47
DIO pins on new dragonfly boards are shown below:
48
-----------------------------------------------
49
| _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC |
50
-----------------------------------------------
51
| _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND |
52
-----------------------------------------------
47
  DIO pins on new dragonfly boards are shown below:
48
  -----------------------------------------------
49
  | _PIN_E6 | _PIN_E7 | _PIN_D2 | _PIN_D3 | VCC |
50
  -----------------------------------------------
51
  | _PIN_E2 | _PIN_E3 | _PIN_E4 | _PIN_E5 | GND |
52
  -----------------------------------------------
53 53
*/
54 54

  
55 55
/** @brief Port A **/
......
194 194
//#define _PIN_G7 63
195 195

  
196 196
/*
197
These are the header pins (the ones you can connect things to)
198
Feel free to use these
197
  These are the header pins (the ones you can connect things to)
198
  Feel free to use these
199 199
*/
200 200

  
201 201
/**
trunk/code/lib/include/libdragonfly/serial.h
36 36
 **/
37 37

  
38 38
/*
39
	serial.h - Contains definitions and function prototypes for the RS232 serial port
39
  serial.h - Contains definitions and function prototypes for the RS232 serial port
40 40
  author(s): pkv
41 41
  
42 42
  Directions:
......
45 45
  write characters to the serial ports.
46 46
  
47 47
  UART Mapping:
48
    usb_*() -> UART0
49
    xbee_*() -> UART1
48
  usb_*() -> UART0
49
  xbee_*() -> UART1
50 50
  
51 51
  Options: (Add the following defines to your code to configure this library)
52
    #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
53
    #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
54
    #define USE_STDIO
52
  #define USB_BAUD { 115200 | 9600 } <= pick ONE value from in here
53
  #define XBEE_BAUD { 115200 | 9600 } <= pick ONE value from in here
54
  #define USE_STDIO
55 55
  
56 56
  Note: If you enable USE_STDIO, the first init function that is called will 
57 57
  automatically be linked to stdin, stdout, and stderr.  To use the baud rate 
trunk/code/lib/include/libdragonfly/reset.h
30 30
 * @brief Contains function(s) for resetting the robots
31 31
 * 
32 32
 * @author Colony Project, CMU Robotics Club, James Kong
33
*/
33
 */
34 34

  
35 35
#ifndef _RESET_H_
36 36
#define _RESET_H_
trunk/code/lib/src/libdragonfly/time.c
34 34
 **/
35 35

  
36 36
/*
37
time.c
38
anything that requires a delay
39
mostly delay_ms
37
  time.c
38
  anything that requires a delay
39
  mostly delay_ms
40 40

  
41
author: Robotics Club, Colony Project
41
  author: Robotics Club, Colony Project
42 42

  
43
Change Log:
44
	2.5.07 - Kevin
45
		Aaron fixed the orb/servo code and made them use timer3 but compare registers B and C. He hard set the prescaler
46
		to 8 so the RTC broke. Changed it so that we use a 8 prescaler which sets the compare match at 1/16th of a second.
47
		You now count how many 16ths of a second you want until you trigger your actual interrupt. Works. Changed defines
48
		for time so you can still call rtc_init with a scale but now it is defined in terms of actual time like second, quarter_second
49
		etc. Read that section in the time.h file for more information. Tested and works, though the clock drifts more than
50
		it used to
51
	1.30.07 - Kevin
52
		Modified the clock to run on timer3 on the Dragonfly. Works with decent accuracy. Using a prescaler of 256
53
	the timer counts up to a precomputer value which will trigger an interrupt and reset the timer. Multiples of
54
	256 change it by that multiple. Refer to the time.h file for all possible prescalers.
55
		The interrupt will call a specified function _rtc_func every pulse.
56
		All of it has been tested and it works.
43
  Change Log:
44
  2.5.07 - Kevin
45
  Aaron fixed the orb/servo code and made them use timer3 but compare registers B and C. He hard set the prescaler
46
  to 8 so the RTC broke. Changed it so that we use a 8 prescaler which sets the compare match at 1/16th of a second.
47
  You now count how many 16ths of a second you want until you trigger your actual interrupt. Works. Changed defines
48
  for time so you can still call rtc_init with a scale but now it is defined in terms of actual time like second, quarter_second
49
  etc. Read that section in the time.h file for more information. Tested and works, though the clock drifts more than
50
  it used to
51
  1.30.07 - Kevin
52
  Modified the clock to run on timer3 on the Dragonfly. Works with decent accuracy. Using a prescaler of 256
53
  the timer counts up to a precomputer value which will trigger an interrupt and reset the timer. Multiples of
54
  256 change it by that multiple. Refer to the time.h file for all possible prescalers.
55
  The interrupt will call a specified function _rtc_func every pulse.
56
  All of it has been tested and it works.
57 57

  
58 58
*/
59 59
#include <avr/interrupt.h>
......
81 81
 *
82 82
 * @param ms the number of milliseconds to delay for
83 83
 **/
84
void delay_ms(int ms) 
85
{
86
	for(; ms > 15; ms-=15)
87
		_delay_ms(15);
88
	_delay_ms(ms);
84
void delay_ms(int ms) {
85
  for(; ms > 15; ms-=15)
86
    _delay_ms(15);
87
  _delay_ms(ms);
89 88
}
90 89

  
91

  
92 90
/* 	Prescales defined in time.h. SECOND will give you 1 second.
93 91
	More scales are defined in the time.h file.
94 92
	rtc_func is the address to a function that you want called every clock tick. */
......
106 104
 **/
107 105
void rtc_init(int prescale_opt, void (*rtc_func)(void)) {
108 106
	
109
	//Clear timer register for Timer 3
110
	TCNT3 = 0;
107
  //Clear timer register for Timer 3
108
  TCNT3 = 0;
111 109
	
112
	/* 	This sets the Waveform Generation Module to CTC (Clear Timer on Compare) Mode (100)
113
		See page135 in Atmega128 Docs for more modes and explanations */
114
	TCCR3B |= _BV(WGM32);
110
  /* 	This sets the Waveform Generation Module to CTC (Clear Timer on Compare) Mode (100)
111
	See page135 in Atmega128 Docs for more modes and explanations */
112
  TCCR3B |= _BV(WGM32);
115 113
	
116
	/* 	This sets the prescaler for the system clock (8MHz) ie: divides the clock by some number.
117
		Currently set to a prescaler of 8 because that is what the orb and servos use (they are on this timer as well)
118
		See page137 in Atemga128 Docs for all the available prescalers */
119
	TCCR3B |= _BV(CS31);
114
  /* 	This sets the prescaler for the system clock (8MHz) ie: divides the clock by some number.
115
	Currently set to a prescaler of 8 because that is what the orb and servos use (they are on this timer as well)
116
	See page137 in Atemga128 Docs for all the available prescalers */
117
  TCCR3B |= _BV(CS31);
120 118
	
121
	/* 	Sets the two regsiters that we compare against. So the timer counts up to this number and
122
		then resets back to 0 and calls the compare match interrupt.
123
		8x10^6 / 8 = 1/16 Second. All values are based off of this number. Do not change it unless you
124
		are l337*/
119
  /* 	Sets the two regsiters that we compare against. So the timer counts up to this number and
120
	then resets back to 0 and calls the compare match interrupt.
121
	8x10^6 / 8 = 1/16 Second. All values are based off of this number. Do not change it unless you
122
	are l337*/
125 123
		
126
	OCR3A = 0xF424;	
124
  OCR3A = 0xF424;	
127 125

  
128
	/* 	Enable Output Compare A Interrupt. When OCR3A is met by the timer TCNT3 this interrupt will be
129
		triggerd. (See page140 in Atmega128 Docs for more information */
130
	ETIMSK |= _BV(OCIE3A);
126
  /* 	Enable Output Compare A Interrupt. When OCR3A is met by the timer TCNT3 this interrupt will be
127
	triggerd. (See page140 in Atmega128 Docs for more information */
128
  ETIMSK |= _BV(OCIE3A);
131 129
	
132
	/*	Store the pointer to the function to be used in the interrupt */
133
	_rtc_f = rtc_func;
130
  /*	Store the pointer to the function to be used in the interrupt */
131
  _rtc_f = rtc_func;
134 132
	
135
	/*	Store how many 1/16ths of a second you want to let by before triggering an interrupt */
136
	_rtc_scale = prescale_opt;
133
  /*	Store how many 1/16ths of a second you want to let by before triggering an interrupt */
134
  _rtc_scale = prescale_opt;
137 135
}
138 136

  
139 137
/**
......
144 142
 *
145 143
 * @see rtc_init, rtc_reset
146 144
 **/
147
int rtc_get(void){
148
	return _rtc_val;
145
int rtc_get(void) {
146
  return _rtc_val;
149 147
}
150 148

  
151 149
/**
......
153 151
 *
154 152
 * @see rtc_init, rtc_get
155 153
 **/
156
void rtc_reset(void){
157
	_rtc_val = 0;
154
void rtc_reset(void) {
155
  _rtc_val = 0;
158 156
}
159 157

  
160 158
/** @} **/ //end defgroup
......
164 162
	and when it reaches the amount of time you want, execute the code. */
165 163
SIGNAL(TIMER3_COMPA_vect) {
166 164

  
167
	if (_rtc_pulse ==  _rtc_scale) {
168
		//Increment the real time clock counter
169
		_rtc_val++;
165
  if (_rtc_pulse ==  _rtc_scale) {
166
    //Increment the real time clock counter
167
    _rtc_val++;
170 168
		
171
		//Calls the function tied to the real time clock if defined
172
		if(_rtc_f != 0)
173
			_rtc_f();
169
    //Calls the function tied to the real time clock if defined
170
    if(_rtc_f != 0)
171
      _rtc_f();
174 172
		
175
		//Resets the pulse until the next scale is matched
176
		_rtc_pulse = 0;
177
	}	
173
    //Resets the pulse until the next scale is matched
174
    _rtc_pulse = 0;
175
  }	
178 176
	
179
	//Updates the amount of pulses seen since the last scale match
180
	_rtc_pulse++;
177
  //Updates the amount of pulses seen since the last scale match
178
  _rtc_pulse++;
181 179
	
182 180
}
183

  
trunk/code/lib/src/libdragonfly/motor.c
50 50
 * @see motors_off, motor1_set, motor2_set
51 51
 **/
52 52
void motors_init( void ) {
53
	// Configure counter such that we use phase correct
54
	// PWM with 8-bit resolution
55
	PORTA &= 0x0F;
56
	DDRA |= 0xF0;
57
	DDRB |= 0x60;
53
  // Configure counter such that we use phase correct
54
  // PWM with 8-bit resolution
55
  PORTA &= 0x0F;
56
  DDRA |= 0xF0;
57
  DDRB |= 0x60;
58 58

  
59
	//timer 1A and 1B
60
	TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
61
	TCCR1B = _BV(WGM12) | _BV(CS10);
62
//	TCCR1A = 0xA1;
63
//	TCCR1B = 0x04;
64
	OCR1AH=0;
65
	OCR1AL=0;
66
	OCR1BH=0;
67
	OCR1BL=0;
59
  //timer 1A and 1B
60
  TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM10);
61
  TCCR1B = _BV(WGM12) | _BV(CS10);
62
  //	TCCR1A = 0xA1;
63
  //	TCCR1B = 0x04;
64
  OCR1AH=0;
65
  OCR1AL=0;
66
  OCR1BH=0;
67
  OCR1BL=0;
68 68
}
69 69

  
70 70
/**
......
78 78
 **/
79 79
void motor1_set(int direction, int speed) {
80 80

  
81
	if(direction == 0) {
82
	    // turn off PWM first if switching directions
83
		if((PORTA & 0x30) != 0x10)
84
		{
85
		  OCR1A = 0;
86
		}	
87
		PORTA = (PORTA & 0xCF) | 0x10;
88
//		PORTD |= 0x10;
89
//		PORTD &= 0xBF;
90
	}
91
	else {
92
	    // turn off PWM first if switching directions
93
		if((PORTA & 0x30) != 0x20)
94
		{
95
		  OCR1A = 0;
96
		}
97
		PORTA = (PORTA & 0xCF) | 0x20;
98
//		PORTD |= 0x40;
99
//		PORTD &= 0xEF;
100
	}
81
  if(direction == 0) {
82
    // turn off PWM first if switching directions
83
    if((PORTA & 0x30) != 0x10) {
84
      OCR1A = 0;
85
    }	
86
    PORTA = (PORTA & 0xCF) | 0x10;
87
    //		PORTD |= 0x10;
88
    //		PORTD &= 0xBF;
89
  } else {
90
    // turn off PWM first if switching directions
91
    if((PORTA & 0x30) != 0x20) {
92
      OCR1A = 0;
93
    }
94
    PORTA = (PORTA & 0xCF) | 0x20;
95
    //		PORTD |= 0x40;
96
    //		PORTD &= 0xEF;
97
  }
101 98
	
102
	// Set the timer to count up to speed, an 8-bit value
103
	OCR1AL = speed;
99
  // Set the timer to count up to speed, an 8-bit value
100
  OCR1AL = speed;
104 101
}
105 102

  
106 103
/**
......
113 110
 * @see motor1_set, motors_init
114 111
 **/
115 112
void motor2_set(int direction, int speed) {
116
	if(direction == 0) {
117
//		PORTD |= 0x20;
118
//		PORTD &= 0x7F;
119
	    // turn off PWM first if switching directions
120
		if((PORTA & 0xC0) != 0x80)
121
		{
122
		  OCR1B = 0;
123
		}		
113
  if(direction == 0) {
114
    //		PORTD |= 0x20;
115
    //		PORTD &= 0x7F;
116
    // turn off PWM first if switching directions
117
    if((PORTA & 0xC0) != 0x80) {
118
      OCR1B = 0;
119
    }		
124 120
		
125
		PORTA = (PORTA & 0x3F) | 0x80;
126
	}
127
	else {
128
//		PORTD |= 0x80;
129
//		PORTD &= 0xDF;
121
    PORTA = (PORTA & 0x3F) | 0x80;
122
  } else {
123
    //		PORTD |= 0x80;
124
    //		PORTD &= 0xDF;
130 125

  
131
	    // turn off PWM first if switching directions
132
		if((PORTA & 0xC0) != 0x40)
133
		{
134
		  OCR1B = 0;
135
		}		
126
    // turn off PWM first if switching directions
127
    if((PORTA & 0xC0) != 0x40) {
128
      OCR1B = 0;
129
    }		
136 130
		
137
		PORTA = (PORTA & 0x3F) | 0x40;
138
	}
139
	OCR1BL = speed;
131
    PORTA = (PORTA & 0x3F) | 0x40;
132
  }
133
  OCR1BL = speed;
140 134
}
141 135

  
142 136
/**
......
145 139
 * @see motors_init
146 140
 **/
147 141
void motors_off( void ) {
148
	OCR1AL = 0x0;
149
	OCR1BL = 0x0;
142
  OCR1AL = 0x0;
143
  OCR1BL = 0x0;
150 144
}
151 145

  
152 146
/**@}**///end defgroup
trunk/code/lib/src/libdragonfly/analog.c
56 56
 * Initializes the ADC.
57 57
 * Call analog_init before reading from the analog ports.
58 58
 *
59
 * @see analog8, analog10
59
 * @see analog8, analog10, analog_get8, analog_get10
60 60
 **/
61 61
void analog_init(int start_conversion)
62 62
{
......
110 110
	}
111 111
}
112 112

  
113
/**
114
 * Returns the 10-bit analog conversion of which from
115
 * the lookup table. If the requested port is the BOM_PORT
116
 * you will get an automatic 0 since the BOM_PORT is not
117
 * read in the loop and not stored. If you need that port
118
 * you should use the functions in bom.c. There is an analog_get10
119
 * function which for instant lookups but should be avoided.
120
 *
121
 * @param which the port that you want to read
122
 *
123
 * @bug may cause a seg fault if which is a larger value
124
 * than exists in an_val table. Not sure if we should fix
125
 * this or not since it would add overhead.
126
 *
127
 * @return 10-bit analog value for the which port requested
128
 *
129
 * @see analog8, analog_get8, analog_get10
130
 **/
113 131
unsigned int analog10(int which) {
114 132
	if (which == BOM_PORT) {
115 133
		return 0;
......
118 136
	}
119 137
}
120 138

  
139

  
140
/**
141
 * Starts the analog update loop. Will continue to run
142
 * until analog_stop_loop is called.
143
 *
144
 * @see analog_stop_loop
145
 **/
121 146
void analog_start_loop(void) {
122 147
	//Start the conversion
123 148
	ADCSRA |= _BV(ADSC);
124 149
	adc_loop_running = 0x1;
125 150
}
126 151

  
127
//will stop after current conversion finishes
152
/**
153
 * Stops the analog update loop. If there is a current
154
 * read, it will finish up and be stored before the loop
155
 * is interrupted. No further updates will be made until
156
 * the loop is started again.
157
 *
158
 * @see analog_start_loop
159
 **/
128 160
void analog_stop_loop(void) {
129 161
	//Stop the conversion
130 162
	adc_loop_running = 0x0;
......
240 272

  
241 273

  
242 274
ISR(ADC_vect) {
243
	static volatile int adc_prev_loop_running = 0;
244

  
275
	static volatile int adc_prev_loop_running = 0; 
245 276
	int adc_h = 0;
246 277
	int adc_l = 0;
247 278

  
248
	//usb_putc('p');
249
	//usb_puti(adc_current_port);
250
	//usb_putc('r');
251
	//usb_puti(adc_loop_running);
252
	//usb_puts("\n\r");
253

  
254 279
	//Store the value only if this read isn't for the BOM
255 280
	if (ADMUX != BOM_PORT) {
256 281
		adc_l = ADCL;
......
258 283
	
259 284
		an_val[adc_current_port - 1].adc10 = (adc_h << 2) | (adc_l >> 6);
260 285
		an_val[adc_current_port - 1].adc8 = adc_h;
261
		//usb_puti(an_val[adc_current_port - 1].adc10);
262
		//usb_puts("\n\r");
263
		//usb_puti(an_val[adc_current_port - 1].adc8);
264
		//usb_puti(ADCH);
265
		//usb_puts("\n\r");
266 286
	}
267 287
	
268 288
	//Save the result only if we just turned off the loop
......
293 313
	}
294 314

  
295 315
	//Initiate next conversion only if we are running a loop
296
	if (!adc_loop_running)
316
	if (!adc_loop_running) {
297 317
		return;
298

  
299
	ADCSRA |= _BV(ADSC);
300
	
301
	//if (ADCSRA & _BV(ADSC))
302
	//	usb_putc('s');
318
    } else {
319
    	ADCSRA |= _BV(ADSC);
320
	}
303 321
		
304 322
	return;
305 323
}
trunk/code/lib/src/libdragonfly/lcd.c
54 54

  
55 55
//**************************************Old shit below!*****************
56 56
/*
57
FontLookup - a lookup table for all characters
57
  FontLookup - a lookup table for all characters
58 58
*/
59 59
static const unsigned char FontLookup [][5] =
60
{
60
  {
61 61
    { 0x00, 0x00, 0x00, 0x00, 0x00 },  // sp
62 62
    { 0x00, 0x00, 0x5f, 0x00, 0x00 },   // !
63 63
    { 0x00, 0x07, 0x00, 0x07, 0x00 },   // "
......
154 154
    { 0x41, 0x41, 0x36, 0x08, 0x00 },   // }
155 155
    { 0x02, 0x01, 0x01, 0x02, 0x01 },   // ~
156 156
    { 0x55, 0x2A, 0x55, 0x2A, 0x55 },   // del
157
};
157
  };
158 158

  
159 159

  
160 160
/**
......
170 170
 * Initializes the LCD. Must be called before any other
171 171
 * LCD functions.
172 172
 **/
173
void lcd_init(void)
174
{
175
	LCDDDR |= (SCE | SDI | SCK);
176
	LCDRESETDDR |= (RST|D_C);
173
void lcd_init(void) {
174
  LCDDDR |= (SCE | SDI | SCK);
175
  LCDRESETDDR |= (RST|D_C);
177 176

  
178
	LCDPORT &= ~( SCE | SDI | SCK);
179
	LCDRESETPORT &=~(D_C);
177
  LCDPORT &= ~( SCE | SDI | SCK);
178
  LCDRESETPORT &=~(D_C);
180 179
  
181
	SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
182
	SPSR |= 0x01;       // a continuation of the above
180
  SPCR |= 0x50;//0b01010000; // no SPI int, SPI en, Master, sample on rising edge, fosc/2
181
  SPSR |= 0x01;       // a continuation of the above
183 182

  
184
	LCDRESETPORT |= RST;
185
	delay_ms(10);
186
	LCDRESETPORT &= (~RST);
187
	delay_ms(100);
188
	LCDRESETPORT |= RST;
183
  LCDRESETPORT |= RST;
184
  delay_ms(10);
185
  LCDRESETPORT &= (~RST);
186
  delay_ms(100);
187
  LCDRESETPORT |= RST;
189 188
	
190
	lcd_putbyte( 0x21 );  // LCD Extended Commands.
191
	lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
192
	lcd_putbyte( 0x06 );  // Set Temp coefficent.
193
	lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
194
	lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
195
	lcd_putbyte( 0x0C );  // LCD in normal mode.
189
  lcd_putbyte( 0x21 );  // LCD Extended Commands.
190
  lcd_putbyte( 0xC8 );  // Set LCD Vop (Contrast).
191
  lcd_putbyte( 0x06 );  // Set Temp coefficent.
192
  lcd_putbyte( 0x13 );  // LCD bias mode 1:48.
193
  lcd_putbyte( 0x20 );  // LCD Standard Commands, Horizontal addressing mode.
194
  lcd_putbyte( 0x0C );  // LCD in normal mode.
196 195
	
197
	LCDRESETPORT |= D_C;		//put it in init instead of main
196
  LCDRESETPORT |= D_C;		//put it in init instead of main
198 197
	
199
	lcd_clear_screen();
198
  lcd_clear_screen();
200 199
}
201 200

  
202 201
/**
......
205 204
 * @see lcd_init
206 205
 **/
207 206
void lcd_clear_screen( void ) {
208
	int i;
209
	for (i = 0; i < 504; i++)
210
		lcd_putbyte(0x0);
207
  int i;
208
  for (i = 0; i < 504; i++)
209
    lcd_putbyte(0x0);
211 210
	
212
	lcd_gotoxy(0,0);
211
  lcd_gotoxy(0,0);
213 212
}
214 213

  
215 214
/**
......
220 219
 *
221 220
 * @see lcd_init
222 221
 **/
223
void lcd_putc(char c)
224
{
225
	int i;
222
void lcd_putc(char c) {
223
  int i;
226 224
	
227
	for (i = 0; i < 5; i++)
228
		lcd_putbyte(FontLookup[c-32][i]);
229
	lcd_putbyte(0);
225
  for (i = 0; i < 5; i++)
226
    lcd_putbyte(FontLookup[c-32][i]);
227
  lcd_putbyte(0);
230 228
}
231 229

  
232 230
/*
233
print an entire string to the lcd
231
  print an entire string to the lcd
234 232
*/
235
void lcd_puts(char *s)
236
{
237
	char *t = s;
238
	while (*t != 0)
239
	{
240
		lcd_putc(*t);
241
		t++;
242
	}
233
void lcd_puts(char *s) {
234
  char *t = s;
235
  while (*t != 0) {
236
    lcd_putc(*t);
237
    t++;
238
  }
243 239
}
244 240

  
245 241
/*
246
go to coordinate x, y
247
y: vertically - 1 char
248
x: horizontally - 1 pixel
242
  go to coordinate x, y
243
  y: vertically - 1 char
244
  x: horizontally - 1 pixel
249 245

  
250
multiply x by 6 if want to move 1 entire character
246
  multiply x by 6 if want to move 1 entire character
251 247

  
252
origin (0,0) is at top left corner of lcd screen
248
  origin (0,0) is at top left corner of lcd screen
253 249
*/
254 250

  
255 251
/**
......
261 257
 *
262 258
 * @see lcd_init
263 259
 **/
264
void lcd_gotoxy(int x, int y)
265
{
266
	LCDRESETPORT &= ~(D_C);
267
	lcd_putbyte(0x40 | (y & 0x07));
268
	lcd_putbyte(0x80 | (x & 0x7f));
269
	LCDRESETPORT |= D_C;
260
void lcd_gotoxy(int x, int y) {
261
  LCDRESETPORT &= ~(D_C);
262
  lcd_putbyte(0x40 | (y & 0x07));
263
  lcd_putbyte(0x80 | (x & 0x7f));
264
  LCDRESETPORT |= D_C;
270 265
}
271 266

  
272 267
/*
273
prints an int to the lcd
268
  prints an int to the lcd
274 269

  
275
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
270
  code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
276 271
*/
277 272

  
278 273
/**
......
283 278
 *
284 279
 * @see lcd_init
285 280
 **/
286
void lcd_puti(int value )
287
{
288
	unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
281
void lcd_puti(int value ) {
282
  unsigned char lcd_data[6]={'0','0','0','0','0','0' }, position=sizeof(lcd_data), radix=10; 
289 283

  
290
        /* convert int to ascii  */ 
291
        if(value<0) { 
292
	  lcd_putc('-'); 
293
	  value=-value; 
294
	}    
295
        do { 
296
	  position--; 
297
	  *(lcd_data+position)=(value%radix)+'0'; 
298
	  value/=radix;  
299
	} while(value); 
284
  /* convert int to ascii  */ 
285
  if(value<0) { 
286
    lcd_putc('-'); 
287
    value=-value; 
288
  }    
289
  do { 
290
    position--; 
291
    *(lcd_data+position)=(value%radix)+'0'; 
292
    value/=radix;  
293
  } while(value); 
300 294

  
301 295
    
302
        /* start displaying the number */
303
        for( ; position<=(sizeof(lcd_data)-1); position++)
304
		lcd_putc(lcd_data[position]);
296
  /* start displaying the number */
297
  for(;position<=(sizeof(lcd_data)-1);position++)
298
    lcd_putc(lcd_data[position]);
305 299

  
306
	return;
300
  return;
307 301
}
308 302

  
309 303
/** @} **/ //end defgroup
310 304

  
311
void lcd_putbyte(unsigned char b)
312
{
313
	SPDR = b;
314
	while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
305
void lcd_putbyte(unsigned char b) {
306
  SPDR = b;
307
  while (!(SPSR & 0x80)); /* Wait until SPI transaction is complete */
315 308
}
316

  
trunk/code/lib/src/libdragonfly/move.c
43 43
void translateAngulartoLinear (int velocity, int omega, int* vl, int* vr);
44 44

  
45 45
// global varaibles for move_avoid
46
int d1, d2, d3, d4, d5; /**
46
int d1, d2, d3, d4, d5; 
47
/**
47 48
 * @defgroup move Movement
48 49
 * @brief Functions fo controlling robot motion
49 50
 * Higher level functions to control the movement of robots.
......
103 104
 *
104 105
 * @see motors_init, range_init, move
105 106
 **/
106
void move_avoid(int velocity, int omega, int strength){
107
void move_avoid(int velocity, int omega, int strength) {
107 108
  int pControl;
108 109
  int vl = 0;
109 110
  int vr = 0;
......
125 126
  d5=(temp == -1) ? d5 : temp;
126 127
  
127 128
  /* Avoid obstacles ahead
128
  if(d2>170)
129
    v*=-1;
129
     if(d2>170)
130
     v*=-1;
130 131
    
131
  Naturally slow down if there is something in the way.
132
  if(d2>150 || d1>180 || d3>180){
133
    v>>=1;
132
     Naturally slow down if there is something in the way.
133
     if(d2>150 || d1>180 || d3>180){
134
     v>>=1;
134 135
  */
135 136
  
136 137
  //pControl= (((d3-d1) + (d4-d5))*strength)/100;
......
153 154
/**@}**///end the motion group
154 155

  
155 156
void translateAngulartoLinear (int velocity, int omega, int* vl, int* vr) {
156
	//omega: angle measure, positive couter-clockwise from front.
157
	// -180 <= omega <= 180
158
	//velocity: -255 <= velocity <= 255
157
  //omega: angle measure, positive couter-clockwise from front.
158
  // -180 <= omega <= 180
159
  //velocity: -255 <= velocity <= 255
159 160
  
160 161
  long int vltemp, vrtemp;
161 162
  
......
163 164
  if (velocity < -255 || velocity >255 || omega < -255 || omega > 255) return;
164 165
	
165 166
  //compute
166
	vrtemp = velocity + omega * 3;
167
	vltemp = velocity - omega * 3;
167
  vrtemp = velocity + omega * 3;
168
  vltemp = velocity - omega * 3;
168 169
	
169
	//check to see if max linear velocities have been exceeded.
170
  //check to see if max linear velocities have been exceeded.
170 171
  if (vrtemp > 255) {
171 172
    vltemp = 255 * vltemp / vrtemp;
172 173
    vrtemp = 255;
173 174
  }
174 175
  if (vltemp > 255) {	   
175
	vrtemp = 255 * vrtemp / vltemp;    
176
	vltemp = 255;  
176
    vrtemp = 255 * vrtemp / vltemp;    
177
    vltemp = 255;  
177 178
  }
178 179
  if (vrtemp < -255) {
179 180
    vltemp = -255 * vltemp / vrtemp;
......
186 187
  
187 188
  *vr = (int)vrtemp;
188 189
  *vl = (int)vltemp;
189
	
190

  
191 190
}
192

  
193

  
trunk/code/lib/src/libdragonfly/battery.c
102 102
  
103 103
  int batt_reading = battery8();
104 104

  
105
  if(next_read == 0) {
105
  if(next_read == 0) 
106
  {
106 107
    if(batt_reading > BATTERY_LOWV)
107 108
    {
108 109
        ret = 0;
......
143 144
  int i;
144 145
  long int sum = 0;
145 146
  
146
  for(i = 0; i < n_samples; i++) {
147
  for(i = 0; i < n_samples; i++) 
148
  {
147 149
    sum += battery8();
148 150
  }
149 151
  
trunk/code/lib/src/libdragonfly/dragonfly_lib.c
62 62
 * @see analog_init, usb_init, xbee_init, buzzer_init,
63 63
 * bom_init, orb_init, motors_init, lcd_init
64 64
 **/
65
void dragonfly_init(int config) 
66
{
67
		sei();
65
void dragonfly_init(int config) {
66
  sei();
68 67

  
69
	// Set directionality of various IO pins
70
	DDRG &= ~(_BV(PING0)|_BV(PING1));
71
	PORTG |= _BV(PING0)|_BV(PING1);
68
  // Set directionality of various IO pins
69
  DDRG &= ~(_BV(PING0)|_BV(PING1));
70
  PORTG |= _BV(PING0)|_BV(PING1);
72 71
	
73
	if(config & ANALOG)
74
		analog_init(ADC_START);
72
  if(config & ANALOG)
73
    analog_init(ADC_START);
75 74
	
76
	if(config & COMM)
77
	{
78
		//Defaults to 115200. Check serial.h for more information.
79
		usb_init();
80
		xbee_init();
81
	}
75
  if(config & COMM) {
76
    //Defaults to 115200. Check serial.h for more information.
77
    usb_init();
78
    xbee_init();
79
  }
82 80
	
83
	if(config & BUZZER)
84
	{
85
		sei();
86
		buzzer_init();
87
	}
81
  if(config & BUZZER) {
82
    sei();
83
    buzzer_init();
84
  }
88 85
	
89
	if(config & ORB)
90
	{
91
		sei();
92
		orb_init();
93
	}
86
  if(config & ORB) {
87
    sei();
88
    orb_init();
89
  }
94 90
	
95
	if(config & MOTORS)
96
		motors_init();
91
  if(config & MOTORS)
92
    motors_init();
97 93

  
98
	if(config & LCD)
99
		lcd_init();
94
  if(config & LCD)
95
    lcd_init();
100 96
	
101
	if(config & ORB)
102
	{
103
		sei();
104
		orb_init();
105
	}
97
  if(config & ORB) {
98
    sei();
99
    orb_init();
100
  }
106 101
	
107
	// delay a bit for stability
108
	_delay_ms(1);
102
  // delay a bit for stability
103
  _delay_ms(1);
109 104
}
110 105

  
111 106

  
trunk/code/lib/src/libdragonfly/dio.c
72 72
 *
73 73
 * @return 1 or 0, depending on the value of the portpin.
74 74
 **/
75
int digital_input(int portpin){
75
int digital_input(int portpin) {
76 76
  int pin = portpin & 0x7;
77 77
  int pin_val = 0;
78 78
  
79
  switch(portpin >> 3){
79
  switch(portpin >> 3) {
80 80
  case _PORT_A:
81 81
    DDRA &= ~_BV(pin);
82 82
    pin_val = PINA;
......
98 98
    pin_val = PINE;
99 99
    return (pin_val >> pin) & 1;
100 100
  case _PORT_F:
101
    if(pin>=4){
101
    if(pin>=4) {
102 102
      MCUSR|=1<<7;
103 103
      MCUSR|=1<<7;
104 104
    }
......
194 194
      PORTG &= (0XFF - _BV(pins));
195 195
      break;
196 196
    }
197
  }else { /* ( val == 1) */ 
197
  } else { /* ( val == 1) */ 
198 198
    switch(portpin >> 3) {
199 199
    case _PORT_A:
200 200
      DDRA |= _BV(pins);
......
235 235
 *
236 236
 * @see button1_wait, button1_click
237 237
 **/
238
int button1_read( void )
239
{
240
	int pin_val;
241
	DDRG &= ~_BV(PING0);
242
	PORTG|= _BV(PING0);
243
    pin_val = PING;
244
	return !((pin_val & _BV(PING0)));
245
  
238
int button1_read( void ) {
239
  int pin_val;
240
  DDRG &= ~_BV(PING0);
241
  PORTG|= _BV(PING0);
242
  pin_val = PING;
243
  return !((pin_val & _BV(PING0)));
246 244
}
247 245

  
248 246
/**
......
250 248
 *
251 249
 * @see button1_read, button1_click
252 250
 **/
253
void button1_wait( void )
254
{
251
void button1_wait( void ) {
255 252
  while(!button1_read() ) {
256 253
    delay_ms(15);
257 254
  }
......
265 262
 *
266 263
 * @see button1_read, button1_wait
267 264
 **/
268
int button1_click()
269
{
270
  if(button1_read()){
265
int button1_click() {
266
  if(button1_read()) {
271 267
    while(button1_read());
272 268
    return 1;
273
  }else{
269
  } else {
274 270
    return 0;
275 271
  }
276 272
}
......
282 278
 *
283 279
 * @see button2_wait, button2_click
284 280
 **/
285
int button2_read( void )
286
{
287
	int pin_val;
288
	DDRG &= ~_BV(PING1);
289
	PORTG|= _BV(PING1);
290
    pin_val = PING;
291
	return !((pin_val & _BV(PING1)));
281
int button2_read( void ) {
282
  int pin_val;
283
  DDRG &= ~_BV(PING1);
284
  PORTG|= _BV(PING1);
285
  pin_val = PING;
286
  return !((pin_val & _BV(PING1)));
292 287
}
293 288

  
294 289
/**
......
296 291
 *
297 292
 * @see button2_read, button2_click
298 293
 **/
299
void button2_wait( void )
300
{
294
void button2_wait( void ) {
301 295
  while(!button2_read()){
302 296
    delay_ms(15);
303 297
  }
......
311 305
 *
312 306
 * @see button2_read, button2_wait
313 307
 **/
314
int button2_click()
315
{
316
	if(button2_read()){
308
int button2_click() {
309
  if(button2_read()) {
317 310
    while(button2_read());
318 311
    return 1;
319
  }else{
320
		return 0;
312
  } else {
313
    return 0;
321 314
  }
322 315
}
323 316

  
trunk/code/lib/src/libdragonfly/serial.c
49 49
  //Set baud rate
50 50
  // - 115200 (both wired and wireless) is UBRR=8, U2X=1
51 51
  // - 9600 is U2X =1, UBRR = 107.
52
	#if (USB_BAUD == 115200)
53
    UBRR0H = 0x00;
54
    UBRR0L = 8;
55
    UCSR0A |= _BV(U2X0);
56
  #elif (USB_BAUD == 9600)
57
    UBRR0H = 0x00;
58
    UBRR0L = 103;
59
    UCSR0A |= _BV(U2X0);
60
  #else //Baud rate is defined in the header file, we should not get here
61
    return;
62
  #endif
52
#if (USB_BAUD == 115200)
53
  UBRR0H = 0x00;
54
  UBRR0L = 8;
55
  UCSR0A |= _BV(U2X0);
56
#elif (USB_BAUD == 9600)
57
  UBRR0H = 0x00;
58
  UBRR0L = 103;
59
  UCSR0A |= _BV(U2X0);
60
#else //Baud rate is defined in the header file, we should not get here
61
  return;
62
#endif
63 63

  
64 64
  /*Enable receiver and transmitter */
65
	UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
65
  UCSR0B |= (1<<RXEN0)|(1<<TXEN0);
66 66
	
67
	/* Set frame format: 8data, 1stop bit, asynchronous normal mode */
68
	UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01);
67
  /* Set frame format: 8data, 1stop bit, asynchronous normal mode */
68
  UCSR0C |= (1<<UCSZ00) | (1<<UCSZ01);
69 69
  
70 70
  // if we have enabled the stdio stuff, then we init it here
71
  #ifdef USE_STDIO
72
    /* Open the stdio stream corresponding to this port */
73
    usb_fd = fdevopen(usb_putc, usb_getc);
74
  #endif
71
#ifdef USE_STDIO
72
  /* Open the stdio stream corresponding to this port */
73
  usb_fd = fdevopen(usb_putc, usb_getc);
74
#endif
75 75
}
76 76

  
77 77
/**
......
83 83
  //Set baud rate
84 84
  // - 115200 (both wired and wireless) is UBRR=8, U2X=1
85 85
  // - 9600 is U2X =1, UBRR = 107.
86
	#if (XBEE_BAUD == 115200)
87
    UBRR1H = 0x00;
88
    UBRR1L = 8;
89
    UCSR1A |= _BV(U2X1);
90
  #elif (XBEE_BAUD == 9600)
91
    UBRR1H = 0x00;
92
    UBRR1L = 103;
93
    UCSR1A |= _BV(U2X1);
94
  #else //Baud rate is defined in the header file, we should not get here
95
    return;
96
  #endif
86
#if (XBEE_BAUD == 115200)
87
  UBRR1H = 0x00;
88
  UBRR1L = 8;
89
  UCSR1A |= _BV(U2X1);
90
#elif (XBEE_BAUD == 9600)
91
  UBRR1H = 0x00;
92
  UBRR1L = 103;
93
  UCSR1A |= _BV(U2X1);
94
#else //Baud rate is defined in the header file, we should not get here
95
  return;
96
#endif
97 97

  
98
	//Enable receiver and transmitter
99
	UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
98
  //Enable receiver and transmitter
99
  UCSR1B |= (1<<RXEN1)|(1<<TXEN1);
100 100
	
101
	// Set frame format: 8data, 1stop bit, asynchronous normal mode
102
	UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
101
  // Set frame format: 8data, 1stop bit, asynchronous normal mode
102
  UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11);
103 103
  
104 104
  // if we have enabled the stdio stuff, then we init it here
105
  #ifdef USE_STDIO
106
    /* Open the stdio stream corresponding to this port */
107
    xbee_fd = fdevopen(xbee_putc, xbee_getc);
108
  #endif
105
#ifdef USE_STDIO
106
  /* Open the stdio stream corresponding to this port */
107
  xbee_fd = fdevopen(xbee_putc, xbee_getc);
108
#endif
109 109
}
110 110

  
111 111
/**
......
114 114
 * @param c the character to send
115 115
 * @return 0 for success, nonzero for failure
116 116
 **/
117
int usb_putc(char c) 
118
{
117
int usb_putc(char c) {
119 118
  // Wait until buffer is clear for sending
120 119
  loop_until_bit_is_set(UCSR0A, UDRE0);
121 120
	
......
130 129
 * @param c the character to send
131 130
 * @return 0 for success, nonzero for failure
132 131
 **/
133
int xbee_putc(char c) 
134
{
132
int xbee_putc(char c) {
135 133
  // Wait until buffer is clear for sending
136 134
  loop_until_bit_is_set(UCSR1A, UDRE1);
137 135
	
......
146 144
 * @param s the string to send
147 145
 * @return 0 for success, nonzero for failure
148 146
 **/
149
int usb_puts(char *s)
150
{
151
	char *t = s;
152
	while (*t != 0)
153
	{
154
		usb_putc(*t);
155
		t++;
156
	}
147
int usb_puts(char *s) {
148
  char *t = s;
149
  while (*t != 0) {
150
    usb_putc(*t);
151
    t++;
152
  }
157 153
  return 0;
158 154
}
159 155

  
......
166 162
 *
167 163
 * @see usb_init, usb_getc_nb
168 164
 **/
169
int usb_getc(void)
170
{
171
	// Wait for the receive buffer to be filled
172
	loop_until_bit_is_set(UCSR0A, RXC0);
165
int usb_getc(void) {
166
  // Wait for the receive buffer to be filled
167
  loop_until_bit_is_set(UCSR0A, RXC0);
173 168
	
174
	// Read the receive buffer
175
	return UDR0;
169
  // Read the receive buffer
170
  return UDR0;
176 171
}
177 172

  
178 173
/**
......
185 180
 * 
186 181
 * @see xbee_init, xbee_getc_nb
187 182
 **/
188
int xbee_getc(void)
189
{
190
	// Wait for the receive buffer to be filled
191
    loop_until_bit_is_set(UCSR1A, RXC1);
183
int xbee_getc(void) {
184
  // Wait for the receive buffer to be filled
185
  loop_until_bit_is_set(UCSR1A, RXC1);
192 186
	
193
	// Read the receive buffer
194
	return UDR1;
187
  // Read the receive buffer
188
  return UDR1;
195 189
}
196 190

  
197 191
/**
......
206 200
 * 
207 201
 * @see usb_init, usb_getc
208 202
 **/
209
int usb_getc_nb(char *c)
210
{
211
	// check if the receive buffer is filled
203
int usb_getc_nb(char *c) {
204
  // check if the receive buffer is filled
212 205
  if (UCSR0A & _BV(RXC0)) {
213 206
    // Read the receive buffer
214 207
    (*c) = UDR0;
215 208
    return 0;
216
  }
217
  else {
209
  } else {
218 210
    // Return empty
219 211
    return -1;
220
	}
212
  }
221 213
}
222 214

  
223 215
/**
......
232 224
 *
233 225
 * @see xbee_init, xbee_getc
234 226
 **/
235
int xbee_getc_nb(char *c)
236
{
237
	// check if the receive buffer is filled
227
int xbee_getc_nb(char *c) {
228
  // check if the receive buffer is filled
238 229
  if (UCSR1A & _BV(RXC1)) {
239 230
    // Read the receive buffer
240 231
    (*c) = UDR1;
241 232
    return 0;
242
  }
243
  else {
233
  } else {
244 234
    // Return empty
245 235
    return -1;
246
	}
236
  }
247 237
}
248 238

  
249 239

  
250 240
/*
251
prints an int to serial
241
  prints an int to serial
252 242

  
253
code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
254
uses usb_putc
243
  code adapted from Chris Efstathiou's code (hendrix@otenet.gr)
244
  uses usb_putc
255 245
*/
256 246
/**
257 247
 * Prints an integer, converted to ASCII, to usb. usb_init must be called
......
264 254
 * @see usb_init, usb_putc
265 255
 **/
266 256
int usb_puti(int value ) {
267
	unsigned char usb_data[6]={'0','0','0','0','0','0' }, position=sizeof(usb_data), radix=10; 
257
  unsigned char usb_data[6]={'0','0','0','0','0','0' }, position=sizeof(usb_data), radix=10; 
268 258

  
269
        /* convert int to ascii  */ 
270
        if(value<0) { usb_putc('-'); value=-value; }    
271
        do { position--; *(usb_data+position)=(value%radix)+'0'; value/=radix;  } while(value); 
259
  /* convert int to ascii  */ 
260
  if(value<0) { 
261
    usb_putc('-'); 
262
    value=-value; 
263
  }    
264
  do { 
265
    position--; 
266
    *(usb_data+position)=(value%radix)+'0'; 
267
    value/=radix;  
268
  } while(value); 
272 269

  
273 270
    
274
        /* start displaying the number */
275
        for(;position<=(sizeof(usb_data)-1);position++)
276
          {
271
  /* start displaying the number */
272
  for(;position<=(sizeof(usb_data)-1);position++) {
277 273
            
278
            usb_putc(usb_data[position]);
279
          }
274
    usb_putc(usb_data[position]);
275
  }
280 276

  
281
	return 0;
277
  return 0;
282 278
}
283

  
284

  
trunk/code/lib/src/libdragonfly/reset.c
51 51
 * and Status Register (MCUCSR).
52 52
 **/
53 53
void reset(void) {
54
    WDTCR &= 0xF8;
55
    WDTCR |= 0x08;
56
    _delay_ms(15);
54
  WDTCR &= 0xF8;
55
  WDTCR |= 0x08;
56
  _delay_ms(15);
57 57
}
58 58

  
59 59
/**@}**/ //end defgroup
trunk/code/lib/src/libdragonfly/rangefinder.c
34 34
 **/
35 35

  
36 36
/*
37
Authors: James Kong and Greg Tress
37
  Authors: James Kong and Greg Tress
38 38

  
39
Last Modified: 4/30/06 by James
40
-Started log_distance conversion function !!!NOT COMPLETE!!!
41
-Cleaning up comments
39
  Last Modified: 4/30/06 by James
40
  -Started log_distance conversion function !!!NOT COMPLETE!!!
41
  -Cleaning up comments
42 42

  
43
-----------------
44
rangefinder.c
45
Using Sharp GP2D02 IR Rangefinder
43
  -----------------
44
  rangefinder.c
45
  Using Sharp GP2D02 IR Rangefinder
46 46

  
47
Vin is the input to the rangefinder, designated RANGE_CTRL.
48
Vout is the output from the rangefinder, designated RANGE_IN# where # is the rangefinder you are reading from
47
  Vin is the input to the rangefinder, designated RANGE_CTRL.
48
  Vout is the output from the rangefinder, designated RANGE_IN# where # is the rangefinder you are reading from
49 49

  
50
Expected Initial Conditions:
51
Vin is high and Vout should read high.
50
  Expected Initial Conditions:
51
  Vin is high and Vout should read high.
52 52

  
53
Usage:
54
1.) Set Vin low. Vout should read low.
55
2.) Wait for high on Vout.
56
3.) Begin clocking Vin and reading 8 bits from Vout (MSB first).
57
4.) Set Vin high for 2ms or more to turn off rangefinder
53
  Usage:
54
  1.) Set Vin low. Vout should read low.
55
  2.) Wait for high on Vout.
56
  3.) Begin clocking Vin and reading 8 bits from Vout (MSB first).
57
  4.) Set Vin high for 2ms or more to turn off rangefinder
58 58

  
59 59
*/
60 60

  
......
62 62
#include "rangefinder.h"
63 63

  
64 64
/*
65
read_distance returns the 8-bit reading from the rangefinder
66
parameters:
67
range_id - dio pin set as the rangefinder Vout [i.e. RANGE_IN0]
65
  read_distance returns the 8-bit reading from the rangefinder
66
  parameters:
67
  range_id - dio pin set as the rangefinder Vout [i.e. RANGE_IN0]
68 68

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff