Main Content

Move the Robot Using ROS Action

Execute the following set of commands to control the robot using joint trajectory controller’s action interface. Using this interface, you can command the robot to move to desired joint configuration and also get the feedback from the robot regarding execution of the desired command.

[trajAct,trajGoal] = rosactionclient('/pos_joint_traj_controller/follow_joint_trajectory'); 

trajAct.FeedbackFcn = []; 

waitForServer(trajAct); 

jointWaypointTimes = 3; 

jointWaypoints = [0 0 0 0 0 0]'*pi/180; 

numJoints = size(jointWaypoints,1); 

 

trajGoal.Trajectory.JointNames = {'elbow_joint','shoulder_lift_joint','shoulder_pan_joint','wrist_1_joint','wrist_2_joint','wrist_3_joint'}; 

 

for idx = 1:numJoints 

trajGoal.GoalTolerance(idx) = rosmessage('control_msgs/JointTolerance'); 

trajGoal.GoalTolerance(idx).Name = trajGoal.Trajectory.JointNames{idx}; 

trajGoal.GoalTolerance(idx).Position = 0; 

trajGoal.GoalTolerance(idx).Velocity = 0.1; 

trajGoal.GoalTolerance(idx).Acceleration = 0.1; 

end 

 
trajPts = rosmessage('trajectory_msgs/JointTrajectoryPoint'); 

trajPts.TimeFromStart = rosduration(jointWaypointTimes); 

trajPts.Positions = jointWaypoints; 

trajPts.Velocities = zeros(size(jointWaypoints)); 

trajPts.Accelerations = zeros(size(jointWaypoints)); 

trajPts.Effort = zeros(size(jointWaypoints)); 

 
trajGoal.Trajectory.Points = trajPts; 


resultState = sendGoalAndWait(trajAct,trajGoal); 

 

If the detailed control of intermediate trajectory is also required, then you can use the velocity and acceleration field of the trajectory_msgs/JointTrajectoryPoint. Refer to a similar workflow for Kinova Gen3 for more details.