| ||||||||||||||
| ||||||||||||||
|
||||||||||||||
Proximity Detection Learning Using NQC
The RobotThe robot that I built was basically a Roverbot as described in the Constructopedia with the standard four wheel setup. At the front of robot I set up a light sensor and touch sensor next to each other. What I wanted was for the robot to adapt its proximity threshold to the light settings. The touch sensor is used to help the robot calculate the optimal threshold.
Threshold?What is the threshold? We will get our IR port to send out a signal roughly every 1/10th second. If we are close enough to something, the IR signal will reflect back and hit our light sensor which will register an abrupt change its reading. The threshold is the minimum change between readings. Let us look at a sample datalog entry:
The Program
I thought it'd be cool if the robot tested different proximities to find an optimal proxmity setting. In the end, the method I used was pretty crude, since we start with a proximity threshold of 800, and just halve it every time it collides with something. There are two conditions under which the robot will edit the threshold: if it crashes into a wall before even detecting it, and if it crashes into a wall while floating the motors (I decided not to stop the motors outright - this gives more realistic motion, in my opinion).Here is the NQC code: //////////////////////////////////////////////////
// Program: Learning Proximity Robot
// Author: James Matthews
// Date: 23rd August, 2000
// URL: http://www.generation5.org/
//
// This is a simple program using a threshold to
// control the proximity. This means that it can
// used in any lighting and environment, and it will
// "adapt". The mechanism is incredibly simple, so
// no guareentees how good it is!! It also plays a
// little "victory chant" when it doesn't collide
// upon stopping.
int ls_lastlevel; // To store the previous light sensor level
int ls_threshold; // The currently used threshold
int collided; // Did we collide this session?
task Send_Signal() {
while(true)
{SendMessage(0); Wait(10);}
}
task Check_Signal() {
while(true) {
ls_lastlevel = SENSOR_2;
if (SENSOR_2 > ls_lastlevel + ls_threshold) {
collided = 0;
Float(OUT_A+OUT_C);
start Check_Collision;
Wait(100);
stop Check_Collision;
if (collided == 0) {
PlaySound(5);
StopAllTasks();
}
}
if (SENSOR_1 == 1) {
ls_threshold = ls_threshold / 2;
OnRev(OUT_A+OUT_C);
Wait(200);
OnFwd(OUT_A+OUT_C);
}
}
}
task Check_Collision() {
while (true) {
if (SENSOR_1 == 1) {
ls_threshold = ls_threshold / 2;
collided = 1;
OnRev(OUT_A+OUT_C);
Wait(200);
OnFwd(OUT_A+OUT_C);
}
}
}
task main() {
ls_threshold = 800;
// Setup the sensors
SetSensorType(SENSOR_1, SENSOR_TYPE_TOUCH);
SetSensorType(SENSOR_2, SENSOR_TYPE_LIGHT);
SetSensorMode(SENSOR_2, SENSOR_MODE_RAW);
OnFwd(OUT_A+OUT_C);
start Send_Signal;
start Check_Signal;
}
Pretty simple. I used the excellent RCX Command Center to program, compile, and download the program as well as collect the datalog information. Thanks to Mark Overmars for his excellent program and huge tutorial on NQC programming.
Submitted: 23/08/2000 Article content copyright © James Matthews, 2000.
|
|
|||||||||||||
All content copyright © 1998-2007, Generation5 unless otherwise noted.
- Privacy Policy - Legal - Terms of Use -