% TrelS = where(theta,TrelW,SrelB)  This function computes the pose (in 
% "internal" form) of the {TOOL} frame relative to the {STATION} frame.
% The function also accepts the transforms (in "internal" form) of the
% {TOOL} frame relative to the {WRIST} frame (TrelW, the "tool offset"),
% and the transform of the {STATION} frame relate to the {BASE} frame
% (SrelB, the "station frame offset"). Note that function where() will 
% call function kin().

function TrelS = where(theta,TrelW,SrelB)

WrelB = kin(theta); % Use forward kin to get {W} relative to {B}.

TrelS = inv(SrelB)*WrelB*TrelW; % Use transform equation to solve.