Friday, February 11

Surveillance 202: Update 1

Well, you know the old 80/20 rule?  Once you get eighty percent of a project you don't want to complete the last twenty percent.  I found that to be the case in my line follower, and have put it on the back burner... for now.  Anyway, I was inspired to build a fully automated video/still camera bot.  It works great and as soon as I get some pictures, I'll put them on this post.  But in the meantime, I would like to share what it does.  First there is a process of positioning in which you manually assign all the coordinates that the robot will use in the rest of the program.  You do this by moving the motors to the desired location, and, with a press of a button, the X and Y motor values are stored in an array.  When you are done storing positions, you press another button, and the robot takes off on its own.  The great thing about this method is: that the program is fully customizable to different rooms or locations, that you have an unlimited amount of picture locations ( basically unlimited, ) and the robot is very easy to build.
There are definitely some things that I want to change, most importantly, I want to be able to change a certain coordinate without having to go back and re-enter all of them.  There are also innumerable extras that would be fun to add, such as a sound sensor to determine the loudest part of the room, and take most of the pictures there, or maybe a portrait taking program that would use an ultrasonic sensor to locate a person and take their picture.  Well I'll leave it at that until I have more time.  See Ya Back!!!


I have added a function to my code. It enables you to change existing parameters and even add new ones!
I am working on pictures right now so stay tuned!


void set_a_val()
{
   PlayTone(1000, 100); Wait(100);
   int c;
   for(c = 0; ButtonPressed(3, true) == false; ){
      ClearScreen();
      NumOut(32, 50, c, false);
      if(ButtonPressed(1, true) == true){
         c++; until(ButtonPressed(1, true) == false); }
      if(ButtonPressed(2, true) == true){
         c--; until(ButtonPressed(2, true) == false); }
   }
   if(c > L) c = L;
   else if(c < 0) c = 0;
   if(c > S) S = c + 1;
 
   until(ButtonPressed(1, true) == true);
   PlaceX[c] = MotorTachoCount(OUT_A); PlaceY[c] = MotorTachoCount(OUT_C);
   PlayTone(500, 100); Wait(200);
   PlayTone(1500, 100); Wait(100);
}


P.S. I recognize that by posting my code to the public, I have given you the permission to use and modify to any extent the said code.  But, this code may not be sold without permission from me, and I would appreciate it if you would give me credit if you do use this code.  Thank you!.

Wednesday, February 9

Line follower update 03

I've gotten the program pretty much worked out.  I have only a few details to be worked out, but for now at least, all building has been put on the back burner as I am now focusing entirely on my schooling about seven hours a day seven days a week. speaking of which, I am supposed to be reading right now... well any way, I am going to post the whole program for ya'all now, so be ware!!!




#define ant(a) until(Button == a) Button = ButtonPressed(3, true)
#define sound(b); PlayTone(b, 50); Wait(100);
#define Move(c,d); { int T; OnFwdEx(OUT_A, d, false); if(c > 0) until( T > c ){ T = MotorTachoCount(OUT_A);} else until( T < c ){ T = MotorTachoCount(OUT_A);} }

bool alth, Go = true, Button = false, line = true;

bool where[] = {false, false, false, false, false};
//int turndeg[] = {-300, -150, 0, 150, 300};
int width = 0, line_position = 0, LLP = 0, thresh = 25;
int m = 0;

safecall int MAP(int input, int input_ref, int output_ref)
     { return (input * output_ref) / input_ref; }

bool AlterThresh(int T, int S, int L, bool AT){
   if(T > S && T < L && AT == true){ thresh = thresh + 5; AT = true; }
   else{ AT = false; } return AT; }

safecall void MOTOR_CONTROL(bool FB, int speed){
     if(FB == true){ int turnpct = MAP(line_position, 100, 200) - 100;
     RotateMotorEx(OUT_BC, speed, 90, turnpct, true, false);}
     else RotateMotorEx(OUT_BC, -speed, 90, 0, false, false);}

task DISPLAY(){ while(Go == true){
     SetSensorLight(IN_3);
     TextOut(0, 57, "W", true); NumOut(10, 57, width, false);
     TextOut(50, 57, "T", false); NumOut(60, 57, MAP(MotorTachoCount(OUT_A), 180, 100), false);
     TextOut(0, 43, "P", false); NumOut(10, 43, line_position, false);
     //TextOut(50, 43, "%", false); NumOut(60, 43, turnpot, false);
     TextOut(0, 0, "L", false); NumOut(10, 0, m, false);
     TextOut(25, 0, "LS", false); NumOut(38, 0, Sensor(IN_3), false);
     TextOut(55, 0, "TH", false); NumOut(68, 0, thresh, false);
     for(int c = 0; c < 5; c++){
          if (where[c] == true) TextOut(c*10, 28, "O", false);
          else TextOut(c*10, 28, "X", false);
     }
     Wait(100);
}}

task SCAN(){
     SetSensorLight(IN_3);
     int T = 0, pace = 50;
     alth = true;
     for(m = 0; Go == true;)
     {
         OnFwdEx(OUT_A, pace, false);
         until( T > 180 || Sensor(IN_3) < thresh ){ T = MotorTachoCount(OUT_A);}
         until( T > 180 || Sensor(IN_3) > thresh ){ T = MotorTachoCount(OUT_A);}
         alth = AlterThresh(T, 160, 200, alth);
         Move(pace, MotorTachoCount(OUT_A) + 10);
         OffEx(OUT_A, false);
         Wait(100);
    
         OnFwdEx(OUT_A, -pace, false);
         until( T < 1 || Sensor(IN_3) < thresh ){T = MotorTachoCount(OUT_A);}
         until( T < 1 || Sensor(IN_3) < thresh ){T = MotorTachoCount(OUT_A);}
         alth = AlterThresh(T, -200, 20, alth);
         OffEx(OUT_A, false);
         Wait(100);
         if(alth == false && m == 0){thresh = thresh + 5; m = 1;}
     }
}

task DATA_LOG(){
     SetSensorLight(IN_3);
     int end, sta;
     while(Go == true){
          bool FR = true;
          int c = 0, now = CurrentTick();
          until(Sensor(IN_3) < thresh){
               if(CurrentTick() - now > 2000 && alth == false){ FR = false; MOTOR_CONTROL(false, 25); }}
          if(FR == true) MOTOR_CONTROL(true, 50);
          sta = MAP(MotorTachoCount(OUT_A), 180, 100);
          sound(800);
          until(Sensor(IN_3) > thresh);
          end = MAP(MotorTachoCount(OUT_A), 180, 100);
          sound(1000);
          line_position = (end + sta) / 2;
          if(sta > end) width = sta - end;
          else width = end - sta;
          for(;c<5;c++) where[c] = false;
          // 0-25, 25-35, 35-65, 65-75, 75-100
          if (line_position > 0 && line_position < 26) where[0] = true;
          if (line_position > 25 && line_position < 50 - (width/2)) where[1] = true;
          if (line_position > 50 - (width/2) && line_position < 50 + (width/2)) where[2] = true;
          if (line_position > 50 + (width/2) && line_position < 74) where[3] = true;
          if (line_position > 75 && line_position < 100) where[4] = true;
     }
}

task main(){
     RotateMotor(OUT_A, 35, -90);
     ResetTachoCount(OUT_A);
     Button = ButtonPressed(3, true);
     while(true)
     {
          start DISPLAY;
          start SCAN; sound(1500);
          for(int c=0;c<5;c++) where[c] = false;
          start DATA_LOG; sound(1500);
          Button = ButtonPressed(3, true);
          ant(true); sound(500);
          ant(false); sound(1000); Go = true;
     }
}


Wow!  If anyone has suggestions or comments, feel free to type, I am always looking for advice!  Also, be sure to check out my other blog the Legoton Press.  You can get there by clicking on "view complete profile" over on the right.

P.S. I recognize that by posting my code to the public, I have given you the permission to use and modify to any extent the said code.  But, this code may not be sold without permission from me, and I would appreciate it if you would give me credit if you do use this code.  Thank you!.