Project

General

Profile

Revision 746

added andrew's ident code files

View differences:

trunk/code/projects/object_manipulation/obj_detect_swarm/main.c.test
1
#include <dragonfly_lib.h>
2

  
3

  
4
//A6
5
#define RED_LED PIN_ADC4
6
//A8
7
#define GREEN_LED PIN_ADC5
8
//A7
9
#define BLUE_LED PIN_ADC6
10

  
11
int main(void) {
12
	dragonfly_init(ALL_ON);
13
	//range_init();
14

  
15
	int rgb[3] = {0,0,0};
16
	
17
	long int distance_red;
18
	long int distance_green;
19
	long int distance_blue;
20
	
21
	int blue[3] = {255,245,249};
22
	int red[3] = {190,122,126};
23
	int green[3] = {118, 80, 86};
24
	
25
	
26
	//Turn each pin on in sequential order
27
	
28
	analog_init(ADC_START);
29

  
30
	while(1)
31
	{		
32
		digital_output(BLUE_LED, 1);
33
		
34
		delay_ms(1);
35
		analog_stop_loop();
36
		rgb[2] = analog8(AN9);
37
		analog_start_loop();
38
		
39
		digital_output(BLUE_LED,0);
40
		digital_output(RED_LED, 1);
41
		delay_ms(1);
42
		
43
		analog_stop_loop();
44
		rgb[0] = analog8(AN9);
45
		analog_start_loop();
46
		
47
		digital_output(RED_LED, 0);
48
		digital_output(GREEN_LED,1);
49
		delay_ms(1);
50
		
51
		analog_stop_loop();
52
		rgb[1] = analog8(AN9);
53
		analog_start_loop();
54
		
55
		digital_output(GREEN_LED,0);
56
		
57
		distance_red = 1;
58
		distance_green = rgb[1] - rgb[0];
59
		distance_blue = rgb[2] - rgb[0];
60
		
61
		distance_blue = distance_blue * rgb[0]/255;
62
		distance_green = distance_green * rgb[0]/255;
63
		
64
		usb_puti(distance_red);
65
		usb_puts("\t");
66
		usb_puti(distance_green;
67
		usb_puts("\t");
68
		usb_puti(distance_blue);
69
		usb_puts("\n");
70
		
71
		/*
72
		distance_red = 0;
73
		distance_green = 0;
74
		distance_blue = 0;
75
		{
76
					
77
			for(int i = 0; i < 3; i++)
78
			{
79
				distance_red += (red[i]-rgb[i])*(red[i]-rgb[i]);
80
				distance_green += (green[i]-rgb[i])*(green[i]-rgb[i]);
81
				distance_blue += (blue[i]-rgb[i])*(blue[i]-rgb[i]);
82
			}
83
			if(distance_red < distance_blue)
84
			{
85
				if(distance_red < distance_green)
86
				{	
87
					usb_puti(distance_red);
88
					usb_puts(" BROWN\n");
89
				}	
90
				else
91
				{
92
					usb_puti(distance_green);
93
					usb_puts(" GREEN\n");
94
				}
95
			}
96
			else
97
			{
98
				if(distance_blue < distance_green)
99
				{
100
					usb_puti(distance_blue);
101
						usb_puts(" ORANGE\n");
102
				}
103
				else
104
				{
105
					usb_puti(distance_green);
106
					usb_puts(" GREEN\n");
107
				}
108
			}
109
		}	
110
		*/
111
				
112
		delay_ms(50);
113
	}
114
}
trunk/code/projects/object_manipulation/obj_detect_swarm/main.c.txt
1
#include <inttypes.h>
2
#include <avr/interrupt.h>
3
#include "serial.h"
4
#include "timer.h"
5
#include "analog.h"
6
#include <stdlib.h>
7
#include "delay.h"
8
#include "servo.h"
9
#include "motor.h"
10

  
11
#define __STDIO_FDEVOPEN_COMPAT_12
12
#include <stdio.h>
13

  
14
extern int16_t error_global;
15
extern uint16_t mot_global;
16

  
17

  
18
/** @brief Main function - initializes and then runs a simple button controlled
19
 *	test.
20
 */
21
int main(void)
22
{
23

  
24
	uint16_t angle;
25
	uint16_t pyro_reading;
26
	
27
	analog_init();
28

  
29
	servo_init();
30
	angle = 8000;
31

  
32
	motor_init();
33

  
34
	timer_init();
35

  
36
	serial_init(BAUD9600);
37

  
38
	// Make the LED an output
39
	DDRG |= _BV(PG2);
40

  
41
	DDRE |= _BV(PE6);
42

  
43
	fdevopen(&serial_putchar, &serial_getchar, 0);
44

  
45
	// Enable interrupts
46
	sei();
47

  
48
	delay_ms(2000);
49

  
50
	motor_set(1,255,1);
51

  
52
	delay_ms(2000);
53

  
54
	motor_set(1,0,1);
55
	while (1)
56
	{
57
		pyro_reading = analog8(1);
58
		printf("Pyro =   %3u\r\n", pyro_reading);
59
		if (pyro_reading > 133)
60
		{
61
			angle = angle - 500;
62
			if (angle < 1000)
63
				angle = 1000;
64
			servo_set_angle(angle);
65
		}
66
		else if (pyro_reading < 100)
67
		{
68
			angle = angle + 500;
69
			if (angle > 15000)
70
				angle = 15000;
71
			servo_set_angle(angle);
72
		}		
73
		//printf("Knob =   %3u\t", analog8(6));
74
		//printf("Accel0 = %3u\t", analog8(1));
75
		//printf("Accel1 = %3u\t", analog8(2));
76
		//printf("Gyro =   %3u\r\n", analog8(0));
77

  
78
		delay_ms(200);
79

  
80

  
81
	}
82
}
83

  

Also available in: Unified diff