Subject:
|
Re: Out of range
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Thu, 10 Dec 1998 17:17:14 GMT
|
Viewed:
|
1094 times
|
| |
| |
Hi,
I have some code that does this but it get kind of complicated to explain
but here goes....
1. I have a separate thread in my (C++) app that is used to poll the
cybermaster variables. I can
set which variables to check under program control.
2. I define two vars for use in communicating between the bot and the C++
program. The first BOT_CMD is used to write commands and data from the C++
app to the Bot. The 2nd BOT_STATUS is used to communicate status etc. from
the bot to the C++ program.
3. I define a set of bits for use with these variables...
const short BOT_CMD_REQ=(short)0x2000;
const short BOT_CMD_ACK=(short)0x4000;
const short BOT_CMD_MASK=(short)0xfff;
const short BOT_STAT_REQ=(short)0x4000;
const short BOT_STAT_ACK=(short)0x2000;
const short BOT_STAT_MASK=(short)0xfff
4. I then download a task to the bot that contains the following code....
BeginOfTask(0);
Loop(BOT_CONST, 0);
ClearTimer(0);
OrVar(BOT_STATUS, BOT_CONST, BOT_STAT_REQ);
While(BOT_TIMER, 0, LT, BOT_CONST, 25);
If(BOT_VAR, BOT_CMD, GT, BOT_CONST, BOT_CMD_REQ-1);
If(BOT_VAR, BOT_CMD, GT, BOT_CONST, BOT_CMD_ACK-1);
AndVar(BOT_STATUS, BOT_CONST, ~BOT_STAT_REQ);
AndVar(BOT_CMD, BOT_CONST, ~BOT_CMD_ACK);
EndIf();
If(BOT_VAR, BOT_CMD, GT, BOT_CONST, BOT_CMD_REQ-1);
AndVar(BOT_CMD, BOT_CONST, ~BOT_CMD_REQ);
StartTask(1);
EndIf();
EndIf();
EndWhile();
If(BOT_VAR, BOT_STATUS, GT, BOT_CONST, BOT_STAT_REQ-1);
PlaySystemSound(1);
Else();
PlaySystemSound(0);
EndIf();
EndLoop();
EndOf
5. In the C++ thread there is code which polls the variables every 10th of a
second or so (can be less frequent but this works well for me). When the
code polls the BOT_STATUS var it executes the following...
case BOT_STATUS:
// Provide feedback to Bot to tell it we are still here.
val = m_Spirit.Poll(BOT_VAR, BOT_STATUS);
if (val & BOT_STAT_REQ)
m_Spirit.OrVar(BOT_CMD, BOT_CONST, BOT_CMD_ACK);
val &= BOT_STAT_MASK;
// Actually use the status info....
break;
6. And that's all folks...
So basically what is going on here is that the bot sets a bit in the status
word and also starts a timer. If the ack bit in the command is set before
the timeout period (in this case approx 2.5 secs) then all is well and the
thing starts again (once the period has expired). If the ack is not set then
the bot assumes it has lost contact (and in the above sounds an alarm). The
C++ side simply checks for the BOT_STAT_REQ bit being set in BOT_STATUS and
when it sees it sets the BOT_CMD_ACK bit in BOT_CMD. Note that when the bot
sees the ack bit set it clears both this and the BOT_STAT_REQ bits for the
duration of the 2.5s loop, this reduces the amount of back and forth
traffic!
The actual code is rather more complex than the above since I use the
BOT_STAT and BOT_CMD vars for issuing command to the bot and getting actual
status back. This requires careful manipulation of the two vars and the use
of critical sections in the C++ to prevent the polling thread and the
command issuing thread trying to update things at the same time!
Anyway the bottom line is that I've been using the above for a while now and
it works fine. So far I've not added the code to try and get the bot to
return within range (when I do I will probably shorten the 2.5s timeout to
limit the distance covered after signal loss).
Hope this helps
Andy
|
|
Message is in Reply To:
| | Out of range
|
| [transferred to a new thread] I'm trying to create a good algorithm for detecting out of range situations with the tower, using NQCC. Have anybody already found a good way of doing this? My guess is that this is not possible, but... I have a (...) (26 years ago, 10-Dec-98, to lugnet.robotics)
|
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|