Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 4038|回復: 3
打印 上一主題 下一主題

Xbee跳點傳 廣播模式 傳送速率慢

[複製鏈接]
跳轉到指定樓層
1#
發表於 2014-4-8 20:41:24 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
題目:
第一台電腦開啟終端機並連接一
組節點,首先下達 a 字元,由中
繼節點 (Arduino + XBee) 接收到
封包後,再轉傳至終端節點,再
終端節點開起終端機,檢驗是否收到


以下是我的程式:
(1)第一台電腦終端機(發送端)
按任意鍵盤,若偵測到"a"字元及發送"a"字元給中繼節點

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() // run over and over
{

if(Serial.available()>0)
{
char a=Serial.read();
if(a =='a')
{
mySerial.print("a");
delay(1);
}
}
}



(2)中繼節點的程式:
如果中繼節點收到"a"字元後即傳送"b"字元到終端節點

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() // run over and over
{

if(mySerial.available()>0)
{
char a=mySerial.read();
if(a =='a')
{
Serial.print("b");
mySerial.print("b");
delay(1);
}
}
}


(3)終端節點的程式:
如果收到中繼點傳來的"b"字元及print"b"出來,使用b字原是為了確保終端節點收到的是中繼點傳來的字元。


#include <SoftwareSerial.h>


SoftwareSerial mySerial(10, 11); // RX, TX


void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  mySerial.begin(9600);
}


void loop() // run over and over
{
  
if(mySerial.available()>0)
{
char a=mySerial.read();
if(a =='b')
{
Serial.print("b");


delay(1);
}
}
}



整體是成功了完成發送端傳送"a"字元,經由中繼點轉傳"b"字元到終端節點,終端節點的終端機也有顯示"b"字元,剩下傳送速率的問題了
之前有練習過點對點完全不會有延遲的現象,但自從用了廣播模式後傳送跟接收無法完全同步,可能傳了四個字元還不會有延遲的現象,但超過4個之後就會發生延遲。
XCTU有設定相同PAND ID


之前有爬了一些文我試過用delay();從1-2000都試過.... 但感覺都沒差  只是接收的速率變得更慢....
也有用過serial flush 也沒有用,我加在程式的最後面,不知道有沒有打錯地方 麻煩各位大大指正一下

或者我有在想是否可以藉由改變Xbee的傳送功率 來改善Xbee傳送速率過慢的問題,但又該如何設定呢?

懇請各位高手解答~~~謝謝
2#
發表於 2014-4-10 03:21:56 | 只看該作者
回復 1# kenn1660


   用了廣播模式會有延遲的現象,是可能的,因為各節點的晶片,要花更多的時間去處理訊號,
3#
 樓主| 發表於 2014-4-21 14:41:36 | 只看該作者
回復 2# vegewell
不好意思 我可以再問一下嗎有沒有能改善Xbee廣播傳輸延遲的問題


想了很久都還沒有結果   


專題要用    感謝回復
4#
發表於 2014-4-21 22:32:08 | 只看該作者
回復 3# kenn1660

請參考:不好意思沒 時間翻成中文    網頁請自搜
   The above two methods separate entire networks, but if you have four XBee's in a multipoint situation, you still need a way to select which of the other three modules to talk to. This is why every Xbee has a 64-bit serial number programmed onto it that can be read out through the SL
(lower 4 bytes) and SH (upper 4 bytes) registers. Every node on the network knows each other's serial numbers or addresses.
So when Point A sends a packet to Point C, it includes Point C's address. All the modules in the network receive this and the microcontroller code compares the included number to their own.
If it matches, the data is for them. If not, the data is discarded.
Note that this must all be implemented by you in the software of the device you attach to the XBee. The XBee itself does not know who else is on the network or how to check the serial numbers.


即使在廣播模式 every Xbee 有獨特的編碼註冊 has a 64-bit serial number (Address) programmed onto it
----------------------------------------------


If you are using the API mode on these XBee chips (sure, if you use the XBee-api library), you do not need to include the address of the sender in the message.
This information is automatically specified in the frame. Have a look at the getRemoteAddress16() and getRemoteAddress64() methods in class ZNetRxBaseResponse .


So what you have to do, is send a first message "hello" i.e. to the Coordinator (which you can address easily as 0x0000) from the Node you want to know the address.
Using the above mentioned methods you can get this information.


你只要用程式先分辯此訊號來自哪個 Xbee   use-> getRemoteAddress64()
去忽略不要收的訊號  或許可改善延遲的情況


範例


#include <XBee.h>


XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx64Response rx64 = Rx64Response();
XBeeAddress64 adr64;


int statusLed = 10;
int errorLed = 11;
uint8_t option = 0;
uint8_t data = 0;


void flashLed( int pin, int times, int wait ) {
    for( int i = 0; i < times; i++ ) {
      digitalWrite( pin, HIGH ); delay( wait ); digitalWrite( pin,
LOW );
      if( i + 1 < times )  delay( wait );
    }
}


void setup() {
  pinMode( statusLed, OUTPUT );
  pinMode( errorLed, OUTPUT );
  xbee.begin( 9600 );
}


void loop() {
    xbee.readPacket();
    if( xbee.getResponse().isAvailable() ) {
      if( xbee.getResponse().getApiId() == RX_64_RESPONSE ) {
        xbee.getResponse().getRx64Response( rx64 );
        option = rx64.getOption();
        data = rx64.getData( 1 );
        if( data == 'B' ) {
          adr64 = rx64.getRemoteAddress64();
          uint8_t payload[] = { 5, 7 };
          Tx64Request tx = Tx64Request( adr64, payload, sizeof
( payload ) );
          xbee.send( tx );
          TxStatusResponse txStatus = TxStatusResponse();
          if( xbee.readPacket( 5000 ) ) {
            if( xbee.getResponse().getApiId() == TX_STATUS_RESPONSE )
{
              xbee.getResponse().getZBTxStatusResponse(txStatus);
              if( txStatus.getStatus() == SUCCESS ) flashLed
( statusLed, 5, 50 );
              else flashLed( errorLed, 3, 500 );
            }
          }
          else flashLed( errorLed, 2, 50 );
        }
      }
    }
}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-30 16:28 , Processed in 0.163329 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表