To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 2730
2729  |  2731
Subject: 
Re: RCX to RCX communication
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Mon, 15 Jul 2002 01:48:15 GMT
Viewed: 
2687 times
  
"Luke Ma" <Luke_Ma@brown.edu> wrote in message news:Gz83nF.7D9@lugnet.com...
In lugnet.robotics.rcx.legos, Mark Sackett writes:
I have studied the sources on the WEB for LNP but have not found any
examples of C or C++ code for RCX to RCX communication.  I have two RCXs • and
would like to build something that takes advantage of 6 inputs and 6 • outputs.

Do you have a sample you would be willing to share?

Thanks,
Mark

Mark,
  I was a TA(Teaching Assistant) for a course at Brown University that
invovled building robots with the mindstorms kit.  Go to the web site:
http://www.cs.brown.edu/courses/cs148 and click on the link to take you to

eep.

erm... we never posted RCX-RCX sample code up.  never gave any of the
students two bricks.  and the LNP code up on our website has our own hacked
up libraries and stuff.

Below is a sample set of programs.  It consists of two files which I've
named brick1.c and brick2.c  It's not the prettiest code, but it should give
you an idea of how to do RCX-RCX communication.  I've assumed that the brick
running brick1.c has LNP host address 0x10, and is listening on port 1.  If
you feel masochistic, you can read through the docs I ripped up on the
aforementioned website.

hope this helps a little.

Albert

file:// brick1.c
--------------------
#include <lnp/lnp.h>
#include <string.h>
#include <conio.h>
#include <dlcd.h>
#include <dsound.h>

char address_buf[255];
int buf_len = 0;
char sender;

note_t notes_short[] = { { PITCH_C4, EIGHTH },
                         { PITCH_END, EIGHTH } };

static void port_handler(const unsigned char *data,
                         unsigned char length,
                         unsigned char src)
{
  memcpy(address_buf, data, length);
  sender = src;
  buf_len = length;
}

static wakeup_t havepack(wakeup_t w)
{
  return buf_len;
}

int read_from_ir(char *data, unsigned char *src)
{
  int ret;
  wait_event(havepack, 0);
  memcpy(data, address_buf, buf_len);
  ret = buf_len;
  buf_len = 0;
  if (src) *src = sender;
  return ret;
}

int main(int argc, char *argv[])
{
  char buf[256];
  int len;

  lnp_addressing_set_handler(1, port_handler);

  while(1)
    {
      len = read_from_ir(buf, 0);
      lcd_int(len);
      msleep(500);
      dsound_play(notes_short);
      cputs(buf);

      msleep(1000);
      cls();
    }

  return 0;
}
------------------------------------

file:// brick2.c
--------------------------------------
#include <lnp/lnp-logical.h>
#include <lnp/lnp.h>
#include <conio.h>
#include <string.h>
#include <dlcd.h>
#include <dsound.h>

#define BRICK1_DEST 0x11

char address_buf[255];
int buf_len = 0;
char sender;

int main(int argc, char *argv[])
{
  char buf[256];

  strcpy(buf, "1234");
  cputs(buf);

  lnp_logical_range(1);

  lnp_addressing_write(buf, strlen(buf),
                       BRICK1_DEST, 1);

  msleep(1000);

  strcpy(buf, "brik");
  cputs(buf);

  lnp_addressing_write(buf, strlen(buf),
                       BRICK1_DEST, 1);

  return 0;
}



Message is in Reply To:
  Re: RCX to RCX communication
 
(...) Mark, I was a TA(Teaching Assistant) for a course at Brown University that invovled building robots with the mindstorms kit. Go to the web site: (URL) and click on the link to take you to the normal page. Then go to the "LegOS" section fo the (...) (22 years ago, 14-Jul-02, to lugnet.robotics.rcx.legos)

3 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