Subject:
|
Question about NQC code
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Tue, 15 Jan 2002 20:12:46 GMT
|
Viewed:
|
3249 times
|
| |
| |
Hi,
I created the following light searching program:
#define speed 2
#define inaccuracy 2
int lightstrength, max, min;
task main()
{
SetSensor(SENSOR_2,SENSOR_LIGHT);
start searchforlight_a;
}
task searchforlight_a()
{
lightstrength = SensorValue(1);
SetPower(OUT_A+OUT_C,speed);
OnFwd(OUT_A);OnRev(OUT_C); // turn right
while(true)
{
if (SENSOR_2 >= lightstrength)
{
lightstrength = SensorValue(1);
}
if (SENSOR_2 < lightstrength)
{
start searchforlight_b;
stop searchforlight_a;
}
}
}
task searchforlight_b()
{
OnRev(OUT_A);OnFwd(OUT_C); // turn left
while(true)
{
if (SENSOR_2 >= lightstrength)
{
lightstrength = SensorValue(1);
}
if (SENSOR_2 < lightstrength)
{
OnFwd(OUT_A);OnRev(OUT_C); // turn right
start searchforlight_c;
stop searchforlight_b;
}
}
}
task searchforlight_c()
{
max = lightstrength + inaccuracy;
min = lightstrength - inaccuracy;
if ((SENSOR_2 >= min)||(SENSOR_2 <= max))
{
OnFwd(OUT_A+OUT_C); // drive forward
PlayTone(440,50);
}
}
However every time I run it, it doesn't seem to work. Does anyone got any
idea what could be the error in this program?
There is only one light sensor needed and it's connected to input 2. The
motors should be connected to output A and output C.
I hope someone can help me out here.
Thanks in advance,
Remi
|
|
1 Message in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|