To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 10087
10086  |  10088
Subject: 
need help for my IR proximity program
Newsgroups: 
lugnet.robotics
Date: 
Sat, 15 Jan 2000 14:16:12 GMT
Original-From: 
dominic frutiger <droid11@student.ethzSPAMCAKE.ch>
Viewed: 
763 times
  
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi,

I am new here and I just bought my Invention Kit four days ago.
I searched the web for infos and found really great stuff - including
this mailing list.

I am only posting my small program for IR proximity detection and a
cruise simulator (just tones instead of motors).
This Program is compilable and working so far - but bad configured.

There is surely somebody out there who has solved a similar problem
(IR proximity detection) and who could give me tipps how to configure
the constants (at the beginning of the program) - because it is
really difficult to get a proper signal.
It's my first program with NQC, and since i'm not so familiar with
this language (i'm not really familiar with any programming
language...) i would appreciate any comment and warnings what i
should do and what not (because of limited memory for example).

Please tell me, if i am not allowed to post programs or something and
i will never do it again =).

have a nice day
df



//START
PROGRAM_______________________________________________________

// IR Proximity Warner + Cruise Simulator

/*
Author: Dominic Frutiger - Switzerland
Date:   15.01.00
Thanks: to the whole internet lego community and especially
        to Svale Skogsrud who inspired this program with his hompage:
http://www.mop.no/~simen/index.htm
*/


// VARIABLES
***************************************************************

int diffLimitFar   =    50;     // difference limits when to react
how
int diffLimitNear  =   130;     // far means small difference
int diffLimitClose =   150;     // close means big difference

int maxCount       =     2;     // how many checks steps before
reaction
int inputCount;

int waitCheck      =    10;     // wait between check steps   100 = 1
sec

int newInput;
int oldInput;

int proxMax;
int proximity      =     0;




// FUNCTIONS
***************************************************************

void CruiseMax(){

           PlayTone(800, 5);

}


void SlowDown(){

           PlayTone(600, 5);

}


void Rewind(){

           PlayTone(200, 5);

}


void Turn(){

           PlayTone(400, 5);

}


// TASKS
*******************************************************************


task ProximityDetection(){

SendMessage(255);
                        newInput = SENSOR_2;             // first
input stored
inputCount = 0;                  // initialized

while(true)
                        {
                          proxMax    = 0;
                          inputCount = 0;              // start
again with counting

                          while(inputCount < maxCount){        //
check as many times as maxCount

  SendMessage(255);
                          oldInput  = newInput;
                          newInput  = SENSOR_2;          // second
input stored
                          oldInput -= newInput;          //
difference of two inputs

  if(oldInput < 0){
                            oldInput *= -1;              // make
difference positiv
                                }

                                if(oldInput > proxMax){
// if difference confirmed
                                        proxMax = oldInput;
                                inputCount++;                  //
next step to confirm

                                        Wait(waitCheck);
// wait before new proximity check
}
                                else{
                                        proxMax    = 0;
// wrong input so do it again
                                        inputCount = 0;
}                                      // end while


                          }

                          proximity = proxMax;
// value confirmed so use it now


  if(proximity>diffLimitFar && proximity<=diffLimitNear){
                                proximity = diffLimitFar;
  }

                          if(proximity>diffLimitNear &&
proximity<=diffLimitClose){
                                proximity = diffLimitNear;
  }

                          if(proximity>diffLimitClose){
        proximity = diffLimitClose;
  }

                        }      // end while

                      }        // task


task Cruising(){

                        while(true){

                                if(proximity <= diffLimitFar){
                                        CruiseMax();
                                }

                                if(proximity == diffLimitFar){
                                        SlowDown();
                                }

                                if(proximity == diffLimitNear){
                                        Turn();
                                }

                                if(proximity == diffLimitClose){
                                        Rewind();
                                }

}   // while

}                           // task



// MAIN
**********************************************************************


task main(){

SetSensorType(SENSOR_2, SENSOR_TYPE_LIGHT);
SetSensorMode(SENSOR_2, SENSOR_MODE_RAW);

SetTxPower(TX_POWER_HI);

PlayTone(800, 5);                     // cruising tone sample

Wait(100);                            // wait until you pulled your
hand back =)

start ProximityDetection;
start Cruising;

}


//END
PROGRAM___________________________________________________________



-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.1i for non-commercial use <http://www.pgpi.com/>
Comment: have a nice day

iQA/AwUBOIBy4mhRss7572OyEQL38gCgzmoM4XxNitBIbbPUjcklGH4mXQsAmgJF
D0RzwhZ0d0htV+ttcZRXaMhZ
=KSUv
-----END PGP SIGNATURE-----



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR