“SKU:RB-02S103 復(fù)眼傳感器”的版本間的差異
來自ALSROBOT WiKi
(→?產(chǎn)品參數(shù)) |
(→?相關(guān)資料) |
||
(未顯示1個用戶的7個中間版本) | |||
第7行: | 第7行: | ||
==產(chǎn)品參數(shù)== | ==產(chǎn)品參數(shù)== | ||
? | |||
===基本參數(shù)=== | ===基本參數(shù)=== | ||
#品名 紅外線復(fù)眼傳感器<br/> | #品名 紅外線復(fù)眼傳感器<br/> | ||
第32行: | 第31行: | ||
? | + | ==使用方法== | |
? | + | ===example1_Arduino=== | |
? | + | * 主要硬件 | |
+ | :Arduino UNO 控制器 | ||
+ | :傳感器擴(kuò)展板 V5.0 | ||
+ | :復(fù)眼傳感器 | ||
+ | :4P 傳感器連接線 | ||
+ | :USB 數(shù)據(jù)線 | ||
? | + | * 硬件連接 <br/> | |
? | < | + | [[文件:02S103101.png|700px|縮略圖|居中]] |
? | + | ||
+ | * 示例程序 | ||
+ | <pre style='color:blue'> | ||
+ | #include <Wire.h> | ||
#define PCF8591 (0x90 >> 1) // I2C bus address | #define PCF8591 (0x90 >> 1) // I2C bus address | ||
+ | |||
byte value0, value1, value2, value3; | byte value0, value1, value2, value3; | ||
? | + | void readvalues(){ | |
? | + | Wire.beginTransmission(PCF8591); // wake up PCF8591 | |
? | + | Wire.write(0x04); | |
? | + | Wire.endTransmission(); | |
+ | Wire.requestFrom(PCF8591, 5); | ||
+ | value0=Wire.read(); | ||
+ | value0=Wire.read(); //上 | ||
+ | value1=Wire.read(); //右 | ||
+ | value2=Wire.read(); //下 | ||
+ | value3=Wire.read(); //左 | ||
+ | Serial.print("value0= "); Serial.print(value0);Serial.print("\t"); | ||
+ | Serial.print("value1= "); Serial.print(value1);Serial.print("\t"); | ||
+ | Serial.print("value2= "); Serial.print(value2);Serial.print("\t"); | ||
+ | Serial.print("value3= "); Serial.print(value3);Serial.print("\t"); | ||
+ | Serial.println(); | ||
+ | } | ||
? | + | void setup() | |
? | + | { | |
+ | Wire.begin(); | ||
+ | Serial.begin(9600); | ||
+ | } | ||
+ | void loop() | ||
+ | { | ||
+ | readvalues(); | ||
+ | } | ||
+ | </pre> | ||
? | / | + | * 程序效果 |
? | + | 通過串口監(jiān)視器,即可讀取傳感器返回的數(shù)據(jù)。<br/> | |
? | + | ||
? | + | ||
? | + | ===example2_Arduino=== | |
+ | * 主要硬件 | ||
+ | :Arduino UNO 控制器 | ||
+ | :Motor Driver Shield 電機(jī)驅(qū)動板 | ||
+ | :復(fù)眼傳感器 | ||
+ | :杜邦線 | ||
+ | :USB 數(shù)據(jù)線 | ||
+ | :二自由度云臺 | ||
? | void | + | * 硬件連接 |
+ | [[文件:02S103102.png|700px|縮略圖|居中]] | ||
+ | * 示例程序 | ||
+ | <pre style='color:blue'> | ||
+ | #include <Servo.h> | ||
+ | #include <Wire.h> | ||
+ | #define PCF8591 (0x90 >> 1) | ||
+ | #define panPin 10 | ||
+ | #define tiltPin 5 | ||
+ | |||
+ | byte LRscalefactor=10; | ||
+ | byte UDscalefactor=10; | ||
+ | int distancemax=80; | ||
+ | int PanZero=90; | ||
+ | int TiltZero=90; | ||
+ | int LRmax=170; | ||
+ | int LRmin=10; | ||
+ | |||
+ | int UDmax=150; | ||
+ | int UDmin=30; | ||
+ | |||
+ | int pan=PanZero; | ||
+ | int tilt=TiltZero; | ||
+ | int panscale; | ||
+ | int tiltscale; | ||
+ | int panOld; | ||
+ | int tiltOld; | ||
+ | int distance; | ||
+ | int temp; | ||
+ | |||
+ | int updown; | ||
+ | int leftright; | ||
+ | |||
+ | Servo panLR; | ||
+ | Servo tiltUD; | ||
+ | byte up_value0, right_value1, down_value2, left_value3; | ||
+ | |||
+ | void readvalues(){ | ||
+ | Wire.beginTransmission(PCF8591); | ||
+ | Wire.write(0x04); | ||
+ | Wire.endTransmission(); | ||
+ | Wire.requestFrom(PCF8591, 5); | ||
+ | up_value0=Wire.read(); | ||
+ | up_value0=Wire.read(); //上 | ||
+ | right_value1=Wire.read(); //右 | ||
+ | down_value2=Wire.read(); //下 | ||
+ | left_value3=Wire.read(); //左 | ||
+ | distance=(up_value0+right_value1+down_value2+left_value3)/4; | ||
+ | Serial.print("up_value0= "); Serial.print(up_value0);Serial.print("\t"); | ||
+ | Serial.print("right_value1= "); Serial.print(right_value1);Serial.print("\t"); | ||
+ | Serial.print("down_value2= "); Serial.print(down_value2);Serial.print("\t"); | ||
+ | Serial.print("left_value3= "); Serial.print(left_value3);Serial.print("\t"); | ||
+ | Serial.print("distance= "); Serial.print(distance);Serial.print("\t"); | ||
+ | Serial.println(); | ||
+ | } | ||
+ | |||
+ | void IRfollow() | ||
+ | { | ||
+ | if (distance<distancemax) | ||
+ | { | ||
+ | ; | ||
+ | // if (pan>PanZero)pan=pan-1; | ||
+ | // if (pan<PanZero)pan=pan+1; | ||
+ | // if (tilt>TiltZero)tilt=tilt-1; | ||
+ | // if (tilt<TiltZero)tilt=tilt+1; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | panscale=(right_value1+left_value3)*LRscalefactor/10; | ||
+ | tiltscale=(up_value0+down_value2)*UDscalefactor/10; | ||
+ | |||
+ | if (left_value3>right_value1) | ||
+ | { | ||
+ | leftright=(left_value3-right_value1)*15/panscale; | ||
+ | pan=pan-leftright; | ||
+ | } | ||
+ | |||
+ | if (left_value3<right_value1) | ||
+ | { | ||
+ | leftright=(right_value1-left_value3)*15/panscale; | ||
+ | pan=pan+leftright; | ||
+ | } | ||
+ | |||
+ | if (up_value0>down_value2) | ||
+ | { | ||
+ | updown=(up_value0-down_value2)*15/tiltscale; | ||
+ | tilt=tilt-updown; | ||
+ | } | ||
+ | |||
+ | if (down_value2>up_value0) | ||
+ | { | ||
+ | updown=(down_value2-up_value0)*15/tiltscale; | ||
+ | tilt=tilt+updown; | ||
+ | } | ||
+ | |||
+ | panOld=pan; | ||
+ | tiltOld=tilt; | ||
+ | if (pan<LRmin) pan=LRmin; | ||
+ | if (pan>LRmax) pan=LRmax; | ||
+ | if (tilt<UDmin)tilt=UDmin; | ||
+ | if (tilt>UDmax)tilt=UDmax; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void setup() | ||
{ | { | ||
? | + | Wire.begin(); | |
? | + | Serial.begin(9600); | |
? | + | panLR.attach(panPin); | |
? | + | panLR.write(PanZero); | |
? | + | tiltUD.attach(tiltPin); | |
? | + | tiltUD.write(TiltZero); | |
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
} | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | panLR.write(pan); | ||
+ | tiltUD.write(tilt); | ||
+ | readvalues(); | ||
+ | IRfollow(); | ||
+ | } | ||
+ | </pre> | ||
+ | * 程序效果 | ||
+ | |||
+ | ===example3_Arduino & Processing=== | ||
+ | * 主要硬件 | ||
+ | :Arduino UNO 控制器 | ||
+ | : 傳感器擴(kuò)展板 V5.0 | ||
+ | :復(fù)眼傳感器 | ||
+ | :杜邦線 | ||
+ | :USB 數(shù)據(jù)線 | ||
+ | |||
+ | * 硬件連接 <br/> | ||
+ | [[文件:02S103101.png|700px|縮略圖|居中]] | ||
+ | |||
+ | * 示例程序 -- Processing | ||
+ | <pre style='color:blue'> | ||
+ | import processing.serial.*; | ||
+ | Serial myPort; | ||
+ | int sWidth=640, sHeight=640; | ||
+ | float xHairLength = 200; | ||
+ | float xpos, ypos; | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | size(640, 640); | ||
+ | println(Serial.list()); | ||
+ | myPort = new Serial(this, Serial.list()[0], 9600); | ||
+ | smooth(); | ||
+ | } | ||
+ | |||
+ | void draw() | ||
+ | { | ||
+ | background(255); | ||
+ | ellipse((640/2)+xpos, (640/2)+ypos, 20, 20); | ||
+ | stroke(0); | ||
+ | line((sWidth/2)-250, sHeight/2, (sWidth/2)+250, sHeight/2); | ||
+ | stroke(0); | ||
+ | line(sWidth/2, (sHeight/2)-250, sWidth/2, (sHeight/2)+250); | ||
+ | } | ||
+ | |||
+ | void serialEvent(Serial myPort) | ||
+ | { | ||
+ | String myString = myPort.readStringUntil('\n'); | ||
+ | if(myString != null) | ||
+ | { | ||
+ | myString = trim(myString); | ||
+ | int sensors[] = int(split(myString, ',')); | ||
+ | for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) | ||
+ | { | ||
+ | print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); | ||
+ | } | ||
+ | println(); | ||
+ | if (sensors.length > 1) | ||
+ | { | ||
+ | float left,right,up,down; | ||
+ | left = map(sensors[3], 0,1000,0,width); | ||
+ | right = map(sensors[1], 0,1000,0,height); | ||
+ | up = map(sensors[0], 0,1000,0,width); | ||
+ | down = map(sensors[2], 0,1000,0,height); | ||
+ | xpos=right-left; | ||
+ | ypos=up-down; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | * 示例程序 -- arduino | ||
+ | <pre style='color:blue'> | ||
+ | #include <Wire.h> | ||
+ | #define PCF8591 (0x90 >> 1) // I2C bus address | ||
+ | |||
+ | byte value0, value1, value2, value3; | ||
void readvalues(){ | void readvalues(){ | ||
Wire.beginTransmission(PCF8591); // wake up PCF8591 | Wire.beginTransmission(PCF8591); // wake up PCF8591 | ||
? | Wire.write(0x04); | + | Wire.write(0x04); |
? | Wire.endTransmission(); | + | Wire.endTransmission(); |
Wire.requestFrom(PCF8591, 5); | Wire.requestFrom(PCF8591, 5); | ||
+ | value0=Wire.read(); | ||
value0=Wire.read(); //上 | value0=Wire.read(); //上 | ||
? | + | value1=Wire.read(); //右 | |
? | value1=Wire.read(); // 右 | + | |
value2=Wire.read(); //下 | value2=Wire.read(); //下 | ||
value3=Wire.read(); //左 | value3=Wire.read(); //左 | ||
? | Serial.print(value0); Serial.print(" "); | + | Serial.print(value0);Serial.print(","); |
? | Serial.print(value1); Serial.print(" "); | + | Serial.print(value1);Serial.print(","); |
? | Serial.print(value2); Serial.print(" "); | + | Serial.print(value2);Serial.print(","); |
? | Serial.print(value3); Serial.print(" " | + | Serial.print(value3); |
? | + | Serial.print("\n"); | |
} | } | ||
第139行: | 第304行: | ||
{ | { | ||
Wire.begin(); | Wire.begin(); | ||
? | + | Serial.begin(9600); | |
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | + | ||
? | Serial.begin(9600); | + | |
} | } | ||
void loop() | void loop() | ||
{ | { | ||
readvalues(); | readvalues(); | ||
? | + | } | |
? | }</pre> | + | </pre> |
? | + | * 程序效果 | |
+ | [[文件:02S103100.png|600px|縮略圖|居中]] | ||
? | == | + | ==相關(guān)資料== |
[[文件:erweima.png|230px|無框|右]] | [[文件:erweima.png|230px|無框|右]] | ||
? | + | * 產(chǎn)品資料 | |
? | + | 下載鏈接: https://pan.baidu.com/s/1wPQh9f7bCNVx92ODYYXKug | |
? | + | 提取碼:kgjt | |
? | + | * 產(chǎn)品購買鏈接:http://www.alsrobot.cn/goods-816.html |
2021年7月27日 (二) 17:45的最后版本
目錄 |
產(chǎn)品概述
復(fù)眼傳感是奧松機(jī)器人推出的復(fù)眼傳感器由許多對紅外線敏感的晶體管和發(fā)光二極管組成。它可以追蹤20厘米范圍內(nèi)物體的移動。盡管傳感器是一個整體,但是你依然可以讀取到每一個紅外線(IR)光敏晶體管的信息。復(fù)眼傳感器采用IIC通訊方式,數(shù)據(jù)傳輸更加簡便。
校正周圍光線是通過關(guān)閉IR LED和比較數(shù)值完成的。如果要改善從復(fù)眼中讀取的數(shù)值,你必須要進(jìn)行校準(zhǔn)。最好等到晚上當(dāng)IR光線不存在時進(jìn)行。注意紅外線可以穿過關(guān)閉的百合窗,所以如果你不想等到晚上,可以去地下室,或者是沒有窗戶的房間,這樣就可以測量數(shù)值了。將一張紙置于傳感器的前方(約20厘米遠(yuǎn)),觀察每支引腳的數(shù)值差異。使用紙張時數(shù)值差異不大(+/- 100)。如果某個數(shù)值過高,可以使用不透明的膠帶或熱收縮膜阻擋部分紅外線。如果數(shù)值過低,則阻擋一部分分散到其他傳感器上的紅外線。
產(chǎn)品參數(shù)
基本參數(shù)
- 品名 紅外線復(fù)眼傳感器
- 貨號 RB-02S103
- 品牌 AlsRobot
- 產(chǎn)地 哈爾濱
- 尺寸 50mm×48mm
- 重量 9g
- 包裝 防靜電包裝
- 固定孔 M3*4個
電氣參數(shù)
- 產(chǎn)品類型:數(shù)字傳感器
- 接口類型:4P防插反接口
- 信號類型:IIC數(shù)字信號
- 工作電壓:3.0V~5.0V
- 工作電流:100mA
- 引腳定義:+ 電源正;- 電源負(fù);SDA IIC數(shù)據(jù)引腳;SCL IIC時鐘引腳
- 連接線: 4P 傳感器連接線
- 檢測范圍:0~20cm
- 工作溫度:-20℃~70℃
- 測試范圍:上、下、左、右輸出四路模擬值范圍(0-255)
- 固定孔:M3*4個
- 產(chǎn)品尺寸(mm):50mm*48mm
使用方法
example1_Arduino
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴(kuò)展板 V5.0
- 復(fù)眼傳感器
- 4P 傳感器連接線
- USB 數(shù)據(jù)線
- 硬件連接
- 示例程序
#include <Wire.h> #define PCF8591 (0x90 >> 1) // I2C bus address byte value0, value1, value2, value3; void readvalues(){ Wire.beginTransmission(PCF8591); // wake up PCF8591 Wire.write(0x04); Wire.endTransmission(); Wire.requestFrom(PCF8591, 5); value0=Wire.read(); value0=Wire.read(); //上 value1=Wire.read(); //右 value2=Wire.read(); //下 value3=Wire.read(); //左 Serial.print("value0= "); Serial.print(value0);Serial.print("\t"); Serial.print("value1= "); Serial.print(value1);Serial.print("\t"); Serial.print("value2= "); Serial.print(value2);Serial.print("\t"); Serial.print("value3= "); Serial.print(value3);Serial.print("\t"); Serial.println(); } void setup() { Wire.begin(); Serial.begin(9600); } void loop() { readvalues(); }
- 程序效果
通過串口監(jiān)視器,即可讀取傳感器返回的數(shù)據(jù)。
example2_Arduino
- 主要硬件
- Arduino UNO 控制器
- Motor Driver Shield 電機(jī)驅(qū)動板
- 復(fù)眼傳感器
- 杜邦線
- USB 數(shù)據(jù)線
- 二自由度云臺
- 硬件連接
- 示例程序
#include <Servo.h> #include <Wire.h> #define PCF8591 (0x90 >> 1) #define panPin 10 #define tiltPin 5 byte LRscalefactor=10; byte UDscalefactor=10; int distancemax=80; int PanZero=90; int TiltZero=90; int LRmax=170; int LRmin=10; int UDmax=150; int UDmin=30; int pan=PanZero; int tilt=TiltZero; int panscale; int tiltscale; int panOld; int tiltOld; int distance; int temp; int updown; int leftright; Servo panLR; Servo tiltUD; byte up_value0, right_value1, down_value2, left_value3; void readvalues(){ Wire.beginTransmission(PCF8591); Wire.write(0x04); Wire.endTransmission(); Wire.requestFrom(PCF8591, 5); up_value0=Wire.read(); up_value0=Wire.read(); //上 right_value1=Wire.read(); //右 down_value2=Wire.read(); //下 left_value3=Wire.read(); //左 distance=(up_value0+right_value1+down_value2+left_value3)/4; Serial.print("up_value0= "); Serial.print(up_value0);Serial.print("\t"); Serial.print("right_value1= "); Serial.print(right_value1);Serial.print("\t"); Serial.print("down_value2= "); Serial.print(down_value2);Serial.print("\t"); Serial.print("left_value3= "); Serial.print(left_value3);Serial.print("\t"); Serial.print("distance= "); Serial.print(distance);Serial.print("\t"); Serial.println(); } void IRfollow() { if (distance<distancemax) { ; // if (pan>PanZero)pan=pan-1; // if (pan<PanZero)pan=pan+1; // if (tilt>TiltZero)tilt=tilt-1; // if (tilt<TiltZero)tilt=tilt+1; } else { panscale=(right_value1+left_value3)*LRscalefactor/10; tiltscale=(up_value0+down_value2)*UDscalefactor/10; if (left_value3>right_value1) { leftright=(left_value3-right_value1)*15/panscale; pan=pan-leftright; } if (left_value3<right_value1) { leftright=(right_value1-left_value3)*15/panscale; pan=pan+leftright; } if (up_value0>down_value2) { updown=(up_value0-down_value2)*15/tiltscale; tilt=tilt-updown; } if (down_value2>up_value0) { updown=(down_value2-up_value0)*15/tiltscale; tilt=tilt+updown; } panOld=pan; tiltOld=tilt; if (pan<LRmin) pan=LRmin; if (pan>LRmax) pan=LRmax; if (tilt<UDmin)tilt=UDmin; if (tilt>UDmax)tilt=UDmax; } } void setup() { Wire.begin(); Serial.begin(9600); panLR.attach(panPin); panLR.write(PanZero); tiltUD.attach(tiltPin); tiltUD.write(TiltZero); } void loop() { panLR.write(pan); tiltUD.write(tilt); readvalues(); IRfollow(); }
- 程序效果
example3_Arduino & Processing
- 主要硬件
- Arduino UNO 控制器
- 傳感器擴(kuò)展板 V5.0
- 復(fù)眼傳感器
- 杜邦線
- USB 數(shù)據(jù)線
- 硬件連接
- 示例程序 -- Processing
import processing.serial.*; Serial myPort; int sWidth=640, sHeight=640; float xHairLength = 200; float xpos, ypos; void setup() { size(640, 640); println(Serial.list()); myPort = new Serial(this, Serial.list()[0], 9600); smooth(); } void draw() { background(255); ellipse((640/2)+xpos, (640/2)+ypos, 20, 20); stroke(0); line((sWidth/2)-250, sHeight/2, (sWidth/2)+250, sHeight/2); stroke(0); line(sWidth/2, (sHeight/2)-250, sWidth/2, (sHeight/2)+250); } void serialEvent(Serial myPort) { String myString = myPort.readStringUntil('\n'); if(myString != null) { myString = trim(myString); int sensors[] = int(split(myString, ',')); for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); } println(); if (sensors.length > 1) { float left,right,up,down; left = map(sensors[3], 0,1000,0,width); right = map(sensors[1], 0,1000,0,height); up = map(sensors[0], 0,1000,0,width); down = map(sensors[2], 0,1000,0,height); xpos=right-left; ypos=up-down; } } }
- 示例程序 -- arduino
#include <Wire.h> #define PCF8591 (0x90 >> 1) // I2C bus address byte value0, value1, value2, value3; void readvalues(){ Wire.beginTransmission(PCF8591); // wake up PCF8591 Wire.write(0x04); Wire.endTransmission(); Wire.requestFrom(PCF8591, 5); value0=Wire.read(); value0=Wire.read(); //上 value1=Wire.read(); //右 value2=Wire.read(); //下 value3=Wire.read(); //左 Serial.print(value0);Serial.print(","); Serial.print(value1);Serial.print(","); Serial.print(value2);Serial.print(","); Serial.print(value3); Serial.print("\n"); } void setup() { Wire.begin(); Serial.begin(9600); } void loop() { readvalues(); }
- 程序效果
相關(guān)資料
- 產(chǎn)品資料
下載鏈接: https://pan.baidu.com/s/1wPQh9f7bCNVx92ODYYXKug 提取碼:kgjt
- 產(chǎn)品購買鏈接:http://lifestyle201.com/goods-816.html