Subject:
|
Spybot studies: seek a world object
|
Newsgroups:
|
lugnet.robotics.spybotics
|
Date:
|
Mon, 10 Nov 2003 19:19:23 GMT
|
Viewed:
|
8470 times
|
| |
| |
/*
beacon.nqc
Uses World Relation Table to get a fix on and drive to another object.
The object can be a Spybot, PC, or Spybot Controller.
The program fixes on (i.e. drives to) the first object it finds. If that
object disappears from the "radar", it will fix on the next one. The
program exits when none are in range.
Functions illustrated:
ClearWorld()
FindWorld([WorldIndex], SPY_RANGE, REL_GT, RANGE_NOWHERE)
SetTargetID([WorldIndex])
Target(SPY_RANGE)
Target(SPY_DIRECTION)
Thoughts and discoveries.
1. The Spybot suffers from the same ills that most two-eared creatures do,
it can't tell whether an object is ahead left or behind right. This
leads it to go in the opposite direction that it should sometimes. There's a
word for this phenomenon, but I can't recall it.
2. I only registered LEFT_OF_CENTER and RIGHT_OF_CENTER when the
object was also in RANGE_HERE.
3. This program usually failed to fix acurately on a second target
after the initial target went to RANGE_NOWHERE.
4. There's probably a ROM routine that does the same thing as this
program, but it may not be useful from NQC.
Uses spy.nqh by John Hansen released 22 Oct 2003. See
http://news.lugnet.com/robotics/spybotics/?n=235
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*/
#include "spy.nqh"
// Convenience macros for my particular 'bot.
#define FWD(x) OnRev(x)
#define REV(x) OnFwd(x)
#define OUT_LEFT OUT_B
#define OUT_RIGHT OUT_A
task main()
{
int t = -1; // our index into the World Relation Table
int x; // temp var
int range; // range to the current target
int state = 0; // used for displaying SHORT_ID and RANGE on LEDs
ClearWorld(); // empty the World Relation Table
// wait for pings to be recieved.
// I think this wait could be smaller, but I don't know by how much.
// Probably something like 2x the default ping interval is enough.
Wait(100);
// FindWorld sets t to the next valid index in the World Relation Table
// or to -1 if there are no more entries.
FindWorld(t, SPY_RANGE, REL_GT, RANGE_NOWHERE);
while (t != -1)
{
// By using SetTargetID, we can use the Target() convenience methods
// for accessing the properities of the device.
SetTargetID(t);
x = Target(SPY_SHORTID);
// put ID of the current target in red LEDs
state = x & 0x7;
SetLED(LED_MODE_ON, state);
// Insure object is still in range before assuming other values are
good.
range = Target(SPY_RANGE);
while (range != RANGE_NOWHERE) {
x = Target(SPY_DIRECTION);
// put direction on green LEDs
state = (state & 0x7) | ((x & 0x7) << 3) ;
SetLED(LED_MODE_ON, state);
if (range == RANGE_HERE) { // we made it!
Off(OUT_A+OUT_B);
} else {
// Turn and move toward the target
switch (x) {
case DIRECTION_LEFT:
REV(OUT_LEFT);
FWD(OUT_RIGHT);
break;
case DIRECTION_LEFT_OF_CENTER:
Float(OUT_LEFT);
FWD(OUT_RIGHT);
break;
case DIRECTION_CENTER:
FWD(OUT_LEFT+OUT_RIGHT);
break;
case DIRECTION_RIGHT:
REV(OUT_RIGHT);
FWD(OUT_LEFT);
break;
case DIRECTION_RIGHT_OF_CENTER:
Float(OUT_RIGHT);
FWD(OUT_LEFT);
break;
default:
// should never get here
PlaySound(SOUND_LOW_BEEP);
} // end switch
} // end if range
range = Target(SPY_RANGE); // update the range to the target
} // end while in range
// If we're here, it means our current target moved to RANGE_NOWHERE
// so we need to acquire a new target.
FindWorld(t, SPY_RANGE, REL_GT, RANGE_NOWHERE);
} // end while
}
|
|
Message has 2 Replies: | | Re: Spybot studies: seek a world object
|
| (...) Cool program. Keep up the great work! (...) You might be able to use PointToward_Bead without running into problems. __nolist void PointToward_Bead(const int& nTimes) { asm { 0xe3, &nTimes, 0x17, 81, 0x01, 1 }; } This ROM routine monitors an (...) (21 years ago, 10-Nov-03, to lugnet.robotics.spybotics)
| | | Re: Spybot studies: seek a world object
|
| (...) Well We are trying to get Spybotics following an IR emitting Ball.. This ball will be emitting the same data as the Controller does on blinking mode.. But somehow the program above (as said before) Will not work propperly and send the spybot (...) (19 years ago, 25-Sep-05, to lugnet.robotics.spybotics)
|
14 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|