MATLAB Answers

ROS action client sendGoalAndWait error: Java exception occurred: java.lang.​​NullPoint​e​rExcepti​on

1 view (last 30 days)
Ben Lu
Ben Lu on 21 Jan 2018
Edited: Ben Lu on 17 May 2018
My ROS and matlab are both in Ubuntu system. I'm learning sending action goal messages to ROS by matlab. I run example: "Send and Cancel ROS Action Goals" in matlab, but error occurred. It showed "Java exception occurred: java.lang.NullPointerException". I don't know how to solve this problem. So thanks for who can help me.
-----------------------------------------------------------------------------------------------------------------------

Answers (1)

Ivan Belyaev
Ivan Belyaev on 16 May 2018
Edited: Ivan Belyaev on 16 May 2018
Dear Matlab, I have exact the same problem as Ben Lu except that I use FollowJointTrajectory. I have suspicion that some Java or Matlab ROS update destroyed actionclient in matlab. I tried the simple example from https://de.mathworks.com/help/robotics/ref/sendgoal.html. That works fluently, but with the code below it does not work.
Im working on mac 10.12.6 and have R2017b. Same problem had workmate with windows 10 and R2018.
On sendGoal(youbotClient,youbotGoalMsgs) it throws this:
Here is listing of my matlab program
function kuka_simulink_ros_action
global youbotClient youbotGoalMsgs;
[youbotClient,youbotGoalMsgs] = rosactionclient('/moveit/arm_controller/follow_joint_trajectory', 'control_msgs/FollowJointTrajectory');
waitForServer(youbotClient);
youbotGoalMsgs.Trajectory.JointNames = {'arm_joint_1','arm_joint_2','arm_joint_3','arm_joint_4','arm_joint_5','virtual_theta', 'virtual_x','virtual_y'};
youbotGoalMsgs.GoalTimeTolerance = rosduration(0,500000000);
points = rosmessage('trajectory_msgs/JointTrajectoryPoint');
trajectory = evalin('base', 'youbotTrajectory');
trj = trajectory.Data;
for i=1:length(trajectory.Data)
points(i) = rosmessage('trajectory_msgs/JointTrajectoryPoint');
points(i).Positions = [trj(i,4),trj(i,5),trj(i,6),trj(i,7),trj(i,8),trj(i,1),trj(i,2),trj(i,3)];
points(i).Velocities = [0,0,0,0,0,0,0,0];
points(i).Accelerations = [0,0,0,0,0,0,0,0];
points(i).TimeFromStart = rosduration(trajectory.Time(i));
end
youbotGoalMsgs.Trajectory.Points = points;
sendGoal(youbotClient,youbotGoalMsgs);
%delete(youbotClient);
end
PS One month ago exact the same code did worked!

  1 Comment

Ben Lu
Ben Lu on 17 May 2018
Hello @Ivan Belyaev, I have solved my issue. This is my solution writed in a Chinese blog Matlab generate ROS action message type from ROS packages . You should generate ROS action message that will be used in matlab by yourself from your ROS packages.
2. Compile your packages in ROS, you will find .msg file, I find the action message generated by matlab was based on these .msg file and package.xml file;
3. Create your message refer to Create Custom Messages from ROS Package

Sign in to comment.

Sign in to answer this question.