View unanswered posts | View active topics It is currently Wed Jul 30, 2014 10:06 am






Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
AMX 13 bridge layer 
Author Message
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: AMX 13 bridge layer
Cool!

Try this:
Code:
int counter = 0;
task main () {
  int num;
  ubyte chksum;
  ubyte incoming[16];
  nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(9600);
  wait1Msec(2000);
  writeDebugStreamLine("slave alive");
  while(true) {
    num = nxtGetAvailHSBytes();
    if (num > 0) {
      wait1Msec(20);
      num = nxtGetAvailHSBytes();
      nxtReadRawHS(incoming[0], num);
      if (num == 16)
      {
        counter++;
        writeDebugStreamLine("Successes: %d  Byte 0 value: %d", counter, incoming[0]);
      }
      else
      {
         writeDebugStreamLine("Only %d bytes received", num);
      }
    }
  }
}


_________________
Matt


Wed Dec 05, 2012 4:14 pm
Profile WWW
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
well

you are a big boss with robotC !!!!!!

is it good ?

slave alive
Only 127 bytes received
Successes: 1 Byte 0 value: 23
Successes: 2 Byte 0 value: 24
Successes: 3 Byte 0 value: 25
Successes: 4 Byte 0 value: 26
Successes: 5 Byte 0 value: 27
Successes: 6 Byte 0 value: 28
Successes: 7 Byte 0 value: 29
Successes: 8 Byte 0 value: 30
Successes: 9 Byte 0 value: 31
Successes: 10 Byte 0 value: 32
Successes: 11 Byte 0 value: 33
Successes: 12 Byte 0 value: 34
Successes: 13 Byte 0 value: 35
Successes: 14 Byte 0 value: 36
Successes: 15 Byte 0 value: 37
Successes: 16 Byte 0 value: 38
Successes: 17 Byte 0 value: 39
Successes: 18 Byte 0 value: 40
Successes: 19 Byte 0 value: 41
Successes: 20 Byte 0 value: 42
Successes: 21 Byte 0 val

......etc....

Successes: 57 Byte 0 value: 79
Successes: 58 Byte 0 value: 80
Successes: 59 Byte 0 value: 81
Successes: 60 Byte 0 value: 82
Successes: 61 Byte 0 value: 83
Successes: 62 Byte 0 value: 84
Successes: 63 Byte 0 value: 85
Successes: 64 Byte 0 value: 86
Successes: 65 Byte 0 value: 87
Successes: 66 Byte 0 value: 88
Successes: 67 Byte 0 value: 89
Successes: 68 Byte 0 value: 90
Successes: 69 Byte 0 value: 91
Successes: 70 Byte 0 value: 92
Successes: 71 Byte 0 value: 93
Successes: 72 Byte 0 value: 94
Successes: 73 Byte 0 value: 95
Successes: 74 Byte 0 value: 96
Successes: 75 Byte 0 value: 97
Successes: 76 Byte 0 value: 98
Successes: 77 Byte 0 value: 99


Wed Dec 05, 2012 4:41 pm
Profile
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
I did other test for AMX13 under fire with color led for lego trucks ;

it is better than lego color sensors

Image

[img=http://images3.photomania.com/3578177/1/_rad8DFD6.jpg]

now I will do it with a new program if I can use the code you gave me for RS485

thanks

didier


Wed Dec 05, 2012 4:46 pm
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: AMX 13 bridge layer
Perfect!

That confirms that you now have a good connection for the master to send data to the slave. In this test, it's transferring 16 bytes, but it should support up to 64.

The data that is being transferred is as RAW as it gets, so you will now need to add any error detection you want, as well as data formatting.

If the master just needs to send motor speed values to the slave, put the motor speed values into the outgoing buffer of the master. On the slave, extract those values from the incoming buffer, and set the motor speeds accordingly.

_________________
Matt


Wed Dec 05, 2012 4:48 pm
Profile WWW
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
very clear

you are an expert

and even more ;

very kind from you ;

I will put code as soon as it will work ;

thanks a lot for the time you have spend for me ;

didier


Wed Dec 05, 2012 4:52 pm
Profile
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
Hello

yesterday night ( here ) my NXT brick and me were almost sleeping ;

so I test your code again this morning ;

and it gives :

slave alive
Successes: 1 Byte 0 value: 0
Successes: 2 Byte 0 value: 1
Successes: 3 Byte 0 value: 2
Successes: 4 Byte 0 value: 3
Successes: 5 Byte 0 value: 4
Successes: 6 Byte 0 value: 5
Successes: 7 Byte 0 value: 6
Successes: 8 Byte 0 value: 7
Successes: 9 Byte 0 value: 8
Successes: 10 Byte 0 value: 9
Successes: 11 Byte 0 value: 10
Successes: 12 Byte 0 value: 11
Successes: 13 Byte 0 value: 12
Successes: 14 Byte 0 value: 13
Successes: 15 Byte 0 value: 14
Successes: 16 Byte 0 value: 15
Successes: 17 Byte 0 value: 16
Successes: 18 Byte 0 value: 17
Successes: 19 Byte 0 value: 18
Successes: 20 Byte 0 value: 19
Successes: 21 Byte 0 value: 20
Successes: 22 Byte 0 value: 21
Successes: 23 Byte 0 value: 22
Successes: 24 Byte 0 value: 23

..................etc..................

Successes: 93 Byte 0 value: 92
Successes: 94 Byte 0 value: 93
Successes: 95 Byte 0 value: 94
Successes: 96 Byte 0 value: 95
Successes: 97 Byte 0 value: 96
Successes: 98 Byte 0 value: 97
Successes: 99 Byte 0 value: 98
Successes: 100 Byte 0 value: 99


so it is quite good , better than yesterday night ;

master sends 100 values and slave received the same ;

good !

didier


Thu Dec 06, 2012 2:43 am
Profile
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
Hello

you did a " un coup de maître " we say in french !

and now my two nxt on AMX13 could be link ;

below the code I built ( not as an expert... ) :

Code:

task RS485MASTER()

{

nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(9600);
  wait1Msec(2000);

   while (true)
   {
  //int num;
  ubyte testBytes[11] = 0;

  //ubyte outgoing[16] = {15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
       testBytes[0]  = 1;// les bytes qui suivent sont des envois
    testBytes[1]  = dataE1;//
    testBytes[2]  = dataE2;//
      testBytes[3]  = dataE3;//
    testBytes[4]  = dataE4;//
      testBytes[5]  = dataE5;//
    testBytes[6]  = dataE6;//
    testBytes[7]  = dataE7;//
    testBytes[8]  = dataE8;//
    testBytes[9]  = dataE9;//
    testBytes[10]  = dataE10;//




    nxtWriteRawHS(&testBytes[0], 11, 0);
    wait1Msec(100);
  }
  wait1Msec(10);
}

//**********************************************************************


Code:


task RS485SLAVE()

{
   

  ubyte receiveBuffer[11];
  nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(9600);
  wait1Msec(2000);
  writeDebugStreamLine("slave alive");
  while(true) {
    num = nxtGetAvailHSBytes();
    if (num > 0) {
      wait1Msec(20);
      num = nxtGetAvailHSBytes();
      nxtReadRawHS(&receiveBuffer[0], num);
      if (num == 11)
      {
        counter++;
        writeDebugStreamLine("Successes: %d  Byte 0 value: %d", counter, receiveBuffer[0]);
       
        reception   = receiveBuffer[0];
        dataR1 = receiveBuffer[1];
    dataR2 = receiveBuffer[2];
           dataR3 = receiveBuffer[3];
           dataR4 = receiveBuffer[4];
           dataR5 = receiveBuffer[5];
           dataR6 = receiveBuffer[6];
           dataR7 = receiveBuffer[7];
           dataR8 = receiveBuffer[8];
            dataR9 = receiveBuffer[9];
            dataR10 = receiveBuffer[10];
      }
      else
      {
         writeDebugStreamLine("Only %d bytes received", num);
      }
    }
  }
}


until now it works !

good job ! thanks again !

didier


Thu Dec 06, 2012 8:56 am
Profile
Expert

Joined: Thu Sep 29, 2011 11:09 pm
Posts: 184
Location: Michigan USA
Post Re: AMX 13 bridge layer
The reason why they were offset the other day, and it didn't appear to work quite perfectly, is that the master program was started first (or at least it started sending before the slave started listening).

To speed things up, I changed the baud rate from 9600 to 921600, which is 96 times as fast. I also changed the delays, so that the master should now update the slave much more often so that it feels real-time to the user. The update rate should now be roughly 150 times per second.

Code:
task RS485MASTER()
{
  nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(921600);
  wait1Msec(20);
 
  ubyte testBytes[11];
 
  while (true)
  {
    testBytes[0]  = 1;      // les bytes qui suivent sont des envois
    testBytes[1]  = dataE1;
    testBytes[2]  = dataE2;
    testBytes[3]  = dataE3;
    testBytes[4]  = dataE4;
    testBytes[5]  = dataE5;
    testBytes[6]  = dataE6;
    testBytes[7]  = dataE7;
    testBytes[8]  = dataE8;
    testBytes[9]  = dataE9;
    testBytes[10] = dataE10;

    nxtWriteRawHS(&testBytes[0], 11, 0);
    wait1Msec(5);
  }
}


Code:
task RS485SLAVE()
{
  ubyte receiveBuffer[11];
 
  nxtEnableHSPort();
  nxtHS_Mode = hsRawMode;
  nxtSetHSBaudRate(921600);
  wait1Msec(20);
  writeDebugStreamLine("slave alive");
  while(true) {
    num = nxtGetAvailHSBytes();
    if (num > 0) {
      wait1Msec(2);
      num = nxtGetAvailHSBytes();
      nxtReadRawHS(&receiveBuffer[0], num);
      if (num == 11)
      {
        counter++;
        writeDebugStreamLine("Successes: %d  Byte 0 value: %d", counter, receiveBuffer[0]);

        reception = receiveBuffer[0];
        dataR1 = receiveBuffer[1];
        dataR2 = receiveBuffer[2];
        dataR3 = receiveBuffer[3];
        dataR4 = receiveBuffer[4];
        dataR5 = receiveBuffer[5];
        dataR6 = receiveBuffer[6];
        dataR7 = receiveBuffer[7];
        dataR8 = receiveBuffer[8];
        dataR9 = receiveBuffer[9];
        dataR10 = receiveBuffer[10];
      }
      else
      {
        writeDebugStreamLine("%d bytes received", num);
      }
    }
  }
}

_________________
Matt


Thu Dec 06, 2012 1:27 pm
Profile WWW
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
hello


I tried it

ok very goods

so I will do other videos this week end ant put them on the forum

thanks to be so kind

yours

didier


Thu Dec 06, 2012 4:12 pm
Profile
Novice

Joined: Sat Sep 15, 2012 11:28 am
Posts: 68
Post Re: AMX 13 bridge layer
Hello

I am so sorry

the video do not work as I would with youtube

too dark

but one is nice


http://www.youtube.com/my_videos_edit?n ... BqLVU0xHuc




didier


Tue Dec 11, 2012 10:47 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 25 posts ]  Go to page Previous  1, 2

Who is online

Users browsing this forum: No registered users 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.