首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ROBOTC -集成编码器编程自主

ROBOTC -集成编码器编程自主
EN

Stack Overflow用户
提问于 2016-10-10 17:13:25
回答 1查看 932关注 0票数 0

我有一个X驱动器是用ROBOTC编码的。我和我的团队已经在机器人上安装了集成的电机编码器(用于自主阶段)。但是,它们运行的代码是不正确的。下面是当前的自治代码。当我运行它时,它只会以不同的速度永远前进。

我看过多个教程,但没有一个能起作用。,有人有代码让马达(393马达)数到720?吗?

代码语言:javascript
复制
#pragma config(I2C_Usage, I2C1, i2cSensors)
#pragma config(Sensor, I2C_1, sensorQuadEncoderOnI2CPort, AutoAssign)
#pragma config(Motor,  port2, FL, tmotorVex393_MC29, PIDControl, encoderPort, I2C_1)
#pragma config(Motor,  port3, BR, tmotorVex393_MC29, PIDControl, reversed, encoderPort, I2C_1)
#pragma config(Motor,  port8, BL, tmotorVex393_MC29, PIDControl, encoderPort, I2C_1)
#pragma config(Motor,  port9, FR, tmotorVex393_MC29, PIDControl, reversed, encoderPort, I2C_1)
//*automatically generated by 'ROBOTC' configuration wizard               *//

task main()
{
// Autonomous with Integrated Encoders
nMotorPIDSpeedCtrl[FL] = mtrSpeedReg;
nMotorPIDSpeedCtrl[FR] = mtrSpeedReg;
nMotorPIDSpeedCtrl[BL] = mtrSpeedReg;
nMotorPIDSpeedCtrl[BR] = mtrSpeedReg;

//Clears motor values
nMotorEncoder[FL] = 0;
nMotorEncoder[FR] = 0;
nMotorEncoder[BL] = 0;
nMotorEncoder[BR] = 0;

//Forward
motor[FL] = 63;
motor[FR] = 63;
motor[BL] = 63;
motor[BR] = 63;
   while(nMotorEncoder[FL] < 720) {
}

//Clears motor values
nMotorEncoder[FL] = 0;
nMotorEncoder[FR] = 0;
nMotorEncoder[BL] = 0;
nMotorEncoder[BR] = 0;

}
EN

回答 1

Stack Overflow用户

发布于 2017-07-20 18:14:42

您需要在while循环之后显式地停止电机(而不仅仅是将编码器调零)。否则,机器人不知道停下来,它只知道它通过了编码器目标。

因此,这段代码应该适用于您:

代码语言:javascript
复制
//Clears motor values
nMotorEncoder[FL] = 0;
nMotorEncoder[FR] = 0;
nMotorEncoder[BL] = 0;
nMotorEncoder[BR] = 0;

 motor[FL] = 63;
 motor[FR] = 63;
 motor[BL] = 63;
 motor[BR] = 63;
//Forward
while(nMotorEncoder[FL] < 720) {
}
//stops motors
motor[FL] = 0;
motor[FR] = 0;
motor[BL] = 0;
motor[BR] = 0;
//Clears motor encoder values
nMotorEncoder[FL] = 0;
nMotorEncoder[FR] = 0;
nMotorEncoder[BL] = 0;
nMotorEncoder[BR] = 0;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39963431

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档