How can I rig a cylinder so that when it's rotated its end cap will not penetrate the floor?
There is no need for complicated trigonometry or drivers. You can do this with constraints.
Constraints are faster than drivers and have no security problems (manual).



The Cylinder Rig

Create the following bones. (Side view. Note, that the orientations of the bones are all the same.)



CTRL_cylinder has no parent or child. The other bones are in the following hierarchy:
floorRotation &gt; orientation &gt; DEF_cylinder &gt; Cylinder (object)


Add a Copy Rotation constraint from CTRL_cylinder to DEF_cylinder.
Add a Copy Rotation constraint from CTRL_cylinder to orientation.





Add a Locked Track constraint to orientation. The Target is CTRL_cylinder, with Head/Tail at 1. Set the To field to -Z and Lock Y.





Add a Copy Location constraint from CTRL_cylinder to floorRotation.
Add a Locked Track constraint from CTRL_cylinder to floorRotation.
Yet again, Head/Tail is at 1. Set the To field to Y and Lock Z.




I suggest the rotation order YZX for CTRL_cylinder. Add a crazy control shape for CTRL_cylinder and set it to be displayed At DEF_cylinder. The animator can move, rotate and roll the cylinder. Optionally, the Y axis can be locked, if no twisting is desired.





BONUS CONTENT

Two Axis (Rocker) Setup

This is useful for objects with two or more pivots, like feet, chairs, ... or a cube.


Create the following setup. The CTRL_cube is not in the hierarchy. The other bones are parented as such:
y_copy &gt; frontPivot &gt; backPivot &gt; DEF_cube &gt; Cube (object)

The rotation order of CTRL_cube is XYZ with Z locked.  


Add a Copy Location constraint from CTRL_cube to y_copy.
Add a Copy Rotation constraint from CTRL_cube to y_copy with only Y checked and Local Space for Target and Owner.


Add a Copy Rotation constraint from the CTRL_cube to frontPivot.
Add a Copy Rotation constraint from the CTRL_cube to backPivot.


Finally, limit the rotation of the frontPivot, to prevent the cube from going under the floor.


Add a Limit Rotation constraint to the frontPivot in Local Space, For Transform and with the X Limits 0 and 90.




The result can be moved rotated and rocked from front to back. With additional pivots and their respective Limit Rotation constraints any number of edges can be available for rocking.


Added a stylisch Bone Shape for CTRL_cube At DEF_Cube.