【问题标题】:ROBOTC - Programming Autonomous With Integrated EncodersROBOTC - 使用集成编码器进行自主编程
【发布时间】:2016-10-10 17:13:25
【问题描述】:

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

我查看了多个教程,但没有一个有效。 有没有人有代码可以让电机(393 个电机)的计数达到 720 个?


#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)
//*!!Code 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;

}

【问题讨论】:

  • 编码器值可以减少而不是增加吗?尝试将您的 while 条件更改为 nMotorEncoder[FL] &gt; -720

标签: integrated robotc


【解决方案1】:

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

所以这段代码应该适合你:

//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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    相关资源
    最近更新 更多