1function J_manipulator_spatial = calculateManipulatorJacobian(num_joints, g_joints_home, bodyTwists)
 2%#codegen
 3
 4% g_joints_home are the homogeneous transformations from the base frame Fb to the
 5% frame of joint i at home position Fi(q_i=0)
 6% bodyTwists is the 6xn-1 matrix of n-1 column vectors respresenting the body
 7% joint twists of each joint, i.e. defining the local (body) axis of translation
 8% (prismatic) or local (body) axis of rotation (revolute) of the joint
 9
10
11J_manipulator_spatial = zeros(6,num_joints);
12
13for i = 1:num_joints
14    Ad_joints_home = calculateAdjoint(g_joints_home(:,:,i));
15    J_manipulator_spatial(:,i) = Ad_joints_home*bodyTwists(:,i);
16end
17
18end