% [sol,near,far] = solve(TrelS,TrelW,SrelB,current) is a function which
% computes the inverse kinematics like invkin(), but now it accepts
% the desired pose of the {TOOL} frame relative to the {STATION} frame,
% matrix TrelS, also (like "where") it accepts the tool and station frame
% offsets TrelW and SrelB (in matrix form).  The "current" joint angles are
% also specified, just like invkin().  The solution flag "sol" and the
% joint angle solutions "near" and "far" follow exactly the same guidelines 
% as for the "invkin()" function.  Function "solve" extracts WrelB using a
% transform equation, then calls function "invkin."

function [sol,near,far] = solve(TrelS,TrelW,SrelB,current)

WrelB = SrelB*TrelS*inv(TrelW); % Compute desired {WRIST} rel to {BASE}

[sol,near,far] = invkin(WrelB,current); % Find joint angle solutions