本文整理汇总了C++中Actuator::Forward方法的典型用法代码示例。如果您正苦于以下问题:C++ Actuator::Forward方法的具体用法?C++ Actuator::Forward怎么用?C++ Actuator::Forward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actuator
的用法示例。
在下文中一共展示了Actuator::Forward方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loop
//-----------------------------------------------------------------------------
//
void loop()
{
/* Update all the values */
while(i2cRead(0x3B,i2cData,14));
accX = ((i2cData[0] << 8) | i2cData[1]);
accY = ((i2cData[2] << 8) | i2cData[3]);
accZ = ((i2cData[4] << 8) | i2cData[5]);
tempRaw = ((i2cData[6] << 8) | i2cData[7]);
gyroX = ((i2cData[8] << 8) | i2cData[9]);
gyroY = ((i2cData[10] << 8) | i2cData[11]);
gyroZ = ((i2cData[12] << 8) | i2cData[13]);
// atan2 outputs the value of -π to π (radians) - see http://en.wikipedia.org/wiki/Atan2
// We then convert it to 0 to 2π and then from radians to degrees
accXangle = (atan2(accY,accZ)+PI)*RAD_TO_DEG;
accYangle = (atan2(accX,accZ)+PI)*RAD_TO_DEG;
double gyroXrate = (double)gyroX/131.0;
double gyroYrate = -((double)gyroY/131.0);
gyroXangle += gyroXrate*((double)(micros()-timer)/1000000); // Calculate gyro angle without any filter
gyroYangle += gyroYrate*((double)(micros()-timer)/1000000);
//gyroXangle += kalmanX.getRate()*((double)(micros()-timer)/1000000); // Calculate gyro angle using the unbiased rate
//gyroYangle += kalmanY.getRate()*((double)(micros()-timer)/1000000);
compAngleX = (0.93*(compAngleX+(gyroXrate*(double)(micros()-timer)/1000000)))+(0.07*accXangle); // Calculate the angle using a Complimentary filter
compAngleY = (0.93*(compAngleY+(gyroYrate*(double)(micros()-timer)/1000000)))+(0.07*accYangle);
kalAngleX = kalmanX.getAngle(accXangle, gyroXrate, (double)(micros()-timer)/1000000); // Calculate the angle using a Kalman filter
kalAngleY = kalmanY.getAngle(accYangle, gyroYrate, (double)(micros()-timer)/1000000);
timer = micros();
temp = ((double)tempRaw + 12412.0) / 340.0;
// Print Data
Serial.print("accX: "); Serial.print(accX); Serial.print("\t");
Serial.print("accY: "); Serial.print(accY); Serial.print("\t");
Serial.print("accZ: "); Serial.print(accZ); Serial.print("\t");
Serial.print("gyroX: "); Serial.print(gyroX); Serial.print("\t");
Serial.print("gyroY: "); Serial.print(gyroY); Serial.print("\t");
Serial.print("gyroZ: "); Serial.print(gyroZ); Serial.print("\t");
Serial.print(accXangle); Serial.print("\t");
Serial.print(gyroXangle); Serial.print("\t");
Serial.print(compAngleX); Serial.print("\t");
Serial.print("kalAngleY: "); Serial.print(kalAngleX); Serial.print("\t");
Serial.print("\t");
Serial.print(accYangle); Serial.print("\t");
Serial.print(gyroYangle); Serial.print("\t");
Serial.print(compAngleY); Serial.print("\t");
Serial.print("kalAngleY: "); Serial.print(kalAngleY); Serial.print("\t");
Serial.print(temp); Serial.print("\t");
int corr = UpdatePid( 178, kalAngleX );
Serial.print(" corr:");
Serial.print(corr);
if( (corr > 0 && prevCmd < 0) ||
(corr < 0 && prevCmd > 0) )
{
m1.Brake();
m2.Brake();
}
prevCmd = corr;
if( corr > 0 )
{
m1.Backward( corr );
m2.Backward( corr );
}
else if( corr < 0 )
{
m1.Forward( -corr );
m2.Forward( -corr );
}
else
{
m1.Coast();
m2.Coast();
}
// LOOP CONTROL
lastLoopUsefulTime = millis() - loopRefTime;
if( lastLoopUsefulTime < FREQ )
{
delay( FREQ - lastLoopUsefulTime );
}
loopRefTime = millis();
Serial.print("\r\n");
}