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

Hi,

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

$roscore
$roslaunch turtlebot_bringup minimal.launch    
$catkin_make 
$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

IP_OF_HOST_COMPUTER = '192.168.10.13'; 
ipaddress = 'http://192.168.10.13:11311'; 
ros_ip = '192.168.10.8'; 
setenv('ROS_MASTER_URI',ipaddress);
setenv('ROS_IP',ros_ip);
rosinit(ipaddress,'NodeHost',IP_OF_HOST_COMPUTER);
velpub = rospublisher('/mobile_base/commands/velocity') ;
odom = rossubscriber('/odom');
imsubR = rossubscriber('/camera/rgb/image_raw');
laser = rossubscriber('/scan');
pause(0.7);
scan = receive(laser,3);
 figure, plot(scan);
 odom = rossubscriber('/odom');
  velmsg = rosmessage(velpub)
  odomdata = receive(odom,3);
  pose = odomdata.Pose.Pose;
tic;

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

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
tic;    
  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)';      
  else
            plot(scan);
            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';                      
                  else
                      % Continue on forward path
                      velmsg.Linear.X = forwardVelocity;
                      velmsg.Angular.Z = 0;
                      disp 'move forward';                      
                  end   
                    send(velpub,velmsg);
                    pause(0.1);
  end

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