Estimate the peak and rated torque a joint needs from the robot’s mass and geometry. The working is shown under the result.
The legged-robot case follows Sizing joint torque for a legged robot. The arm case adds the torque to accelerate the payload and the link, treating each as a point mass. Check speed and heat as well: How to choose a robot joint actuator.