ros can't receive the message of 'nav_msgs/Path'
8 views (last 30 days)
Show older comments
Yi Liu
on 4 Jul 2022
Commented: Cam Salzberger
on 4 Aug 2022
the version of MATLAB is R2021A, and I use the ros topic of MATLAB to publish the message to ros node of rviz,both run on Ubuntu.
The problem is that rviz cannot receive the message of "nav_msgs/Path" published by MATLAB, but it can receive the message of "sensor_msgs/JointState" .
Here is the whole program
r = rosrate(30);
joint_name={'joint1_1','joint1_2','joint1_3','joint1_4','joint1_5','joint1_6','joint1_7','joint2_1','joint2_2','joint2_3','joint2_4','joint2_5','joint2_6','joint2_7'};
joint_pub=rospublisher('/joint_states','sensor_msgs/JointState');
path_pub=rospublisher('/manipulator_path','nav_msgs/Path');
joint_msg=rosmessage(joint_pub);
path_msg=rosmessage(path_pub);
pos_msg=rosmessage('geometry_msgs/PoseStamped');
pos_msg.Header.FrameId='base_link';
path_msg.Header.FrameId='base_link';
joint_msg.Name=joint_name;
reset(r);
for i=1:N
pos_msg.Header.Stamp=rostime('now');
pos_msg.Pose.Position.X=(pos(1,4)); %pos(1,4) is a double
pos_msg.Pose.Position.Y=(pos(2,4));
pos_msg.Pose.Position.Z=(pos(3,4));
path_msg.Header.Stamp=rostime('now');
path_msg.Poses(i)=pos_msg;
send(path_pub,path_msg); %This part doesn't work
joint_msg.Header.Stamp=rostime('now');
joint_msg.Position=qq';
send(joint_pub,joint_msg); %This part can work
waitfor(r);
end
I found it can work when I use MATLAB subscriber receive the message of "nav_msgs/Path" published by c++,and publish the received message to rviz, That makes me confused
1 Comment
Jagadeesh Konakalla
on 4 Jul 2022
Hi Yi Liu,
What version of MATLAB that you are using ? What the distribution that your ROS network is using ?
Are you saying that path_msg sent by MATLAB is not received by your ROS network ? Is the issue only with this specific message ? Or any messages from MATLAB are not received by ROS network.
Please provide detailed description of your issues.
Thanks,
Jagadeesh K.
Accepted Answer
Jagadeesh Konakalla
on 4 Jul 2022
Hi Yi Liu,
The issue is that nav_msg/Path is a variable length nested ROS message. In your example, Looks like that written M code is wrong. You need to completely fill the variable length Poses field before publishing. i.e move the Send function to outside of the for loop.
Please follow the below example to learn how to publish these kind of messages.
https://www.mathworks.com/help/ros/ug/publish-variable-length-nested-ros-messages.html
Let me know if this does not work for you.
Thanks,
Jagadeesh K.
2 Comments
Cam Salzberger
on 4 Aug 2022
I can't really think of anything in geometry_msgs/PoseStamped that could cause this issue, that would be resolved by saving and loading the joint state message to/from a MAT file.
The one thing that is odd is how you are building the nav_msgs/Path message sequentially, but sending it after each setting. As in:
i=1 -> path_msg.Poses = 1x1 array -> send
i=2 -> path_msg.Poses = 2x1 array -> send (first pose still there)
etc...
It would make more sense to me to build the Path message within the for loop, but only send it afterwards.
Also, when you say something "doesn't work", it helps to get more details. Is there an error? Is no message received? Is a message received but the data seems incorrect? That kind of thing.
-Cam
More Answers (0)
See Also
Categories
Find more on Specialized Messages in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!