I have created a 6-DOF robot using RigidBodyTree() method and modified D-H parameters using robotics toolbox in MATLAB.
The modified DH parameters for the robot are as follows:

I have followed the example here: https://www.mathworks.com/help/robotics/ref/robotics.rigidbodytree-class.html#bvet6e8
To bring the robot to its actual home position (position of the real robot when encoder values read 0), I have to pass specific theta (DH Parameter) values: [0 -pi/2 0 0 0 pi].
However, there are discrepancies in the joint values for home position of robot created using DH parameters and that of the actual robot.
For actual robot and its simulators, passing a joints value of [0 0 0 0 0 0] gets to the home position.
The visulaization of robot created using robotics toolbox using DH parameters and that of the simulator are shown below:

This creates problems during inverse kinematics. For the same home position (4X4 transformation matrix), the joint angles are different for real robot simulator and robot created using modified DH parameters ([0 0 0 0 0 0] vs [0 -pi/2 0 0 0 pi]).
The DH parameter method ignores theta values when creating robot. How can I match the home configuration of the robot to the real robot?
outputAngles = rawOutputAngles + abs(initialThetas). It looks like just adding initialThetas doesn't match the simulator pose. I am guessing this has to do with -pi/2 ("negative" second joint angle) in the theta vector. I can't seem to find a logical explanation for this. Do you know why absolute value of angle result in correct pose? – Rock Jun 03 '19 at 22:55clampedAngle = rawAngle - floor(rawAngle/360)*360;If your angle were -10 degrees,floor(-10/360)becomes-1, so you wind up with-10 - (-1*360)or-10 + 360or 350. I'm not sure what you mean when you say joint 2 is "not a simple spherical joint" - do you mean not a revolute joint? If it's a prismatic joint then the theta value should be fixed, I believe; the distance d would vary. Regarding your absolute values issue, it might be a sign problem; tryoutputAngles = rawOutputAngles - initialThetasinstead. – Chuck Jun 05 '19 at 13:30