“SKU:RB-02S103 复眼传感器”的版本间的差异
来自ALSROBOT WiKi
(→产品参数) |
|||
第7行: | 第7行: | ||
==产品参数== | ==产品参数== | ||
− | |||
===基本参数=== | ===基本参数=== | ||
#品名 红外线复眼传感器<br/> | #品名 红外线复眼传感器<br/> | ||
第32行: | 第31行: | ||
− | + | ==使用方法== | |
− | + | ===example1_Arduino=== | |
− | + | * 主要硬件 | |
+ | :Arduino UNO 控制器 | ||
+ | :复眼传感器 | ||
+ | :杜邦线 | ||
+ | :USB 数据线 | ||
− | + | * 硬件连接 <br/> | |
− | < | + | [[文件:02S10301.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(){ | 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(value0);Serial.print("\t"); |
− | Serial.print(value1); Serial.print(" "); | + | Serial.print("value1= "); Serial.print(value1);Serial.print("\t"); |
− | Serial.print(value2); Serial.print(" "); | + | Serial.print("value2= "); Serial.print(value2);Serial.print("\t"); |
− | Serial.print(value3); Serial.print(" "); | + | Serial.print("value3= "); Serial.print(value3);Serial.print("\t"); |
Serial.println(); | Serial.println(); | ||
} | } | ||
第139行: | 第69行: | ||
{ | { | ||
Wire.begin(); | Wire.begin(); | ||
− | + | Serial.begin(9600); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | Serial.begin(9600); | + | |
} | } | ||
void loop() | void loop() | ||
{ | { | ||
readvalues(); | readvalues(); | ||
− | + | } | |
− | }</pre> | + | </pre> |
− | + | * 程序效果 | |
+ | 通过串口监视器,即可读取传感器返回的数据。<br/> | ||
+ | |||
+ | ===example2_Arduino=== | ||
+ | * 主要硬件 | ||
+ | :Arduino UNO 控制器 | ||
+ | :Motor Driver Shield 电机驱动板 | ||
+ | :复眼传感器 | ||
+ | :杜邦线 | ||
+ | :USB 数据线 | ||
+ | :二自由度云台 | ||
+ | |||
+ | * 硬件连接 | ||
+ | D5 - Servo1 | ||
+ | D10 - Servo2 | ||
+ | 复眼 - IIC接口 | ||
+ | |||
+ | * 示例程序 | ||
+ | <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> | ||
+ | * 程序效果 | ||
==产品相关推荐== | ==产品相关推荐== |
2018年9月28日 (五) 11:07的版本
目录 |
产品概述
复眼传感是奥松机器人推出的复眼传感器由许多对红外线敏感的晶体管和发光二极管组成。它可以追踪20厘米范围内物体的移动。尽管传感器是一个整体,但是你依然可以读取到每一个红外线(IR)光敏晶体管的信息。复眼传感器采用IIC通讯方式,数据传输更加简便。
校正周围光线是通过关闭IR LED和比较数值完成的。如果要改善从复眼中读取的数值,你必须要进行校准。最好等到晚上当IR光线不存在时进行。注意红外线可以穿过关闭的百合窗,所以如果你不想等到晚上,可以去地下室,或者是没有窗户的房间,这样就可以测量数值了。将一张纸置于传感器的前方(约20厘米远),观察每支引脚的数值差异。使用纸张时数值差异不大(+/- 100)。如果某个数值过高,可以使用不透明的胶带或热收缩膜阻挡部分红外线。如果数值过低,则阻挡一部分分散到其他传感器上的红外线。
产品参数
基本参数
- 品名 红外线复眼传感器
- 货号 RB-02S103
- 品牌 AlsRobot
- 产地 哈尔滨
- 尺寸 50mm×48mm
- 重量 9g
- 包装 防静电包装
- 固定孔 M3*4个
电气参数
- 产品类型:数字传感器
- 接口类型:4P防插反接口
- 信号类型:IIC数字信号
- 工作电压:3.0V~5.0V
- 工作电流:100mA
- 引脚定义:+ 电源正;- 电源负;SDA IIC数据引脚;SCL IIC时钟引脚
- 连接线: 4P 传感器连接线
- 检测范围:0~20cm
- 工作温度:-20℃~70℃
- 测试范围:上、下、左、右输出四路模拟值范围(0-255)
- 固定孔:M3*4个
- 产品尺寸(mm):50mm*48mm
使用方法
example1_Arduino
- 主要硬件
- Arduino UNO 控制器
- 复眼传感器
- 杜邦线
- USB 数据线
- 硬件连接
- 示例程序
#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(); }
- 程序效果
通过串口监视器,即可读取传感器返回的数据。
example2_Arduino
- 主要硬件
- Arduino UNO 控制器
- Motor Driver Shield 电机驱动板
- 复眼传感器
- 杜邦线
- USB 数据线
- 二自由度云台
- 硬件连接
D5 - Servo1 D10 - Servo2 复眼 - IIC接口
- 示例程序
#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(); }
- 程序效果