PIDSubsystem CommandBased DifferentialDrive

Obi-Wan, you’re my only hope…

OK, so I want to use a ADXRS450 Gyro with my DifferentialDrive subsystem.
I want to drive and turn based on the angle that is sent (autonomous command).

I cannot seem to find instructions or a library that explains this. Anyone have an example doing this?

You are correct that there’s no standard tutorial on how to do this.

The usual “simplest effective turn-to-angle loop” is a feedback loop closed on the gyro heading whose output goes to a speed differential between the two sides of the drive.

There are a number of ways to “plumb” default WPILib objects in a way that will do this; it is not hard to figure out one of them by reading through the javadocs - the relevant classes to look at are PIDController and its various convenience wrappers (PIDCommand and PIDSubsystem). Which one is best depends on how you want your program flow to go; we tend to use PIDCommand for things like this, but it is up to you.

I’m still very new to this so I need to see a RobotDrive class that is doing this.

You can use bang-bang control. For instance when you want to turn in place at a desire angle set the curvatureDrive() method to 0 xspeed, value between 1 to -1 for zrotation depends on clockwise or counter clockwise you want the bot to rotate, true for quickturn mode like drive.curvature(0,1 or -1, true), and run that in a loop until the gyro.get() (actual angle) is close to your target (the angle you previously received), and set the drive to a stop.

PID control will be a better solution and more accurate because it prevents over shooting, but it’s time consuming so if you started new.
Good luck

Sent from my iPad using Tapatalk