Turtlebot not moving by getting velocity commands from MATLAB

asked 2020-01-31 20:09:40 -0500

noor gravatar image

updated 2020-01-31 20:11:03 -0500


i am also facing the similar problem discussed in turtlebot wont move link. but i have tested it by disabling my firewall even, still i am facing same problem. i am running following code on matlab 2017 to run turtlebot2 (ubuntu 14 , ros indigo).

Program runs successfully. but it does not moves turtlebot even a single inch. ROS and matlab both machines can ping each other, can display rostopic list. matlab program is perfectly plotting laser scan data and/or image data received form ubuntu ros machine on my matlab machine. and my code also displays 'move forward' or move backword' message depending upon the object distance in front of the turtlebot 3d sensor (ros astra pro). but turtlebot does not moves and neither shows any error.

i am using following code on ros machine side

$roslaunch turtlebot_bringup minimal.launch    
$source devel/setup.bash 
$rosrun astra_camera create_udev_rules 
$roslaunch astra_launch astra_pro.launch
$rosrun depthimage_to_laserscan depthimage_to_laserscan image:=/camera/depth/image_raw
$roslaunch turtlebot_teleop keyboard_teleop.launch  
$roslaunch turtlebot_navigation gmapping_demo.launch
$roslaunch turtlebot_rviz_launchers view_navigation.launch

i am using following code on matlab side

ipaddress = ''; 
ros_ip = ''; 
velpub = rospublisher('/mobile_base/commands/velocity') ;
odom = rossubscriber('/odom');
imsubR = rossubscriber('/camera/rgb/image_raw');
laser = rossubscriber('/scan');
scan = receive(laser,3);
 figure, plot(scan);
 odom = rossubscriber('/odom');
  velmsg = rosmessage(velpub)
  odomdata = receive(odom,3);
  pose = odomdata.Pose.Pose;

while toc < 10
  scan = receive(laser,3);

rostopic info /mobile_base/commands/velocity
spinVelocity = 0.6;       % Angular velocity (rad/s)
forwardVelocity = 0.1;    % Linear velocity (m/s)
backwardVelocity = -0.02; % Linear velocity (reverse) (m/s)
distanceThreshold = 0.3;  % Distance threshold (m) for turning
  while toc < 5
  scan = receive(laser,2);
  if isempty(scan) 
      disp 'laser data not received or out of sensor range (distance too short or too high)';      
            data = readCartesian(scan);      
              x = data(:,1);
              y = data(:,2);              
                  dist = sqrt(x.^2 + y.^2);
                  minDist = min(dist);                    
                  if minDist < distanceThreshold 
                      % If close to obstacle, back up slightly and spin
                      velmsg.Angular.Z = spinVelocity;
                      velmsg.Linear.X = backwardVelocity;
                      disp 'move back';                      
                      % Continue on forward path
                      velmsg.Linear.X = forwardVelocity;
                      velmsg.Angular.Z = 0;
                      disp 'move forward';                      

end rosshutdown

and when i print my variables data on matlab , i get

velmsg = ROS Twist message with properties: MessageType: 'geometry_msgs/Twist' 
Linear: [1×1 Vector3] Angular: [1×1 Vector3] Linear
X : 0.1, Y : 0, Z : 0 Angular
X : 0, Y : 0, Z : 0
edit retag flag offensive close merge delete