Example code for Arm

My robot has an arm on it that can rotate 180 degrees around its center. Because gravity affects the arm differently based on where it is rotated, I don’t know how to program it well. How can I program it using PID and Feedforward? Any example projects would be greatly appreciated!

I think the PID controller will be unaffected (programming wise, not physically). WPIlib has an arm feedforward class that calculates a feed forward based on the arm’s angle.

I’ve looked at it but I don’t see where you would input an angle.

// Calculates the feedforward for a position of 1 units, a velocity of 2 units/second, and
// an acceleration of 3 units/second^2
// Units are determined by the units of the gains passed in at construction.
feedforward.calculate(1, 2, 3);

“Angle” is a positional unit, so the first parameter would be the angle you want.

More in the docs here: Feedforward Control in WPILib — FIRST Robotics Competition documentation

1 Like

Would you happen to know an example of this code being used somewhere?

We started with one of the example projects that comes with WPILIB. We used the ArmBot example to generate base code. It has a PID control subsystem with feed forward to account for weight of the arm.

First year for our current team members working with PID controllers. We have been working to get the code going to certain set points. Worked yesterday to add factor to account for the gearbox.

Our mechanical team should have our arm finished on Monday and we can test out the code

We plan on using the Recalc website to calculate the constants to use in the code to account for the feed forward terms.

There is an article on the WPILIB website that tells how to use the Arm Feedforward.

3 Likes

Here is the link to the ArmBot code. We are using CAN Spark Max and the built-in encoder. We are using the RelativeEncoder in our code.

ArmBot

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.