Cap a beveled curve with a half-circle
You can do this with an array modifier and a curve modifier.

Similar to this post:

How to avoid objects intersecting eachother

Make 2 pieces, a straight section and the end one, and a curve to control the way the array curves and twists.



Move the main piece so that the object and the curve have their origins on the same spot.



Use an array modifier, set it to use the curve.



Then add a curve modifier, so that the array follows the curve.

In the array modifier you can set Start and End caps. Set the end to use the endcap object.