So in my lab, I am to create a rigid body tree robot that has an end effector that can be teleoperated by keyboard commands. I found a function called waitforbuttonpress that allowed me to give the user the ability to select a specific keyboard key and then use that key to change the position vector to a different value. I placed the inverse kinematics solver inside of the function below because I believed that the function would solve the new angle joints based off of every time the position of the end effector changed, though for some reason I am getting some error in the inverse kinematics solver saying: Error using trvec2tform Expected t to be an array with number of columns equal to 3. I am using the home configuration of the robot as input for the kinematic solver function. Any advice is welcome below is the entire code of both the rigid body system as well as the kinematic solver function.
pbot = robotics.RigidBodyTree('DataFormat','column','MaxNumBodies',2); body1 = robotics.RigidBody('body1'); joint1 = robotics.Joint('jnt1','revolute'); joint1.JointAxis = [1 1 1]; setFixedTransform(joint1,trvec2tform([0 0 2])); body1.Joint = joint1; addBody(pbot,body1,'base') s0 = homeConfiguration(pbot); weights = [0, 0, 0, 1, 1, 1]; ik = robotics.InverseKinematics('RigidBodyTree',pbot); sInitial = s0; disp(body1) keyboard_move(s0); show(pbot) function keyboard_move(x) k = waitforbuttonpress; p = get(gcf, 'CurrentCharacter'); while p ~= 'q' if p == 'a' x = x + [0 -.1 .1]; k = waitforbuttonpress; p = get(gcf, 'CurrentCharacter'); elseif p == 's' x = x + [-.1 0 .1]; k = waitforbuttonpress; p = get(gcf, 'CurrentCharacter'); elseif p == 'd' x = x + [0 .1 .1]; k = waitforbuttonpress; p = get(gcf, 'CurrentCharacter'); elseif p == 'w' x = x + [.1 0 .1]; k = waitforbuttonpress; p = get(gcf, 'CurrentCharacter'); else fprintf("Please enter a correct key: 'a', 's', 'd', 'w'") end mover = ik('body1',trvec2tform([0 0 1 + x]), weights, s0); sInitial = mover; end end end