I’m relatively new to programming robots in Java and am looking for some pointers on how to accomplish the following.
Our team wants to be able to do a few PID controlled tasks, mostly with the drive system. We are using a command based structure for our code. Essentially we want to be able to use a few different sensors for a few different tasks, they are as follows:
-Average encoders to drive straight and drive for a certain distance
-Use two ultrasonic sensors to turn the robot until its relatively parallel to a surface as well as drive until we are a certain distance away from a surface
-Utilize vision to turn towards a target
Now, the solutions I’ve seen so far here on CD are varied. One idea I saw was to create multiple PID loops within the drive subsystem. Another idea was to create separate dummy subsystems specifically for each PID task. I’m not quite sure what the best way to approach this problem is.
I’d suggest that the second of these ideas is more difficult/risky, with the potential for parallel commands sending conflicting drive-straight/rotate instructions.
The second idea just requires you to use conditions (eg if setpoint-is-angle, elseif setpoint-is-distance…) within your ChassisPIDSubsystem’s returnPIDInput() and usePIDOutput() and potentially within a custom-onTarget() too.
Okay, that makes sense. Would each different setpoint set require different values for the constants as well?
With this approach you need to limit drive-action to drive or rotate, not drive-curve, and this way the setpoint and the input-output values all need to be within one ‘dimension’ (at a time). (You might also want/need conditions for the strafe-dimension, if that is relevant to autonomous).
That not only makes sense, but works much better with what we’re trying to accomplish. The idea is to use all of these PID loops for autonomous gear placement, so it does make more sense to worry about one drive function at a time rather than multiple. We’re ditching the ultrasonic capability so now I only need to worry about turning with vision and driving straight for a set distance with encoders. Appreciate the help.