I'm trying to obtain dynamics of a 4 DOF robot. Firstly, I calculated all Transformation matrices and Jacobians. While solving Lagrangian there is two main things one is kinetic energy and the other is potential energy . The kinetic energy is simplified into D matrix and Coriolis's factor, which to find the gravitational factor in lagrangian method , we need to find the potential energy. My problem is in that potential energy which is equal to P=mgh . I don't know what does that h correspond to and how to find the value of h . Could some one help me solving this issue ?
h is a height relative to some arbitrary baseline. You can set it anywhere you want, but I think typically the easiest way to choose your baseline height is to set zero as the lowest reachable point for your robot. Then all heights are positive and you can have zero kinetic energy when speed is zero and zero potential energy when your arm is at its lowest point.
Based on your graphic, it looks like $F_1$, your first joint, is at the top, so you've drawn the arm with as low of a reach as it could have. That means the $h=0$ datum should be through the center of the bottom joint (or center of mass of the end effector, but you don't have a Frame 5 $F_5$ depicted):