Robofun 機器人論壇

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

EZ1超音波連接運用在ARDUINO上大問題!

[複製鏈接]
1#
發表於 2011-9-17 20:31:28 | 顯示全部樓層
本帖最後由 vegewell 於 2011-9-17 20:39 編輯

仔細看這裡有調整的軟體可下載 及How can I use more than one MaxSonar®-EZ1
in the same system?


http://www.maxbotix.com/tutorials.htm#What_are_the_differances_between_the_Original_MaxSonar_EZ1_and_the_LV_MaxSonar_EZ1
=====================================
How can I chain multiple MaxSonar® sensors together?
There are multiple ways to use the sensors without interference.  Three ways are described below.

Daisy Chaining using a Commanded Loop

Figure 6.5.


To chain the sensors, and have them operate in sequential daisy-chained fashion, you do so by linking the TX of unit 1 to RX of unit 2 and so on.  The BW pin is tied high on all of the parts.  Then just strobe the first sensor's RX pin and all of the sensors will read the range in sequence.  The analog values can then be read. The example in Figure 6.5 would use one pin to command the chain, and three analog to digital inputs. Please click the link to the download the  PDF file.Commanded Loop PDF File

Daisy Chaining with Constantly Looping


Figure 6.6.

If you want them to keep running and constantly loop and always provide the latest range reading you will have to do two things.



First, add a resistor between the last sensor's TX back to the Rx of the first unit through a 1K resistor as shown in Figure 6.6.

Second, you will have to "kick start" them, (at least 250mS or more after power is applied to the sensors to give the sensors this time to boot-up).  To do this, pull the RX pin high on the first sensor for at least 20uS.  Then controller will have to return it's pin to a high impedance state so that the next time around the TX output from the last sensor will make it's way to the RX of the first sensor.  Then all of the sensors in the chain will run in sequence.  This "ring of sensors" will cycle around and around, constantly maintaining the validity of their analog values.  You can then read the latest range reading (i.e. the analog value) at any time.  This is the easiest way to use them.


After pulling the RX pin low,  you can read the analog pin about 50mS (100mS if this is the first time reading the sensor as it calibrates upon the first commanded range cycle after power up, i.e. the sensor must complete a range cycle). In addition, the most recent range reading is always ready to be read on the analog voltage pin, so once you start the chain, and if you are using it in continuous mode,  you can read the values at any time. Please click the link to download the PDF file. Constantly Looping PDF File




Simultaneous Operation


Figure 6.7.


You can also run them all at the same time (and for some uses this is preferred as the measurement speed is maximum, but it is only for selected applications).   Just tie all of the RX pins together and command them with a pin from your microcontroller as shown in figure 6.7.  Hold the pin high for more than 20uS.  Do not continuously leave this pin high, as then all of the sensors will free run as described above.  Command the sensors every 50mS or whenever a new range reading is desired. Please click the link to download the PDF file. Simultaneous Operation PDF File
2#
發表於 2011-9-18 19:20:31 | 顯示全部樓層
本帖最後由 vegewell 於 2011-9-18 21:23 編輯

這裡有人用四個, 放置 前 後 左 右不同方向,
http://www.ecs.umass.edu/ece/sdp/sdp11/soules/files/mdr_draft.pdf
你有沒有試過不同方向?
另外他們使用 LV-MaxSonar-EZ1 不是MaxSonar-EZ1,
我再多看看,知道再提供意見,
這裡只有 nichal大 比較像似可愛的神人,
nichal大會解釋得很清楚,難不倒他的.
3#
發表於 2011-9-18 21:28:03 | 顯示全部樓層
回復 5# yao412030
這裡有很詳細的說明(6 SENSORS):
http://arduino.cc/forum/index.php?topic=66765.0

請仔細看過後,有問題再逐一的提出,

下圖除了藍色線有問題外, 其餘的就照著做看看

    http://s3.amazonaws.com/twitpic/photos/full/349405101.png?AWSAccessKeyId=AKIAJF3XCCKACR3QDMOA&Expires=1316352760&Signature=%2FZbA6RpkjFafVqfZYKZQo%2BMtY2E%3D
4#
發表於 2011-9-19 17:20:08 | 顯示全部樓層
回復 10# nichal


    nichal大 已經把波形概念解釋得很清楚,
對此原理很清楚之後,寫起程式就會有秩序合邏輯.
5#
發表於 2011-9-19 17:21:33 | 顯示全部樓層
大大您第二個網址我不能開欸....
小弟我還會多多研究!!!
先謝謝您!
yao412030 發表於 2011-9-18 21:57



    這個網址我一下子就能開啟了,
你也應該開入去得到關鍵知識,
標題是   Wire logic high, multiple sensors.
http://arduino.cc/forum/index.php?topic=66765.0
6#
發表於 2011-9-19 17:23:07 | 顯示全部樓層
本帖最後由 vegewell 於 2011-9-19 17:24 編輯
我的是要同一方向放在左右邊不同位置,而我是買MaxSonar-EZ1請問還可以照接嗎??
http://twitpic.com/5s0yp9/full這是我找到的圖....他好像是Daisy Chaining with Constantly Looping
他的藍色線我有點搞不懂,他是三個sensor的AN拉出來接在一起在拉到ARDUINO的ANALOG即可??
還是三個連線一起之後再一個一個另外拉線出來到ARDUINO的ANALOG接腳呢??
有點看不懂還請大大指導!!!

yao412030 發表於 2011-9-18 21:59

你找到的圖http://twitpic.com/5s0yp9/full,
就是我要說的那個圖,
Daisy Chaining with Constantly Looping
藍色的線,做者的說法是:
[blue lines were a little lazy, each AN from the sensor is going to a separate Analog pin on the board.
So Sensor 1 is going into ANalog pin 0 sensor 2 into Analog pin 1, etc.]
不過我認為都連結在一個pin也行,
========================
LV-MaxSonar-EZ1 比 MaxSonar-EZ1 容易連結使用幾個 sensors,(你要先努力嘗試使用手上的MaxSonar-EZ1)
如下圖serial timing那列有介紹:
7#
發表於 2011-9-19 17:25:49 | 顯示全部樓層
依照那國外做者,請先試試下圖的接法:


arduino的程式如下

int ultraSoundSignalPins[] = {0,1}; // 2 Ultrasound signal pins
int ultraSoundTriggerPin = 6;        // output pin to start Ultrasound signals


void setup() {
   Serial.begin(9600);
   for(int i=0; i < 2; i++) {
       pinMode(ultraSoundSignalPins, INPUT); // Switch signalpin to input
   }
   pinMode(ultraSoundTriggerPin, OUTPUT); // set this pin to output
  //give the sensors time to boot up
   delay(250);
   // send RX pin high to signal to chain to ping
   digitalWrite(ultraSoundTriggerPin, HIGH);
   delayMicroseconds(30);
   digitalWrite(ultraSoundTriggerPin, LOW);
   pinMode(ultraSoundTriggerPin, INPUT); // electrically disconnects the pin
   delay(50);
}
void loop()
{
   unsigned long ultrasoundValue;
   unsigned long echo;
   delay(50);
   for(int i=0; i < 2; i++)
   {
//Now the values from each sensor can be read:
       echo = analogRead(ultraSoundSignalPins); //Listen for echo
       ultrasoundValue = (echo / .58138);


       Serial.println();
       Serial.print("UltraSound Value");
       Serial.print( ultraSoundSignalPins);
       Serial.print(  "= ");
       Serial.print(ultrasoundValue);
      

      
   delay(500);
   
   }
  
}
==================
如有問題,
pin0 and pin1的線互換看看,
another 有沒有接 1 k 的電阻?
依照做者的說法,在測至一米前,都蠻(準確度)的 ,
8#
發表於 2011-9-20 09:43:15 | 顯示全部樓層
解釋是:
[Analog pins are INPUT only, so there is no reason to set the pin mode for them.
As a result, the pinMode() function only applies to digital pins.
So, you just set digital pins 0 to 5 as input, including the ones managed by the Serial instance.]
所以你把下列幾行刪除試試(多餘的):
for(int i=0; i < 2; i++) {
       pinMode(ultraSoundSignalPins, INPUT); // Switch signalpin to input
   }
======================
9#
發表於 2011-9-20 11:12:54 | 顯示全部樓層
回復 16# yao412030


不過,沒有刪的原程式,
我現在自己用  Arduino Mega 去編譯 是 Done Compiling,
而且 Done uploading,
我是用最新版本 Arduino 0022,
你是怎麼用的?
原程式在此
http://arduino.cc/forum/index.php/topic,65727.0.html
  
10#
發表於 2011-9-20 20:58:10 | 顯示全部樓層
本帖最後由 vegewell 於 2011-9-20 21:18 編輯

回復 20# yao412030

那你也蠻會的, 知道要降至3.3V,
請問你是哪裡怎麼降至3.3V的?

你的意思是說,現在可以正確的顯示,至少誤差不會太大?
除了顯示值差距太小, 就沒有問題了嗎?

The LV-MaxSonar&reg;-EZ0™
detects objects from 0-inches to 254-inches
最長可偵測 是(6.45-meters),
那你想偵測的最遠為何?假設是100公分
假設0公分時類比值是10,  那100公分時假設類比值25,
所以你要在程式裡加入map()函數:
----------------------------------
ultrasoundValue = (echo / .58138);
ultrasoundValue = map(ultrasoundValue, 10, 25, 1000, 2500);
       Serial.println();
       Serial.print("UltraSound Value");
       Serial.print( ultraSoundSignalPins);
       Serial.print(  "= ");
       Serial.print(ultrasoundValue);
-------------------------------------
試看看 因為是long 不是int 所以不把握,
11#
發表於 2011-10-4 20:00:33 | 顯示全部樓層
回復 22# yao412030

不客氣,
也謝謝你讓我有機會,更深入瞭解這個超音波元件.
我們一樣都是在網路上學習別人的知識
12#
發表於 2011-10-16 13:37:37 | 顯示全部樓層
本帖最後由 vegewell 於 2011-10-16 13:53 編輯

回復 24# yao412030


    你現在是移動轉向時,會有問題發生,
靜止時沒有問題,
是不是?
那麼是 MaxSonar-EZ1本身沒問題及與ARDUINO的連線沒問題,
對不對?
你只用一顆MaxSonar-EZ1面對兩個障礙物,移動轉向時會有問題發生嗎?
這個類比值是否符合兩個障礙物的距離?而不是有很多不同數值亂跳?

那麼可能就是設計上有問題,
先請問你的自走車有多寬?幾公分?
兩顆MaxSonar-EZ1相距幾公分?
兩顆MaxSonar-EZ1是平行的放置面對同一方向嗎?
13#
發表於 2011-10-16 22:08:28 | 顯示全部樓層
本帖最後由 vegewell 於 2011-10-16 22:10 編輯

回復 26# yao412030

你必須先確定是 MaxSonar-EZ1本身沒問題,
如果你沒驅使馬達轉動的時候,
兩顆MaxSonar-EZ1對著各種障礙物,包括你畫的圖這種角度對著牆壁,
兩顆MaxSonar-EZ1讀出的值是否正確?

如果正確,就表示 MaxSonar-EZ1本身沒問題,

至於你馬達的程式,因為我不曉得你是怎麼連線及控制馬達,
所以不曉得你的程式對不對,

如果你肯定正確的話,就表示最可能出現的問題是ARDUINO,
ARDUINO可能又控制馬達,造成電力不足,
所以有數值跳動的問題產生,
這種情形在ARDUINO控制servo時經常發生.
14#
發表於 2011-10-16 22:57:14 | 顯示全部樓層
回復 24# yao412030


    另外一種可能就是因為斜面折射的關係,
所以比較遠的那一顆接受到近的那顆的訊號,  而且比較多,
所以,以後每次在車子轉動時你就反過來寫,
大概如下:
}else if(right && left <= 30 && right>left){ //偵測到左右方障礙物且左方距離障礙物較遠減速轉向左方
      analogWrite(g_nMotor_2_Pin_B,255);
      analogWrite( g_nMotor_1_Pin_A, 0);
      analogWrite( g_nMotor_1_Pin_B , 120);
    l = 1;
  }else if (right >= 30 && right > left){ //偵測結束回復速度
      analogWrite( g_nMotor_1_Pin_A, 0);
      analogWrite( g_nMotor_1_Pin_B , 180);
  }else if(right && left <= 30 && right<left){ //偵測到左右方障礙物且右方距離障礙物較遠減速轉向右方
      analogWrite(g_nMotor_2_Pin_A,255);
      analogWrite( g_nMotor_1_Pin_A, 0);
      analogWrite( g_nMotor_1_Pin_B , 120);
  }else if (left >= 30 && right < left){ //偵測結束回復速度
      analogWrite( g_nMotor_1_Pin_A, 0);
      analogWrite( g_nMotor_1_Pin_B , 180);
    r = 1;
15#
發表於 2011-10-18 17:50:09 | 顯示全部樓層
回復 29# yao412030

不客氣,
也感謝你給我研究的動力,
試試 使用Simultaneous Operation的方式,也是應該的嘗試.
另外,如果你的自走車,
寬度不過十幾公分,
其實只用一顆MaxSonar-EZ1 也可以在碰到障礙物時,
知道要轉哪個方向,
如下舉例,給你參考:
http://megaswf.com/serve/1186867
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-5-14 16:25 , Processed in 0.209746 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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