turtlebot3 can't receive message from matlab, but matlab can get data from turtlebot

13 visualizaciones (últimos 30 días)
I use matlab to control my turtlebot, there is something wrong with communication.
Rossubscriber can work sucessfully, matlab can get data from bot correctly, from topics like /scan , /cmd_vel
But rospublisher cannot work.
I tried rospublisher() and send() to send msg to /cmd_vel,
and /cmd_vel is always linear: x: 0.0 y: 0.0 z: 0.0
However, I can make the bot move by terminal via ssh into the board on the turtlebot
both
rostopic pub -r 10 /cmd_vel geometry_msgs/Twist '{linear: {x: 0.1, y: 0, z: 0}, angular: {x: 0, y: 0, z: 0}}'
and
roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
can work,
so the hardware does not have problems.
Here are my Settings.
In ubuntu of turtlebot, .bashrc
export ROS_IP=192.168.1.101
export ROS_MASTER_URI=http://192.168.1.101:11311
export ROS_HOSTNAME=192.168.1.101
In matlab
rosshutdown;
setenv('ROS_IP','192.168.1.108')
setenv('ROS_MASTER_URI','http://192.168.1.101:11311')
ipaddress = "http://192.168.1.101:11311" ;
rosinit(ipaddress)
code to move the bot
cmd_publish = rospublisher("/cmd_vel","DataFormat","struct") ;
velMsg = rosmessage(cmd_publish);
velMsg.Linear.X = 0.1;
send(cmd_publish,velMsg)
another attempt
velocity=0.1;
robot = rospublisher("/cmd_vel",'geometry_msgs/Twist')
velmsg = rosmessage(robot)
velmsg.Linear.X = velocity;
send(robot,velmsg)
Neither echo nor rospublisher can find any change in /cmd_vel
I don't understand why rospublisher can't work but rossubscriber can.
All help is appreciated.
Thank you in advance.

Respuesta aceptada

Cam Salzberger
Cam Salzberger el 25 de Mzo. de 2022
Hello Hengxing,
I've seen this kind of issue a few times, but usually in the reverse direction (MATLAB can't receive data). The fix there is to ensure ROS_IP is set correctly on the VM so that the correct endpoint of the communication is advertised when the node is started.
Since you are setting ROS_IP at both endpoints, and you shouldn't have to anyway on MATLAB's side, then that doesn't seem to be the issue here. The most likely explanation is that the firewall is blocking communication on certain ports that MATLAB is trying to use. Depending on your firewall program, you can set MATLAB (and maybe VMware) as a trusted program and allow communication through it.
If that isn't the issue, check that the IP addresses you are using are actually correct. There are usually multiple network interfaces, each with their own IP addresses. You usually want the standard ethernet or wireless network, not the VM-communication-specific interfaces. You can see your network interfaces in Windows with ipconfig or Unix systems with ifconfig.
-Cam
  2 comentarios
Hengxing Zhao
Hengxing Zhao el 25 de Mzo. de 2022
Hello Cam,
I have read the link you mentioned above.
At first, I didn't set the ROS_IP on MATLAB's side. Then I find that some answers in the community which mention it. so I tried it.
I do close the firewall of PC, and ping is running successfully on both sides.
Could it be a firewall on ubuntu that receive ping but refuse matlab?
I'm using a real turtlebot now, so there is no problem with vmware.
As for the ip, I've bound the IP to the MAC address, so they are fixed. And I will check them everytime, so it will be all right.
Thank you for your answer very much, but it doesn't seem to be the problem.
Are there more other possibilities?
Cam Salzberger
Cam Salzberger el 28 de Mzo. de 2022
Being able to ping in both directions doesn't usually mean a lot in terms of ROS communication. If you can't ping, you probably can't communicate over ROS. But there are a lot of situations where ping works but ROS communication doesn't.
It's always possible that Ubuntu has some kind of security or port-blocking measure that is preventing this communication, but I've not heard of that being an issue before.
Further investigation is probably going to be along the lines of testing variables to try to narrow down on the cause. Off the top of my head, you could try:
  • Ensure pub-sub works with two different nodes (ros.Node objects) within MATLAB.
  • Ensure pub-sub works between two separate MATLAB instances.
  • If you have another computer with MATLAB installed, hook it up to the same network that you are using with the TurtleBot, and ensure pub-sub works between those computers in both directions.
  • Is the ROS master on the TurtleBot or MATLAB? Can you try starting the master on the other one and connect both to it?
  • Are you using a direct wired connection, a LAN, a general (wired) internet connection, a dedicated wireless network (no internet access), or a general wireless network (with internet) for this communication? Sometimes general networks come with additional configuration or security that impedes ROS communication (like disabling multicast). I've usually experimented with a dedicated wireless network that basically just has the laptop and the turtlebot as the only things on the network.
  • Is the computer connected to any other networks (ethernet or wireless)? Consider removing them and then restarting MATLAB/ROS/etc. It could be that it is attempting to communicate on a different network interface.
  • Do you have ROS installed to the computer (outside of MATLAB)? Can you send communication from that to the TurtleBot?
-Cam

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Network Connection and Exploration en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by