Software > Software
$50 sharp IR code - calling non existence thread?
(1/1)
HDL_CinC_Dragon:
--- Quote from: .c Source file ---1 //SoR Include
2 #include "SoR_Utils.h" //includes all the technical stuff
3
4 //global variables
5 int sharp_IR_reading=0;
6
7 int scan_thresh=0;//threshold value of scanning sensor
8
9 int scan_angle=30;//position of scanner, in units of servo command
10 int max_scan_angle=56;//maximum position scanner can rotate to (57)
11
12
13 //this function causes scanning servo to center on edge of object
14 void scan(void)
15 {
16 //lower (-) goes right
17 //higher (+) goes left
18 //30 far right, 50 straight, 56 far left (until it jams)
19
20 /*psuedocode
21 object is detected
22 scan right object detected
23 object not detected
24 scan left until object detected*/
25
26 sharp_IR_reading=a2dConvert8bit(3);
27
28 if (sharp_IR_reading > scan_thresh)//object detected
29 {
30 if (scan_angle>41) //overflow protection
31 scan_angle-=2;//scan right
32 }
33 else //object not detected
34 {
35 if (scan_angle<=max_scan_angle) //maximum servo angle
36 scan_angle+=2; //scan left
37 //else //if scanned all the way, this forces it to start over
38 // scan_angle=30;
39 }
40
41 //servo scan code
42 servo_scan(scan_angle);
43 }
44
45
46 //automatically calculates threshold value before run
47 void autocalibrate(void)
48 {
49 scan_thresh=a2dConvert8bit(3);//sensor reading
50 }
51
52 int main(void)
53 {
54 //LED_on();
55
56 initialize();
57
58 delay_cycles(42000);//two second wait delay
59
60 /*********ADD YOUR CODE BELOW THIS LINE **********/
61
62 //find thresholds
63 autocalibrate();
64
65 //LED_off();
66
67
68 while(1)
69 {
70 scan();
71
72 //object on left
73 if(scan_angle > 57)
74 robot_turn_left();
75
76 //object on right
77 else if(scan_angle < 41)
78 robot_turn_right();
79
80 //object is centered
81 else
82 robot_go_straight();
83
84 delay_cycles(400);//a small delay to prevent crazy oscillations
85 }
86 /*********ADD YOUR CODE ABOVE THIS LINE **********/
87
88 return 0;
89 }
--- End quote ---
On line 42, it says "servo_scan(scan_angle);". I cant find a thread in either the c source file nor the SoR_utils header file... so what is this line calling? Have I somehow somewhere deleted a thread?
Admin:
In the SoR_Utils.h file for the stampy version code of the $50 robot you will see this:
--- Code: ---void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 2);
delay_cycles(speed);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);
}
--- End code ---
HDL_CinC_Dragon:
ah ok, apparently I have 2 versions of the SoR_Utils. Sorry :-[
Admin:
yea sorry . . . I'm not the best of programmers . . . I need to learn about version control . . . :P
Navigation
[0] Message Index
Go to full version