Drivetrain gyro turning

I was wondering if the angle parameter in the drivetrain turn command automatically uses the Gyro connected to the Brain or I need to manually make it use the connected Gyro through a loop.

Does this:

dt.turnFor(-160.5, rotationUnits::deg, 40, velocityUnits::pct);

equal this?:

while(Gyro.angle() >-160.5)
{
  dt.turn(turnType::left, 40, velocityUnits::pct);
}

if dt is an instance of a drivetrain, then dt.turnFor will use the gyro if you have configured it that way (in which case it would be an instance of a smartdrive). If you configured without a gyro then it will use the motor encoders (and the wheel circumference etc.) to do the turn.

The turn we do with the gyro is a little more complex than just

while(Gyro.angle() >-160.5)
{
  dt.turn(turnType::left, 40, velocityUnits::pct);
}

It will slow the drivetrain as it nears the target and also correct for any overshoot. However, it does not use a PID algorithm, we had to leave room for students to improve upon what we provide.

5 Likes

I have not intialized the drivetrain as an instance of smartdrive but simply as:

vex::motor_group l(LeftFrontMotor, LeftRearMotor);
vex::motor_group r(RightFrontMotor, RightRearMotor);
vex::drivetrain dt(l, r);

Do I need to initialize the drivetrain as a smartdrive in order for it to use the gyro? Also, do I need to upgrade the project in order to use smartdrive?

1 Like

See this

2 Likes