Moving Robot Tank drive certain angle based on command

58 views
Skip to first unread message

pl22...@ahschool.com

unread,
Jan 20, 2016, 1:08:25 PM1/20/16
to Strongback

How can you make a drivetrain in tank turn a certain angle from its previous point on its own radius? For example, if my robot is facing forward, is there anyway to get it turn say, 15 degrees clockwise, when I give it a command of MoveAngle(15);? This is all obviously in terms of Strongback.

examples would be greatly appreciated.

Randall Hauch

unread,
Jan 20, 2016, 1:44:14 PM1/20/16
to Strongback
There is no easy way to do this on any robot, whether or not your using Strongback. Strongback makes it easier to use the hardware classes that comes with WPILib and it gives you some additional pieces (see below), but it doesn't provide this high-level functionality.

A "hack" is to time your robot as it rotates at a known rotational speed. You can use this to compute an estimated time for a desired change in angle (at that speed), and with this you can create a command like "RotateLeft" or "RotateRight" that takes the angle, computes the estimated time (again, at the speed you measured), and sets the timeout for the command. This will not be accurate, but it may be worth a shot.

Of course, the best way is to use a gyroscope or IMU device that measures the angular position, velocity, and acceleration in multiple axis. WPILib has support for analog gyroscopes that connects via the analog input, and the digital ADXRS450 gyro sensor that connects via SPI. Strongback already has support to obtain a Gyroscope for these via the Hardware class. See https://strongback.gitbooks.io/using-strongback/content/angle_sensors.html.

Now, being able to obtain the current angle is one part: the other is accurately controlling your robot to rotate to a different angle than it's current orientation. To do this well, you'll likely need some form of feedback control loop. Strongback recently added a PIDController interface and a SoftwarePIDController implementation, which you can set up with the angular position as the input. (See the JavaDoc on these classes and the SoftwarePIDControllerTest for a bit more context.) However, determining the proportional, integral, and differential gains is always a tricky art form, and there are lots of references on Chief Delphi and other sites. (There is also a TalonPIDController implementation that delegates to the Talon SRX, though that won't help you in this situation since the motor controller is not designated solely for controlling angular position. You'd use this for a subsystem that has a motor to move an arm or something else based upon some other input sensors, such as limit switches.) I'd probably set up the controller to compute a rotational speed to achieve the desired angle (each time you call "computeOutput()" on the controller), and then your command or other logic has to add/subtract this to the motor values. (It all depends on whether you have the motors do anything else while rotating.)

Sorry this isn't easier and that we don't have any examples. This is one of the harder parts of programming a robot for FRC. Feel free to ask on Chief Delphi for tips or examples on using a PID controller to control/alter motor speeds for rotational position.

Randall Hauch

unread,
Jan 20, 2016, 1:52:04 PM1/20/16
to Strongback
If this is for autonomous, then another approach might be to program the robot to follow a pre-programmed trajectory. Again, this is beyond Strongback's purpose, but you can find examples on Chief Delphi. For example, Team 254 did this in 2014 (see here). See also this presentation video at the 2015 FIRST Championships Conference.
Reply all
Reply to author
Forward
0 new messages