I am trying to at a PID controller to our single-flywheel shooter, but I do not know exactly what I’m doing and cant quite get it to work so any help would be appreciated. This is all I have so far.
float k = .02;
int desired = 400;
SensorValue(wheelen) = 0;
wheel = SensorValue(wheelen);
It looks like you have made a positional P loop instead.
If you are trying to make it move at a certain speed, you have to calculate velocity and then compare it to a target. I think you tried to do it with the “speed” variable but I don’t see where you set its value. Hope this helps.
You could also just use a bang-bang controller. It worked very well for our kids during NBN.
You can modify it somewhat to have the bottom be > 0. So, for instance, check your speed, if it is less than you want then set the output to 127. If it is more than what you want set it to 50. repeat this every 20ms.
The 20 ms is important on the Cortex because of delays in the actual requesting value getting sent out to the motors.
The value of 50 is experimental. It depends a bit on your friction and such, but you want it low enough that your flywheel will not be increasing speed any longer, but high enough that it doesn’t decrease speed to quickly.
The value of 127 is probably ok, but is experimental to some degree. Sometimes you want two values, the value of 127 until the flywheel first crosses the requested speed, then a second value when it is holding speed.
I think you can just use a PID controller @TriDragon to check speed and the error. This will adjust real time without any delay. It seems a bang-bang controller will not be as accurate as these value are estimations. The robot will be doing all of the calculations for adjusting the speed.
There is plenty of delay in a PID, it may be real time in checking and update (20ms), but it will have phase lag due to the equations. And for the OP, new to PID, tuning and such will take a good bit of time. You need a lot of gain in the PID to get the response time of resolving speed after each shot. You also need good sensors for a derivative, and the resolution of the sensors for the Cortex systems is fairly poor. For NBN, there was very little time between shots, << 1sec, so it needed very quick response. If this game can take a few seconds to recover then PI will work fine.
Yes, but simply using the ziegler nichols method one can very easily calibrate the PIDs and the bang-bang method results in a lot of variation. So long as you have a negative integral, small derivative, and large proportion then there will be quick adjustments. Also, the equations are being computed by the brain, so the lag time is very very small.
Yes, it’s a good start, but real PID control generally requires more than just that type of tuning for good results…
It results in a lot of jumping around of the commanded power, but not of the overall system. Mechanical inertia, as well as, electrical response time smooths that out.
I really hope you don’t have a negative integral…
I am assuming the brain has the power to do the equations, although bang-bang taxes the processor much less. The lag has nothing to do with the brain, it is inherent in the controls equations and their gains.
The negative integral helps the derivative. It is popularly used in gyroscope PID coding. The ziegler nichols method is a mathematical model proved for tuning PIDs, so it is extremely accurate. In fact, I was able to tune our chassis within 15 minutes. I would also just be very weary about using the bang-bang method. Motors will be taxed and damage them permanently.