Main Content

Control Cartesian Pose Using MATLAB

This section helps you to manipulate the KINOVA® Gen3 7-DoF Ultralightweight Robot arm and achieve desired Cartesian pose using MATLAB®. Execute the following commands sequentially in the MATLAB to manipulate the robot. As explained in KINOVA github page, the first part of the ROS topic, 'my_gen3’ might be different based on the robot name set during the roslaunch command.

Read the current Cartesian pose of the robot.

baseSub = rossubscriber('/my_gen3/base_feedback');
baseMsg = baseSub.LatestMessage;

Set the offset in the current Cartesian pose. First three values corresponds to the offset in X, Y and Z positions respectively and are in meters. The last three values correspond to the offset in rotation angles with respect to X, Y and Z axis respectively and are in degrees.

offsets = [0.1 0.1 0.1 0 0 0];

Create a service client and an empty ROS message for the ROS service /my_gen3/base/play_cartesian_trajectory.

[cartTrajSrv,cartTrajMsg] = rossvcclient('/my_gen3/base/play_cartesian_trajectory');

Set the desired Cartesian pose using the existing pose and offsets.

cartTrajMsg.Input.TargetPose.X = baseMsg.Base.ToolPoseX + offsets(1);
cartTrajMsg.Input.TargetPose.Y = baseMsg.Base.ToolPoseY + offsets(2);
cartTrajMsg.Input.TargetPose.Z = baseMsg.Base.ToolPoseZ + offsets(3);
cartTrajMsg.Input.TargetPose.ThetaX = baseMsg.Base.ToolPoseThetaX + offsets(4);
cartTrajMsg.Input.TargetPose.ThetaY = baseMsg.Base.ToolPoseThetaY + offsets(5);
cartTrajMsg.Input.TargetPose.ThetaZ = baseMsg.Base.ToolPoseThetaZ + offsets(6);

Set the velocity constraints on the translation speed and rotational speed.

speedConstraint = rosmessage('kortex_driver/CartesianSpeed');
speedConstraint.Translation = 0.5; % m/s
speedConstraint.Orientation = 45;  % deg/s
cartTrajMsg.Input.Constraint.OneofType.Speed = speedConstraint;

Call the service to move the robot.

call(cartTrajSrv,cartTrajMsg);