Subject:
|
Re: Infrared Ranging
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Thu, 26 Oct 2000 16:08:49 GMT
|
Viewed:
|
888 times
|
| |
| |
Here is a program letting you play with InfraRed Ranging using the
standard Light Sensor and the built in IR Communications Port. You
can play around with the THRESHOLD value with 2 light sensors and
see what kind of range and consistency you get at various levels.
The program lets you know if you are geting "Hits" by sending out
beeps, sort of like a Geiger Counter.
Feel free to disseminate, use and modify the code as needed.
Dave Chen
/*
* IRPing
* ======
* NQC code by David Chen, dcchen@pacbell.net, 1999
* Based on concept by Simen Svale Skogsruds
*
* Reads light level into Level, transmitts it out via SendMessage.
* If level > Thresh, a beep will sound to indicate proximity detection.
*
* Adjust threshold from initial THRESHOLD value by pushing touch
* sensors, IN_1 decreases Thresh, IN_3 increases Thresh.
*
* Mount Light Sensor, IN_2, pointing in same direction as the IR Port
*
* Mapping:
* OUT_A: empty
* OUT_B: empty
* OUT_C: empty
* IN_1: left touch sensor
* IN_2: light sensor
* IN_3: right touch sensors
*
* By Sending out DCYCLE IR "Pings" in a row followed by a rest
* period of OFF msec, you don't take as heavy a toll on battery
* life.
*
*/
#define DCYCLE 10
#define OFF 100
#define THRESHOLD 70
int Thresh;
int Level;
int Active;
int Lt;
int Rt;
int Max;
int Min;
task Control
{
while(true)
{
Lt = IN_1;
Rt = IN_3;
if((Lt == 1) && (Rt == 1))
{
wait((IN_1 == 0) && (IN_3 == 0));
if(Active == 1)
{
stop Ping;
Active = 0;
}
else
{
start Ping;
Active = 1;
}
PlaySound(2);
Lt = 0;
Rt = 0;
}
if(Lt == 1)
{
wait(IN_1 == 0);
Thresh -= 1;
PlayNote(400,5);
}
if(Rt == 1)
{
wait(IN_3 == 0);
Thresh += 1;
PlayNote(480,5);
}
}
}
task Ping
// Beeps if IN_2 > THRESHOLD
{
while(true)
{
repeat(DCYCLE)
{
SendMessage(Level);
Level = IN_2;
if(Level > Thresh)
PlayNote(360,1);
if(Level > Max)
Max = Level;
if(Level < Min)
Min = Level;
}
Sleep(OFF);
}
}
task main
{
// Set up the sensors
Sensor(IN_1,IN_SWITCH);
Sensor(IN_2,IN_CFG(STYPE_LIGHT, SMODE_PERCENT));
Sensor(IN_3,IN_SWITCH);
Thresh = THRESHOLD;
Active = 1;
Max = 0;
Min = 100;
// Start Tasks
start Control;
start Ping;
}
Michael Gasperi wrote:
>
> "Josh Hunter" <optijosh@cs.com> wrote in message
> news:G318tA.LBy@lugnet.com...
> > Hey. Does anyone know how i can accomplish IR ranging with my RCX? does the
> > light sensor respond to IR? how does it work? lend a brother a hand... lol
> =]
>
> Answers to all these questions can be found here:
> http://www.plazaearth.com/usr/gasperi/lego.htm
--
dcchen@pacbell.net
|
|
Message is in Reply To:
| | Re: Infrared Ranging
|
| "Josh Hunter" <optijosh@cs.com> wrote in message news:G318tA.LBy@lugnet.com... (...) the (...) =] Answers to all these questions can be found here: (URL) (24 years ago, 26-Oct-00, to lugnet.robotics)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|