How Do I Use Subscriber Block to Get Messages from a ROS Node Running in Linux?

Below is the code that generates geometry_msgs::Point messages.
#include "ros/ros.h"
#include "geometry_msgs/Point.h"
#include <cmath>
int main(int argc, char **argv)
{
ros::init(argc, argv, "sinewaves_generator");
ros::NodeHandle n;
ros::Publisher wave_pub = n.advertise<geometry_msgs::Point>("/location", 1000);
ros::Rate loop_rate(100);
long count = 0;
while (ros::ok())
{
geometry_msgs::Point msg;
double time = (double)count / 100.;
msg.x = sin(time - M_PI / 2.);
msg.y = sin(time);
ROS_INFO("%f, %f", msg.x, msg.y);
wave_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
The roscore is running at a Ubuntu host, and the publisher is running at a Ubuntu host. The subscriber model is running on windows with network access specified to the Ubuntu host as instructed here: http://www.mathworks.com/help/robotics/ug/configure-ros-network-addresses.html
Both the publisher and the subscriber run, but the subscriber doesn't get x and y values.

답변 (1개)

Sebastian Castro
Sebastian Castro 2015년 7월 14일
편집: Sebastian Castro 2015년 7월 14일
It should work, as geometry_msgs/Point is definitely a supported message type in Robotics System Toolbox.
First thing I would do is try ping the machine by issuing a system command from MATLAB (!) and using the IP address of the Ubuntu node.
!ping 192.168.182.138 %(For example)
Next, I would run "rosinit" in MATLAB and check that the /location topic exists:
rostopic list
If it does, and you try subscribe in MATLAB as follows, does "msg" ever become a non-empty message?
sub = rossubscriber('/location');
msg = sub.LatestMessage; %(or msg = receive(sub))
- Sebastian

댓글 수: 2

Hello Sebastian,
I am able to ping the ros master host. Then I used
rosinit(hostIP).
Then I followed the commands you listed and
msg = sub.LatestMessage
gives me
msg =
0x1 ROS Point message array with properties:
MessageType
X
Y
Z
But the subscriber model still doesn't work.
Thanks, Brian
Yeah, the fact that you're seeing a 0x1 message means that nothing is being received on the MATLAB side.
How certain are you that your C++ node works fine? You could try do a "rostopic echo /location" in a Terminal on the Ubuntu side to see if anything is happening on the publisher side.
Then, you can enter the same command and then in MATLAB itself to see if anything is coming in.
If you see message on the Ubuntu side and not on the MATLAB/Windows side, then there might be some networking issues. Do you have a firewall or anything set up? You could also try a different port besides the default one when you do "rosinit".
- Sebastian

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Network Connection and Exploration에 대해 자세히 알아보기

질문:

2015년 7월 13일

댓글:

2015년 7월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by