|
Hi Everybody,
I have used SendSpybotMsg and SendSpybotCtrlMessage (of course in connection
with resopective set messages) without any problems using BCC 3.3.7.5 and
3.3.7.9. These two commands gives RCX a nice control over spybot. Specially
SendSpybotMsg is capable of passing parameters embedeed to the message which I
haven't seen before. (If this is not the case please forgive me.)
Most important thing is SendSpybotMessage delivers last three parameters of the
SetSpybotMessage without altering them. So I thought them to use as my
parameters. I used NQC function BasicMove to test the functinality. first I
define the following constants.
#define CMD_BASIC_MOVE 0x24
#define SPY_CONTROLLER_BUTTON 0x40
#define CMD_BASIC_FORWARD 0x01
#define CMD_BASIC_BACKWARD 0x02
#define CMD_BASIC_SPINLEFT 0x03
#define CMD_BASIC_SPINRIGHT 0x04
#define CMD_BASIC_TURNLEFT 0x05
#define CMD_BASIC_TURNRIGHT 0x06
#define CMD_BASIC_AVOIDLEFT 0x07
#define CMD_BASIC_AVOIDRIGHT 0x08
#define CMD_BASIC_REST 0x09
#define CMD_BASIC_STOP 0x0A
Then I used following messages on my RCX Message Sender program.
SetSpybotMessage(MSG_BROADCAST, 0xD8, 0x04 , CMD_BASIC_MOVE, CMD_BASIC_FORWARD,
100);
SendSpybotMsg();
Wait(200);
SetSpybotMessage(MSG_BROADCAST, 0xD8, 0x04 , CMD_BASIC_MOVE, CMD_BASIC_BACKWARD,
100);
SendSpybotMsg();
Wait(200);
I slightly altered the John's version of SpyListner (only watchmessage task)
program as follows and add a function DoBasicMoves.DispCtrlBtn function was
added to test the outpit of SendSpybotCtrlMessage.
void DoBasicMoves(const int &y, const int &z)
{
switch(y)
{
case CMD_BASIC_FORWARD :
BasicMove(MOVE_BASIC_FORWARD, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_BACKWARD :
BasicMove(MOVE_BASIC_BACKWARD, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_SPINLEFT :
BasicMove(MOVE_BASIC_SPIN_LEFT, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_SPINRIGHT :
BasicMove(MOVE_BASIC_SPIN_RIGHT, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_TURNLEFT :
BasicMove(MOVE_BASIC_TURN_LEFT, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_TURNRIGHT :
BasicMove(MOVE_BASIC_TURN_RIGHT, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_AVOIDLEFT :
BasicMove(MOVE_BASIC_AVOID_LEFT, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_AVOIDRIGHT:
BasicMove(MOVE_BASIC_AVOID_RIGHT, z); BasicMove(MOVE_BASIC_STOP, 2);
break;
case CMD_BASIC_REST:
BasicMove(MOVE_BASIC_REST, z); BasicMove(MOVE_BASIC_STOP, 2); break;
case CMD_BASIC_STOP:
BasicMove(MOVE_BASIC_STOP, z); BasicMove(MOVE_BASIC_STOP, 2); break;
default :
Disp(ANIMATION_SPARKLE); break;
}
}
void DispCntlBtn(const int &b)
{
switch(b)
{
case CONTROLLER_BUTTON1 :
PlaySound(SOUND_HIT_BY_LASER); SetLED(LED_MODE_ON, 0x02); Wait
(20); break;
case CONTROLLER_BUTTON2 :
PlaySound(SOUND_HIT_BY_LASER); SetLED(LED_MODE_ON, 0x03);
break;
case CONTROLLER_BUTTON3 :
PlaySound(SOUND_HIT_BY_LASER); SetLED(LED_MODE_ON, 0x04);
break;
case CONTROLLER_BUTTON4 :
PlaySound(SOUND_HIT_BY_LASER); SetLED(LED_MODE_ON, 0x05);
break;
case CONTROLLER_BUTTON5 :
PlaySound(SOUND_HIT_BY_LASER); SetLED(LED_MODE_ON, 0x06);
break;
default :
PlaySound(SOUND_CRASH); SetLED(LED_MODE_ON, 0x07); break;
} // End of Controller Button Commands
}
task WatchMessage()
{
while (true)
{
monitor (EVENT_MASK(MessageEvent))
{
Wait(100);
}
catch
{
PlaySound(SOUND_SHOCKED);
int a = RxMessage(MSG_IR, MSG_INDEX);
*p = a; p++;
int b = RxMessage(MSG_IR, MSG_COMMAND);
*p = b; p++;
int y = RxMessage(MSG_IR, MSG_HI_BYTE);
*p = y; p++;
int z = RxMessage(MSG_IR, MSG_LO_BYTE);
*p = z; p++;
int x = y * 256 + z;
switch(b)
{
case SPY_CONTROLLER_BUTTON:
DispCntlBtn(x);
break;
case CMD_FIRE_LASER:
PlaySound(SOUND_SHOCKED); SetLED(LED_MODE_ON, 0x08); break;
case CMD_FIRE_SPINNER:
PlaySound(SOUND_SHOCKED); SetLED(LED_MODE_ON, 0x09); break;
case CMD_FIRE_ELECTRONET:
PlaySound(SOUND_SHOCKED); SetLED(LED_MODE_ON, 0x0A); break;
case CMD_BASIC_MOVE:
DoBasicMoves(y, z);
break;
default :
PlaySound(SOUND_CRASH); SetLED(LED_MODE_ON, 0x20); break;
}
}
}
}
Now by sending
SetSpybotMessage(MSG_BROADCAST, 0xD8, 0x04 , CMD_BASIC_MOVE, CMD_BASIC_FORWARD,
100);
I can ask my spybot to "Move forward Normally for 1 second". I have tested
couple of other spybot utility functions such as "RandomMove", "FancyMove" etc
without any problem (Of course thanks to Dave to incorperate them on NQC).
Now I am thinking about developing spybot missions that can controlled by RCX. I
used only one spybot (that is all I have) to receive messages so I don't know
how it will behave if you have more than one spybot. If somebody can do that it
will be great help.
Hope somebody will find a value here. If anybody need more clarifications please
don't hesitate to drop me a mail.
Alex Jayasundara
|
|
Message is in Reply To:
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|