View unanswered posts | View active topics It is currently Fri Apr 18, 2014 5:15 am






Reply to topic  [ 134 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9  Next
1.45..1.40 public: RS485 connection for M/S-muxing? samples? 
Author Message
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: how to use RS485 connection? code samples?
I have some working code by now. Me and Docilio already tested with 2 NXT but function for max 4 (changeable).

Any feedback would be apreciated.

:downloading:

The ideia is a task controling the comunication and 2 buffers and a token ring tipology. The next one to speak is the one with the next id in the message head (sender field). If there is no message to be sent, it sends a null message just to give the other NXT the control of the line.

This program cam be used for multi master aplications.

Code:
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                         Port S4 High-Speed RS-485 Full Duplex Token Ring
//
// Autor  : Tiago Gonçalves (ogait87)
// Release: 0.0.3
// Date   : 30/08/2008
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma platform(NXT)

//#define HSPEED_DEBUG

long nXmitSuccesses = 0;
long nRcvChars = 0;

void setupHighSpeedLink(const bool bMaster)
{
   //
   // Initialize port S4 to "high speed" mode.
   //
   nxtEnableHSPort();
   //nxtSetHSBaudRate();
   nxtHS_Mode = bMaster ? hsMsgModeMaster : hsMsgModeSlave;

   //
   // Configure the link for raw read and write. User program will have complete control over the link.
   // User program will be responsible for managing the half-duplex operation and must prevent collisions!
   //
   nxtHS_Mode = hsRawMode;

   return;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                        Driver Task
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
ubyte HSpeedTxData[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int   HSpeedTxDataLen = 0;
ubyte HSpeedRxData[17] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int   HSpeedRxDataLen = 0;

int   MaxNXT = 0;
int   IAmNXT = 0;

task HSpeed()
{
   bool IAmMaster = false;
   int timeout;
   int dest, len;
   ubyte TxData = (IAmNXT << 6);
   ubyte lixo = 0x00;
   ubyte head;
   int i;
   ClearTimer(T1);

#ifdef HSPEED_DEBUG   
   int master_count = 0;
   int head_count = 0;   
   int loop_count = 0;
   int timeout_count = 0;
#endif

   while(true)
   {
#ifdef HSPEED_DEBUG
      loop_count++;
        nxtDisplayTextLine(4, "LOOP: %d", loop_count);
#endif
      if ( IAmMaster )
      {
         if ( HSpeedTxDataLen > 0)
         {
            HSpeedTxData[0] = HSpeedTxData[0] << 4;
            HSpeedTxData[0] = HSpeedTxData[0] | (IAmNXT << 6);
            HSpeedTxData[0] = HSpeedTxData[0] | HSpeedTxDataLen;
            nxtWriteRawHS(HSpeedTxData, HSpeedTxDataLen+1, 0); // == ioRsltSuccess
            HSpeedTxDataLen = 0;
         }
         else
         {
            nxtWriteRawHS(TxData, 1, 0);
         }
         // Dar tempo ao recetor receber e procesar a mensagem
         IAmMaster = false;
#ifdef HSPEED_DEBUG
         master_count++;
         nxtDisplayTextLine(6, "MASTER: %d", master_count);
#endif
         wait1Msec(100);
      }
      timeout = random[1000] + 2000;
      ClearTimer(T1);

      while( nxtGetAvailHSBytes() <= 0 && time1[T1] < timeout)
         wait1Msec(10);

      // Houve erro na comunicao e niguem sabe quem e a vez de falar
      if ( time1[T1] >= timeout )
      {
         IAmMaster = true;
#ifdef HSPEED_DEBUG
         timeout_count++;
         nxtDisplayTextLine(7, "TIMEOUT: %d", timeout_count);
#endif
         continue;
      }

      // Recebi pelo menos 1 byte
      nxtReadRawHS(head, 1);

#ifdef HSPEED_DEBUG
      head_count++;
      nxtDisplayTextLine(5, "HEAD: %d C: %d", (int) head&0xFF, head_count);
#endif

      // Sou o proximo?
      if ( ((head >> 6) + 1) % MaxNXT == IAmNXT)
      {
         IAmMaster = true;
      }

      // Processar o corpo da mensagem
      len = head&0x0F;
      if( len != 0 )
      {
         dest = (head>>4) & 0x3;
#ifdef HSPEED_DEBUG
         nxtDisplayTextLine(3,"PM Master:%d", (byte) IAmMaster);
#endif
         i = 0;
         while( i < len)
                {
            while(nxtGetAvailHSBytes() <= 0)
            wait1Msec(10);

            nxtReadRawHS(lixo, 1);

            if ( dest == IAmNXT )
               HSpeedRxData[i+1] = lixo;

            i++;
         }

         if ( dest == IAmNXT )
         {
            HSpeedRxData[0] = head>>6;
            HSpeedRxDataLen = len;
         }
         else
         {
            HSpeedRxDataLen = 0;
         }
#ifdef HSPEED_DEBUG
         if ( dest == IAmNXT )
         {
            nxtDisplayTextLine(3, "PARA MIM");
         }
         else
         {
            nxtDisplayTextLine(3, "IGNORE");
         }
#endif
      }
      wait1Msec(100);
   }
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//                                        Main Task
//
////////////////////////////////////////////////////////////////////////////////////////////////////////

task main()
{
   string sFriendlyName;
   int count = 0;
   long loop_count = 0;
   long send_count=0;

   setupHighSpeedLink(true);

   MaxNXT = 2;

   getFriendlyName(sFriendlyName);
   IAmNXT = sFriendlyName == "HRF1" ? 0 : 1;

   eraseDisplay();
   bNxtLCDStatusDisplay = true; // Enable top status line display

   nxtDisplayTextLine(2, "IAmNXT: %d MAX: %d", IAmNXT, MaxNXT);

   StartTask(HSpeed);

   ClearTimer(T2);

   while(true)
   {
      nxtDisplayTextLine(3, "Loop: %d", loop_count++);

      while(HSpeedRxDataLen == 0 && time1[T2] < 1000)
      {
         nxtDisplayTextLine(3, "Loop: %d %d", HSpeedRxDataLen, time1[T2]);
         wait1Msec(10);
      }

      if ( HSpeedRxDataLen != 0 ) // Recebi Algo
      {
         count ++;
         nxtDisplayTextLine(6, "Rx: ID %d Len %d", (int)HSpeedRxData[0], HSpeedRxDataLen);
         nxtDisplayTextLine(7, "Rx: %d", count);
         HSpeedRxDataLen = 0;
      }

      if ( time1[T2] > 1000)
      {
         send_count++;
         HSpeedTxData[0] = IAmNXT == 0 ? 1 : 0;
         HSpeedTxData[1] = 1;
         HSpeedTxDataLen = 1;
         nxtDisplayTextLine(4, "Send: %d", send_count);
         ClearTimer(T2);
      }
   }
}

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/


Thu Sep 04, 2008 6:52 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
hi,
looks fine :))
but 2 questions before I can start testing:
where do you have to define the nxt ID's for every single brick?
Do have to give the bricks special names as before?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Fri Sep 05, 2008 6:29 am
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post Re: 1.40 public: how to use RS485 connection? code samples?
Ford Prefect wrote:
where do you have to define the nxt ID's for every single brick?


On that code the nxt ID is give as the other code(with the bricks name)

Ford Prefect wrote:
Do have to give the bricks special names as before?


Code:
   IAmNXT = sFriendlyName == "HRF1" ? 0 : 1;


to more than 2, we need only to change this IAmNXT to a diferent code...

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Fri Sep 05, 2008 6:33 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post RS485 standardization
hi,
looks very fine! I tested it and as far as I can see there's something happening ;)
but to be honest, I can't see WHAT'S happening :$

to improve your code and to make the code more standardized, I'll suggest the following:
1) generally the alowed friendlynames should only be "00", "01", "02",.."255" for EVERY RS485 protocoll written in future by anyone,
2) maybe the names may be set by a routine in the code itself (sfriendlyname="03" or whatever)
3) master always is nxt "00" in order to superior controlling purposes
4) the RS485 code should be written to a header file ("RS485com.h") which can be included as #include "RS484com.h" by any user program
5) the header file contains all needed interface functions:
- the RS485 protocoll should be activated by a function void RS485Init(), which starts an endless task for the comm message sending / receiving switching;
- RS485SendBytes(byte[12] myByteArray) sends 12 bytes or ubytes
- RS485GetBytes (byte[12] myByteArray) receives 12 bytes or ubytes
- the series of bytes in the ByteArrays have certain meanings as descibed befor (adressee, sender, length_of_data, sort_of_data, message, ..) which still has to be optimized

EDIT:
imagine: there are several bricks, each brick sends various events by various tasks.
Now many messages come to a receiver - how can the receiver know what data this is and what to do with it?

If it's a sensor value: from which sensor port?
If it's a calculated variable value: of which variable (you might give them numbers for transmission)

is it an integer value?
is it a float value?

The event might be the following:
e.g., you may have a ultra sonic distance Sensor at your nxt 01 (port 0=S1), and in case an obstacle has been detected, a message containig this SensorValue has to be transmitted to the "Master":

Then imagine, there may be an infrared Sensor on brick 02 port 02 which just detected a IR soccer ball; immediately he also sends his discovery to the master at almost the same time. So 2 messages arrive at the addressee and he must be able to distinguish which which message contains what kind of data (e.g., display this value on the master's screen or start/stop a motor)


this following might be the 1st message, a 2nd message may look similar:

Code:
if SensorValue[0]>=100 // send in case a wall (e.g., raw=400) has been detected
{
  myByteArray[0]=0; // addressee: Master=00
  myByteArray[1]=1; // own address 01
  myByteArray[2]=00 // sensor port 0 --- or alternatively  a message ID (to answer to a request?)
  myByteArray[3]=02 // 2 byte integer (short)
  myByteArray[4]= 0xC0 // value=400 => lowByte of SensorValue=400-256=144 
  myByteArray[5]= 0x01 // value=400 => hiByte of SensorValue=1*256
  myByteArray[6]= 0x00  // needed only for 4 byte int
  myByteArray[7]= 0x00  // needed only for 4 byte int
  myByteArray[8] =... // needed only for 8 byte int/float
  myByteArray[9] =... // needed only for 8 byte int/float
  myByteArray[10]=... // needed only for 8 byte int/float
  myByteArray[11]=... // needed only for 8 byte int/float   
  SendRS485Message(myByteArray);
}


do you think we can establish such a standard? 8)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Fri Oct 17, 2008 11:17 am, edited 3 times in total.



Sat Sep 06, 2008 7:15 am
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post Re: 1.40 public: how to use RS485 connection? code samples?
hi Ford

as ogait told , it's the primary code...
So, we will upgrade it.

By now, its workinG =)

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Sat Sep 06, 2008 4:00 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
hi,
don't misunderstand me - it's a very good job you've done - all of you!
I myself never had managed to come so far!
And I need to say that I'm glad to see that my thread opening question had found so many interested people to work on this :P

It's just my intention to say that it might be the best way that all of you who are working on this communication code (docilio, ogait, Koldo, nxt) maybe should agree to a common syntax how to send and receive messages. If everyone is optimizing his own code by his own way there surely could be reached very good results, but 1 code won't work ever with the other.

Maybe we can try to find a common platform for the "token ring" to work with the "motor remote control" ?
docilio, ogait, Koldo, nxt: What do you think?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Sep 06, 2008 5:17 pm
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: RS485 standardization
Ford Prefect wrote:
hi,
looks very fine! I tested it and as far as I can see there's something happening ;)
but to be honest, I can't see WHAT'S happening :$
Probably my fault. I even forgot to make the comments in English. :wink:

Ford Prefect wrote:
to improve your code and to make the code more standardized, I'll suggest the following:
1) generally the allowed friendlynames should only be "00", "01", "02",.."255" for EVERY RS485 protocoll written in future by anyone,
2) maybe the names may be set by a routine in the code itself (sfriendlyname="03" or whatever)
Probably we haven't explained why we used friendlynames. The task HSpeed need that each NXT has a unique number. Since the NXT I have used had names, it was simpler to use a single source file and have a line of code do generate de unique number. I some applications i can be easy to have multiple source files, each one include the HSpeed.c and in the main task sets the IAmNXT a different number in each source file. HSpeed task don't bother to know how you grant a unique number, it just need one. friendlynames was a easy way to do that.

Ford Prefect wrote:
3) master always is nxt "00" in order to superior controlling purposes
4) the RS485 code should be written to a header file ("RS485com.h") which can be included as #include "RS484com.h" by any user program
I am using a token ring scheme and i don now see why to have a NXT with more control than the others NXT. In another way to control the bus maybe. I am just spiking in controlling the bus. In an application where you have NXT just relaying sensors and motors it makes sense to have a "Master" NXT, but not in the buss sense :bigthumb: It is possible do just include a .h file with just the headers or the .h has to have code?

Ford Prefect wrote:
5) the header file contains all needed interface functions:
- the RS485 protocoll should be activated by a function void RS485Init(), which starts an endless task for the comm message sending / receiving switching;
- RS485SendBytes(byte[12] myByteArray) sends 12 bytes or ubytes
- RS485GetBytes (byte[12] myByteArray) receives 12 bytes or ubytes
- the series of bytes in the ByteArrays have certain meanings as descibed befor (adressee, sender, length_of_data, sort_of_data, message, ..) which still has to be optimized

EDIT:
imagine: there are several bricks, each brick sends various events by various tasks.
Now many messages come to a receiver - how can the receiver know what data this is and what to do with it?

If it's a sensor value: from which sensor port?
If it's a calculated variable value: of which variable (you might give them numbers for transmission)

is it a 4 Byte integer value?
is it a 8 Byte float value?

The event might be the following:
e.g., you may have a ultra sonic distance Sensor at your nxt 01 (port 0=S1), and in case an obstacle has been detected, a message containig this SensorValue has to be transmitted to the "Master":

Then imagine, there may be an infrared Sensor on brick 02 port 02 which just detected a IR soccer ball; immediately he also sends his discovery to the master at almost the same time. So 2 messages arrive at the addressee and he must be able to distinguish which which message contains what kind of data (e.g., display this value on the master's screen or start/stop a motor)


this following might be the 1st message, a 2nd message may look similar:

Code:
if SensorValue[0]>=100 // send in case a wall (e.g., raw=400) has been detected
{
  myByteArray[0]=0; // addressee: Master=00
  myByteArray[1]=1; // own address 01
  myByteArray[2]=00 // sensor port 0 --- or alternatively  a message ID (to answer to a request?)
  myByteArray[3]=02 // 2 byte integer (short)
  myByteArray[4]= 0xC0 // value=400 => lowByte of SensorValue=400-256=144 
  myByteArray[5]= 0x01 // value=400 => hiByte of SensorValue=1*256
  myByteArray[6]= 0x00  // needed only for 4 byte int
  myByteArray[7]= 0x00  // needed only for 4 byte int
  myByteArray[8] =... // needed only for 8 byte int/float
  myByteArray[9] =... // needed only for 8 byte int/float
  myByteArray[10]=... // needed only for 8 byte int/float
  myByteArray[11]=... // needed only for 8 byte int/float   
  SendRS485Message(myByteArray);
}


do you think we can establish such a standard? 8)
I Think i can be done. some is already done , some is to be done (simpler interface) and you point a interesting problem, witch was ignored when the code had been made. I was just a data link, not a tcp like protocol. :D but that is early implemented.

Thanks for the appreciation. I soon i have a new code i publish it were.

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/


Last edited by ogait87 on Sat Sep 06, 2008 6:48 pm, edited 1 time in total.



Sat Sep 06, 2008 6:23 pm
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: 1.40 public: how to use RS485 connection? code samples?
Sorry double posting but this was i tink it is more organized.
Ford Prefect wrote:
It's just my intention to say that it might be the best way that all of you who are working on this communication code (docilio, ogait, Koldo, nxt) maybe should agree to a common syntax how to send and receive messages. If everyone is optimizing his own code by his own way there surely could be reached very good results, but 1 code won't work ever with the other.

Maybe we can try to find a common platform for the "token ring" to work with the "motor remote control" ?
docilio, ogait, Koldo, nxt: What do you think?
I think we shouldn't try to include the "motor remote control" in this protocol. If someone wish to make a sersor/motor relay protocol on the top of this one is free to do so, i just have to define how to organize data, collect data and send it via HSpeed. A standard is a good idea. It allows to build others protocol on top of this one more easily.

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/


Sat Sep 06, 2008 6:31 pm
Profile
Rookie

Joined: Tue Aug 26, 2008 6:53 am
Posts: 13
Post Re: RS485 standardization
to de deleted

_________________
My sensors and librarys for robotc
http://hng.av.it.pt/~tgoncalves/robotc/cgit.cgi/


Sat Sep 06, 2008 6:48 pm
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post Re: 1.40 public: how to use RS485 connection? code samples?
The idea is that any comunication in here should respect that protocol (not finished)

Now it's just create a message lable like "01:sensor", "02:order","03:motor code" ...

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Sat Sep 06, 2008 6:49 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
maybe you could take my transmission block, and if you wish we can add another 4 bytes to this to be more flexible for the future:
Code:
 
// transmission block: 16 bytes
// header block: 8 bytes
  TBlock[0] =0x00; // addressee: 00
  TBlock[1] =0x01; // own address 01
  TBlock[2] = ...  // free; maybe low byte of mesage ID or sth. else
  TBlock[3] = ...  // free; maybe hi byte  of mesage ID or sth. else
  TBlock[4] =0x00; // value type: sensor port 0  (see below)
  TBlock[5] = ...  // in case of variable value:  low byte variable ID 
  TBlock[6] = ...  // in case of variable value:  hi byte variable ID   
  TBlock[7] =0x21;  // value encoded as 2 byte integer (short)  (see below)
// data block: 8 bytes
  TBlock[8] = 0xC0; // lowByte of (short)SensorValue
  TBlock[9] = 0x01; // hiByte of (short)SensorValue
  TBlock[10]= 0x00; // needed only for 4 byte int
  TBlock[11]= 0x00; // needed only for 4 byte int
  TBlock[12]= 0x00; // needed only for 8 byte int/float
  TBlock[13]= 0x00; // needed only for 8 byte int/float
  TBlock[14]= 0x00; // needed only for 8 byte int/float
  TBlock[15]= 0x00; // needed only for 8 byte int/float 


TBlock[7]= encoder types:
Quote:
01 1 single ubyte
02 2 single ubytes
03 3 single ubytes
...
11 1 single byte
12 2 single bytes
13 3 single bytes
...
21 1* 2 byte integer (short)
22 2* 2 byte integer
23 3* 2 byte integer
24 4* 2 byte integer
...
31 1* 4 byte integer
32 2* 4 byte integer
...
41 1* 8 byte integer
...
A1 1* 4 byte float (?)
A2 2* 4 byte float (?)
...
B1 1* 8 byte float
...



TBlock[4]= value types:
Quote:
00 sensor port 0 (S1)
01 sensor port 1 (S2)
02 sensor port 2 (S3)
03 sensor port 3 (S4)
... (space for more virtual ports of sensor multiplexers)
30 sensor port 0 (S1) requested
31 sensor port 1 (S2) requested
32 sensor port 2 (S3) requested
33 sensor port 3 (S4) requested
... (space for more virtual ports of sensor multiplexers)
70 motor encoder 0 (motorA)
71 motor encoder 1 (motorB)
72 motor encoder 2 (motorC)
... (space for more virtual ports of motor multiplexers)
A0 motor encoder 0 (motorA) requested
A1 motor encoder 1 (motorB) requested
A2 motor encoder 2 (motorC) requested
... (space for more virtual ports of motor multiplexers)
E0 variable value sent (number of variable specified in TBlock[5] + [6] )
E1 variable value requested (number of var specified in TBlock[5] + [6] )
...
FE error (general)
FF ok

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Sun Sep 07, 2008 5:10 pm, edited 20 times in total.



Sun Sep 07, 2008 5:10 am
Profile
Expert

Joined: Sun Sep 09, 2007 10:12 am
Posts: 116
Post Re: 1.40 public: how to use RS485 connection? code samples?
Thanks for sugestions...

Ogait will read it and after it could create the end file...

what he created till now was a way to things work (they talk), not a way to share motors or sensors...

In some days, a final or beta version will be write...

Thanks

_________________
http://www.apcsguarda.com
My Project: http://www.robotc.net/forums/viewtopic.php?f=15&t=712


Sun Sep 07, 2008 5:31 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
hi,
do you meanwhile have a workaround?
Shall we have a 16 or 32 byte data block additional to the 8 byte header block to tranfer even more accurate ints and floats?
Maybe if you'll post your working model we all can have a look upon this and improve it together?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Sep 18, 2008 5:34 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 614
Post Re: 1.40 public: how to use RS485 connection? code samples?
This is a very interesting thread. I'm very interested in adding new functionality to ROBOTC firmware to facilitate RS485 communications. it's really a matter of coming up with something of interest to most users.

I was thinking of something along the lines of the existing Bluetooth mailbox messaging scheme except over RS-485. The higher level functionality is providing a message based interface.

The applications that can be developed are limitless.

One application that I've thought about is using a slave NXT as a motor and sensor expander. With the recent 1.43 ROBOTC release this is a lot easier as it introduces support for the HiTechnic Motor Controller (HMC). A HMC connects to a sensor port, communicates over I2C and supports two motors with encoders. Up to four HMC can be daisy chained on a single sensor port. There is an integrated driver for the HMC within the ROBOTC firmware. As part of the implementation, support was added to allow other types of motor controllers like this application; for this application, the driver might be best as a ROBOTC program with a separate task running handling the RS485 messaging to/from the slave NXT.

Another application is an RS485 connection to some of the available video cameras designed for robotics use.


Mon Sep 22, 2008 11:30 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: 1.40 public: how to use RS485 connection? code samples?
hi,
I'm not sure what you actually try to tell us (my English is unfortunately not good enough):
Do I understand you right that this RS485 TCP concept finds your interest and you want to implement sort of "token ring server" running on a "slave nxt"?
Or not?
Unfortunately the muliplexers alone are no solution for my project, because the 15k variable limit is too poor and I need to implement different sub-programs on different nxt's (e.g., 1 is running the navigator, 1 is running the neural net, 1 is controlling the cam and the 5- or 6- axis arm), and all 3 have to communicate. If I had 50 or 60k variable space on 1 nxt, there was no problem using many multiplexers.

On the other hand, also the motor muxers of Hitechnic are no solution yet, because
- I have 8 nxt motors at least,
- nxt motors can not be pugged to the HT muxers,
- even if I took VEX or TETRIX gear motors instead, then I needed to have 4 muxers daisy chained = 4*80 $= 320 $ plus the costs for the motors and the encoders... that is much too expensive
- and after all gear motors can't be plugged to the Lego technic bars or beams

So a RS485 TCP could be the best solution for this all .

Maybe docilio & Co will find also a way to develop this - or even found it?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Tue Sep 23, 2008 2:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 134 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9  Next

Who is online

Users browsing this forum: alexdhas and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.