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 / 846
845  |  847
Subject: 
Electrical Data Link between 2 RCXs
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Wed, 25 Oct 2000 13:35:07 GMT
Viewed: 
1888 times
  
The following describes an "electrical data link" (one direction) between 2
RCXs (see also my subject "Connecting 2 RCXs").

The task is that one RCX sends a number (e.g. a status) to another RCX via a
cable. The IR link cannot be used because they can't "see" each other. So, the
output of the transmitting RCX is connected with the input of the receiving RCX
(input set to TOUCH_SENSOR). The data link should be fast, allowing the
receiving RCX to react quickly.

The transmitting RCX generates a sequence of 1's and 0's
The protocol is very simple: it consists of a startbit and 3 following bits,
allwoing seven numbers (1 - 7) to be transmitted. The duration of each bit is
around 30 ms. E.g. the output for a 5 ("101") would be


_____|---------------|_______|-------|_________
          |  start  |  bit 2  |   bit 1    |   bit 0  |

          ^              ^           ^           ^
The above symbols (^) show the points of time when the receiving RCX checks the
status of the bits. At first the routine will wait for a 1 at the input.
Afterwards it waits for the end of the startbit (30 ms). A delay of 10 ms is
performed. After that every 30 ms the bits 2 to 0 are checked. The whole
transmission is 120 ms long (see below remarks about timing).

The 1's and 0's are created by setting the motor output of the transmitting RCX
to OFF for a 1 and to FLOAT for a 0 (thanks to Dean Husby for this "trick" -
note, that by this procedure no voltage is being sent to the input of the
receiving RCX).

The two programs are given below. They work well with a cycle of 30 ms. Using
20 ms for each bit may lead to wrong numbers, due to the RCX's slow execution
of statements (see also subject "Timing of RCX statements). Of yourse it would
be nicer to have a more general program that allows transferring of an 8 bit
number (1 to 255). I tried this out with a code like

if ((num & 0x08) == 0x08) {_setbit;} else {_clrbit;}
if ((num & 0x04) == 0x04) {_setbit;} else {_clrbit;}
if ((num & 0x02) == 0x02) {_setbit;} else {_clrbit;}
if ((num & 0x01) == 0x01) {_setbit;} else {_clrbit;}

but I could not get a stable timing (i.e. equidistant bits) unless I increased
the duration of a single bit to 100 ms or more and using a timer. The demand
for a fast link won't be fulfilled. But for transmitting small numbers out of a
set of seven like e.g. a status (e.g. 1 = drive, 2 = stop, 3 = move arm, etc.)
the given programs are fine and the compiled code for the transmitting routine
is fairly small.

// Program for TRANSMITTING RCX
//
#define _tbit 3
#define _setbit Off (OUT_B); Wait (_tbit); Float (OUT_B);
#define _clrbit Float (OUT_B); Wait (_tbit); Float(OUT_B);

int num;

task main ()
{
  Float (OUT_B);

  while (true) {
    ClearMessage ();
    until (Message() != 0);
    num = Message ();
    PlayTone (2000, 5);

    switch (num)
    {
      case 1 :
      {_setbit;
       _clrbit;
       _clrbit;
       _setbit;
       break;}
      case 2 :
      {_setbit;
       _clrbit;
       _setbit;
       _clrbit;
       break;}
      case 3 :
      {_setbit;
       _clrbit;
       _setbit;
       _setbit;
       break;}
      case 4 :
      {_setbit;
       _setbit;
       _clrbit;
       _clrbit;
       break;}
      case 5 :
      {_setbit;
       _setbit;
       _clrbit;
       _setbit;
       break;}
      case 6 :
      {_setbit;
       _setbit;
       _setbit;
       _clrbit;
       break;}
      case 7 :
      {_setbit;
       _setbit;
       _setbit;
       _setbit;
       break;}

      default :
      {}
      }
    }
}

// Program for REVEIVING RCX
//
#define _tbit 3

int num;
int display;

task main ()
{
  SetSensor (SENSOR_1, SENSOR_TOUCH);

  while (true)
  {
  num = 0;
  ClearSensor (SENSOR_1);
  until (SENSOR_1 == 1);   /* wait for Startbit */
  Wait (_tbit);

  Wait(1);                 /* delay */
  if (SENSOR_1 == 1) num = num + 0x04;
  Wait (3);

  if (SENSOR_1 == 1) num = num + 0x02;
  Wait (3);

  if (SENSOR_1 == 1) num = num + 0x01;
  Wait (3);

  display = num;
  SetUserDisplay (display, 0);
  PlayTone (4000, 5);
  }
}



Message has 1 Reply:
  Re: Electrical Data Link between 2 RCXs
 
(...) Have you tried using SENSOR_MODE_EDGE or PULSE? Maybe it can keep track of it better? Edge could be very useful as it can count both on's and off's whereas pulse counts only on's. Dean -- Coin-Op's For Sale!: (URL) Lego Workshop: (URL) Lego (...) (24 years ago, 25-Oct-00, to lugnet.robotics.rcx.nqc)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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