Subject:
|
Re: Spybots communication
|
Newsgroups:
|
lugnet.robotics.spybotics
|
Date:
|
Tue, 16 Mar 2004 21:46:26 GMT
|
Viewed:
|
7695 times
|
| |
| |
In lugnet.robotics.spybotics, Adam Kowalski wrote:
> Hello, how can I establish communication between Spybots. Ive found
> SendSpybotMessage function in extended John Hansens spybot api, but I dont
> know how to use it. I want to use two spybots to build one robot, so I need two
> way communication between them.
To send and receive IR or VLL messages using NQC and Spybots you would write a
program something like this:
#define VLLEvent 1
#define MessageEvent 2
void DebugOut(const int &x)
{
SetLED(LED_MODE_ON, (x & 0x17) | ((x & 8) * 4) | ((x & 32) / 4));
SetLED(LED_MODE_YELLOW, (x / 64) & 0x01);
SetLED(LED_MODE_VLL, x & 0x80);
}
task WatchVLL()
{
while (true)
{
monitor (EVENT_MASK(VLLEvent))
{
Wait(100);
}
catch
{
PlaySound(SOUND_GOT_IT);
DebugOut(VLL()); // display VLL code on LEDs
}
}
}
task WatchMessage()
{
while (true)
{
monitor (EVENT_MASK(MessageEvent))
{
Wait(100);
}
catch
{
int x = RxMessage(MSG_IR, MSG_HI_BYTE) * 256 + RxMessage(MSG_IR,
MSG_LO_BYTE);
switch(x)
{
case 0x0200 :
// RCX sent 0x9223 (controller red button)
PlaySound(SOUND_SHOCKED);
Disp(ANIMATION_SPARKLE);
break;
case 0x0103 :
// RCX sent 0x92ab
PlaySound(SOUND_HIT_BY_LASER);
Disp(ANIMATION_ALARM);
break;
default :
PlaySound(SOUND_CRASH);
Disp(ANIMATION_SCAN);
break;
}
}
}
}
task main()
{
SetPingInterval(0); // turn off Spybot ping
SetRCRxChannel(RC_CHANNEL_2); // Receive IR messages on channel 2
// setup the IR and VLL message events
SetEvent(MessageEvent, VLL(), EVENT_TYPE_MSG_RECEIVED);
SetEvent(VLLEvent, VLL(), EVENT_TYPE_VLL_MSG_RECEIVED);
// start our watcher tasks
start WatchVLL;
start WatchMessage;
int i = 0;
while (true)
{
Wait(100);
// send out a spybot broadcast message (link, cmd, hi, lo)
SendSpybotMessage(INDEX_BROADCAST, COMMAND_CONTROLLER, 0x02, i);
// wait a second
Wait(100);
// also send out a VLL command every 2 seconds
SendVLL(i);
i++;
}
}
This is essentially a port to NQC from a MindScript program that Mark Riley
wrote quite a while ago (http://news.lugnet.com/robotics/spybotics/?n=56).
All of these functions should be documented in the BricxCC help (release
3.3.7.7). With NQC 3.0a2 you don't need to #include the spy.nqh file for this
to compile against the Spybot target.
You might want to link the two Spybots using a light pipe and use SendVLL and
EVENT_TYPE_VLL_MSG_RECEIVED rather than SendSpybotMessage and
EVENT_TYPE_MSG_RECEIVED. SendSpybotMessage will work as well but you might get
interference from other IR sources.
Let us all know how it works out for you.
John Hansen
http://bricxcc.sourceforge.net/
|
|
Message is in Reply To:
| | Spybots communication
|
| Hello, how can I establish communication between Spybots. Ive found SendSpybotMessage function in extended John Hansens spybot api, but I dont know how to use it. I want to use two spybots to build one robot, so I need two way communication (...) (21 years ago, 22-Feb-04, to lugnet.robotics.spybotics)
|
2 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|