Flywheel PID Programming for dummies

We have a pretty decent bot, making almost 100 points on skills. Using a horizontal dual-flywheel launcher. it is very well built, but we have no shaft encoders/IME programming. We now have a shaft encoder linked to a gear going as fast as the motors.

Can someone explain to me how to program a PID loop for this?

If you’re running Robot C 4.X, Robot C has a built in Library for this. Input the motor into the motors and sensors input, and then assign it an encoder using the encoder ports. Then enable PID by clicking the PID check box. You can then assign the motor a speed (0-100).

``````
#pragma config(Motor,  port1,           Left,          tmotorVex393_HBridge, PIDControl, driveLeft, encoderPort, dgtl1)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

{

nMotorPIDSpeedCtrl[port1] = 100;

}

``````

If you are interested in the above method, jpearman has made a very good thread about the in built PID on RobotC, which also covers why the motors can only be assigned a value from 0-100 as well as explaining the use of the function SlaveMotor and how to edit PID settings.

The launcher has 4 motors, on ports 3,4,6,7
And all we have are quadrature shaft encoders.
Will this still work? Im sincerely confused about these pid loops. Ill post a picture of the robot tomorrow.

Hey man! The key for PI control on your flywheel is figuring out how many ticks of your encoder u want for a set period of a time. You’re gonna take the error in your velocity and multiply it by a gain (u gotta tune that though) and that’ll give you your power. RobotC has velocity control however, you may want to look into that.habe fun! If you need any more help we’re close by

The RobotC PID only works with IMEs. I would suggest jpearman’s I control TBH as a quick and easy control.

We’re using bang-bang right now; I need to play around with other stuff more.

is there any way to loophole a shaft encoder to work as an IME?

@Scarr what are you guys using? maybe we can tailor it to our robot? send me a private message please, we need this code for bradenton saturday!

I personally have found figuring out the code yourself is an immense learning experience and how I’ve come to understand programming more and more. I’m here if you need me to help you but I personally feel you would be best off searching around the different threads on the forum and figuring it out. Trust me, you’ll be glad you did!

@Scarr i would love to keep researching and learning myself but we have a very limited time frame and need this program in three days. It would be very helpful and possibly our beat chance at states.