(SKU:SEN0038)A4WD 3PA 机器人小车专用编码器脉冲计数器套件
来自DFRobot Product Wiki
目录 |
概述
4WD/3PA小车专用编码器采用非接触式方式把角位移转换成电信号。遮断式光电采样传感器将编码盘上的透光区和不透光区用高低脉冲进行状态标记并通过计算小车轮子在一定时间内产生的脉冲个数可以换算出轮子的转速。
由于安装空间的限制,编码盘上设计齿数只有10齿,若采用正负沿采样可以得到20个脉冲/圈的测量精度。
该编码器是A4WD/3PA机器人小车实现高级避障,PID速度控制等算法的必要配件。
它包括编码器,塑料管,纸介导的垫片等
技术规格
- 信号类型:数字输出
- 工作电压:5V DC
- 电流:<20mA
- 尺寸:兼容Baron-4WD/Turtle-2WD小车
- 接口类型:PH2.0-3P
示例代码
// # // # Editor : Lauren from DFRobot // # Date : 17.01.2012 // # Product name: Wheel Encoders for DFRobot 3PA and 4WD Rovers // # Product SKU : SEN0038 // # Description: // # The sketch for using the encoder on the DFRobot Mobile platform // # Connection: // # left wheel encoder -> Digital pin 2 // # right wheel encoder -> Digital pin 3 // # #define LEFT 0 #define RIGHT 1 long coder[2] = { 0,0}; int lastSpeed[2] = { 0,0}; void setup(){ Serial.begin(9600); //init the Serial port to print the data attachInterrupt(LEFT, LwheelSpeed, CHANGE); //init the interrupt mode for the digital pin 2 attachInterrupt(RIGHT, RwheelSpeed, CHANGE); //init the interrupt mode for the digital pin 3 } void loop(){ static unsigned long timer = 0; //print manager timer if(millis() - timer > 100){ Serial.print("Coder value: "); Serial.print(coder[LEFT]); Serial.print("[Left Wheel] "); Serial.print(coder[RIGHT]); Serial.println("[Right Wheel]"); lastSpeed[LEFT] = coder[LEFT]; //record the latest speed value lastSpeed[RIGHT] = coder[RIGHT]; coder[LEFT] = 0; //clear the data buffer coder[RIGHT] = 0; timer = millis(); } } void LwheelSpeed() { coder[LEFT] ++; //count the left wheel encoder interrupts } void RwheelSpeed() { coder[RIGHT] ++; //count the right wheel encoder interrupts }
安装指导
Step1:
Step2:
Step3:
Step4:
编码器原理图
[编码器原理图]