Author Topic: $50 sharp IR code - calling non existence thread?  (Read 2200 times)

0 Members and 1 Guest are viewing this topic.

Offline HDL_CinC_DragonTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,261
  • Helpful? 5
$50 sharp IR code - calling non existence thread?
« on: November 18, 2007, 11:57:16 AM »
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   }

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?
United States Marine Corps
Infantry
Returns to society: 2014JAN11

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: $50 sharp IR code - calling non existence thread?
« Reply #1 on: November 18, 2007, 01:56:57 PM »
In the SoR_Utils.h file for the stampy version code of the $50 robot you will see this:
Code: [Select]
void servo_scan(signed long int speed)
{
PORT_ON(PORTD, 2);
delay_cycles(speed);
PORT_OFF(PORTD, 2);//keep off
delay_cycles(200);
}

Offline HDL_CinC_DragonTopic starter

  • Supreme Robot
  • *****
  • Posts: 1,261
  • Helpful? 5
Re: $50 sharp IR code - calling non existence thread?
« Reply #2 on: November 19, 2007, 06:53:53 PM »
ah ok, apparently I have 2 versions of the SoR_Utils. Sorry  :-[
United States Marine Corps
Infantry
Returns to society: 2014JAN11

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: $50 sharp IR code - calling non existence thread?
« Reply #3 on: November 19, 2007, 08:36:16 PM »
yea sorry . . . I'm not the best of programmers . . . I need to learn about version control . . . :P

 


Get Your Ad Here

data_list