MATLAB Answers

I can't move the turtlebot3 with matlab and ros

20 views (last 30 days)
Ambroise MOCK
Ambroise MOCK on 29 May 2020
Commented: Cam Salzberger on 8 Jun 2020
Hello,
i have some weird trouble here with the turtlebot and hope somebody can help me find where i did wrong. Up until now I can't make the turtlebot move when I publish on /cmd_vel
PC with matlab : 192.168.43.76
Rpi : 192.168.43.215
On the Rpi of the turtlebot:
I did modify the ~/.bashrc :
export ROS_MASTER_URI=http//192.168.43.215:11311
export ROS_HOSTNAME=192.168.43.215
export ROS_IP=192.168.43.215
export TURTLEBOT3_MODEL=waffle_pi
then I did: source ~/.bashrc
Next on matlab I wrote:
rosshutdown
setenv('ROS_IP','192.168.43.76')
setenv('ROS_HOSTNAME','192.168.43.76')
setenv('ROS_MASTER_URI','http://192.168.43.215:11311/')
rosinit
So the weird thing are that when i write :
velocity = 1.0;
robot = rospublisher('/cmd_vel','geometry_msgs/Twist');
msg = rosmessage(robot);
msg.Linear.X= velocity;
send(robot,msg);
the robot doesn't move, although I have verified that the matlab is a publisher on /cmd_vel node on the RPi ( with the command rostopic info /cmd_vel), but i doesn't receive anything from the matlab ( I have also check with rostopic echo /cmd_vel)
I have already verify if the trouble was on the turtlebot but I can make the turtlebot move by using the command:
rostopic pub -1 /cmd_vel geometry_msgs/Twist --'[1.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'
but this time I try to check if I was seeing anything on the matlab by using rostopic('echo','/cmd_vel') but it doesn't show any modification of the topic on this either.
So I guess I have communication trouble between matlab and Rpi but I can't find where.
If anybody has an hint, you're more than welcome.
Thank you in advance community.

  0 Comments

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 29 May 2020
Edited: Cam Salzberger on 29 May 2020
Hello Ambroise,
There are a couple of things I noticed right off the bat that could be causing things to be weird:
export ROS_MASTER_URI=http//192.168.43.215:11311
I believe you have forgotten the colon between "http" and "//".
export ROS_HOSTNAME=192.168.43.215
export ROS_IP=192.168.43.215
Generally you should only set either the hostname or the IP address. The hostname will override the IP address if both are set. However, since you are trying to specify an IP address, then "ROS_IP" would be the more appropriate variable to set.
Also, I generally have not seen the ROS_MASTER_URI set before starting a roscore. ROS_IP is fine, I think, but the master generally selects its own IP and port number. Try removing the setting of ROS_MASTER_URI, and see if it automatically sets itself to the same address anyway. If it doesn't try updating the MATLAB code to target the correct address and test that.
setenv('ROS_IP','192.168.43.76')
setenv('ROS_HOSTNAME','192.168.43.76')
You should not need to set either ROS_HOSTNAME or ROS_IP in MATLAB. When you do "rosinit" or "ros.Node", these variables are set for you before spinning off the node. It shouldn't hurt, but it probably isn't necessary. If you do want to set something, just set the one variable.
setenv('ROS_MASTER_URI','http://192.168.43.215:11311/')
You've got an extra slash on the end of the address. Not sure it matters, but I've never seen it done that way before.
Other tips for diagnostics:
  • If you're using a VM or another machine, try to see if the message is getting through. Open a new terminal, set up the same Master target, run "rostopic echo /cmd_vel", and see if the MATLAB messages are received.
  • Check if you are receiving sensor messages from the robot in MATLAB. Sometimes if communications are only going one-way, it can indicate improper address or network settings.
  • After the turtlebot is started, can you see /cmd_vel advertised as an existing topic in MATLAB ("rostopic list").
  • Try roswtf from a Linux machine.
-Cam

  4 Comments

Show 1 older comment
Cam Salzberger
Cam Salzberger on 1 Jun 2020
Hmm, well it looks like it's not a problem, per se, to set ROS_MASTER_URI before running roscore, as that seems to be used if you want to specify the port it uses. But you should be able to get the address used by roscore from its display output (attached). However, I think it uses the hostname rather than the IP address by default. You can still get the IP address from ifconfig though.
What about the other diagnostics tips I suggested? What were the results of those?
-Cam
Ambroise MOCK
Ambroise MOCK on 6 Jun 2020
Hi,
I'm using another screen for the RPi so I did try to run the command 'rostopic echo /cmd_vel' in either matlab and the rpi while modifying the value on the other, but the data is not getting through by any way.
I checked if matlab was receiving data from the Rpi but except for '/scan' which seems to be receiving data matlab doesn't receive any modification on the topics .
I tried to use roswtf while connecting the matlab and while it was disconnected:
during the first one I received the following text:
WARNING The following node subscription are unconnected:
* /turtlbot3_core:
*/motor_power
*/sound
*/reset
*/cmd_vel
and when I run rosinit on matlab I received the same warning but with somes errors:
ERROR Could not contact the following nodes :
*/matlab_global_node_71068
ERROR the following nodes should be connected but aren't :
*/matlab_global_node_71068->/rosout(/rosout)
Thanks again.
A.M.
Cam Salzberger
Cam Salzberger on 8 Jun 2020
To make sure I'm understanding you correctly, you've tried:
  • Publishing /cmd_vel from TurtleBot and subscribing in MATLAB -> No communication
  • Publishing /cmd_vel from MATLAB and subscribing in TurtleBot -> No communication
  • Publishing /scan from TurtleBot and subscribing in MATLAB -> Communication works
That is odd. I'd normally expect to see any and all communication from one source to the other fail, not particular topics. There are two more things to explore that I can suggest:
  • I have seen firewalls be an issue in ROS networks before, blocking communication in either one or both directions. The ROS documentation has some tips for configuring your firewall, but use your best judgement and follow your organization's security guidelines (if applicable).
  • If the message definitions are different between two machines, the messages will be dropped when their MD5 checksum does not match. This shouldn't be the issue, as I don't believe geometry_msgs/Twist (I assume that's the message type for /cmd_vel) or its nested messages (geometry_msgs/Vector3) have changed since creation, but it's worth checking. Run this command on both MATLAB and TurtleBot, and make sure the value is the same:
rosmsg md5 geometry_msgs/Twist

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!