<分区>
我一直在看一些 RobotC 代码,它与 C 非常相似(而且我没有足够的声誉来制作新的 RobotC 标签),我遇到了 *= 运算符。我在谷歌上搜索了很多,但我只能知道它是 C 中的按位运算符。似乎没有人确切地说出它的作用,但是如果你们能提供帮助,我将不胜感激。
rot *= 5;
这是我找到它的代码。所有的功能都是重新调整机器人的方向,使其始终面向北方。
//Turns back to North
void TurnStraight(int cdegree) //cdegree is the sensor value read by the compass sensor
{
int rot = cdegree % 360;
int mot = 1;
//stop when the NXT facing North
if (cdegree == 0){
return;
}
//reset the encoders value to avoid overflaow
clear_motor_encoders();
if (cdegree > 180 && cdegree < 360){
rot = 360 - rot;
mot = 0;
}
rot *= 5; // ratio between the circumference of the tire to the circumference of the rotation circle around itself
switch (mot){
case 1:
moveTo(rot/2,1);
break;
case 0:
moveTo(rot/2,-1);
break;
case -1:
moveTo(rot,1);
break;
}
}
void clear_motor_encoders()
{
nMotorEncoder[motorA] = 0;
}
void moveTo(int rot, int direction)
{
nSyncedMotors = synchAC;
nSyncedTurnRatio = -100;
nMotorEncoderTarget[motorA] = rot;
motor[motorA] = direction * 50;
while (nMotorRunState[motorA] != runStateIdle) ;
motor[motorA] = 0;
}
这当然不是我的代码,我只是想知道它是如何工作的。