# How to calculate potential enegy of manipulator dynamics?

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 ?

We have the position of the COM of the $$i_{th}$$ link with respect to the $$(i-1)_{th}$$ frame (or joint). Also, the homogeneous transformation matrix relating the $$(i-1)_{th}$$ frame to the $$0_{th}$$ frame is known from the DH parameters. We simply multiply them in order get the transformation matrix of the $$i_{th}$$ link's COM w.r.t to $$0_{th}$$ frame. The $$3rd$$ element of the $$4th$$ column of the resultant matrix is the height of the COM from the ground.
In your case it's the same. So what you have indicated as $$r_{c,i}$$, corresponds to the distance between the center of mass of each robot link and this zero potential energy plane. Generally, there is one potential energy associated with each actuator, and this helps you to calculate the torque that each actuator needs to apply to keep the robot in an static position, that doesn't coincide with the zero potential energy plane.