decided to give it a go, here is a video of me figuring it out. ( first watch the above up vector video)
and here is the file: https://www.dropbox.com/s/j8utemifrx1pqgb/mech_arm_ik_0001.c4d?dl=1
you might want to play around with how the end is attached, can't say im thrilled with the current way. but it's just a matter of picking the right up vectors.