To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1750
1749  |  1751
Subject: 
Re: Sending Commands to Spybot from RCX - Question from a Beginner to Comm area.
Newsgroups: 
lugnet.robotics.spybotics, lugnet.robotics, lugnet.robotics.rcx, lugnet.robotics.rcx.nqc
Date: 
Tue, 8 Feb 2005 15:33:12 GMT
Viewed: 
272 times
  
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:
  Re: Sending Commands to Spybot from RCX - Question from a Beginner to Comm area.
 
(...) First of all, my apologies for not answering you via email. I've been a bit busy at work. I needed to run some tests myself before I could properly respond as well. The 0x9223 from the RCX happens to match the IR sent out by the Spybot (...) (20 years ago, 28-Jan-05, to lugnet.robotics.spybotics, lugnet.robotics, lugnet.robotics.rcx, lugnet.robotics.rcx.nqc)

3 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
17 hours ago
Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR