turtlebot not moving for send velocity command

11 views (last 30 days)
naria
naria on 31 Jan 2020
Edited: Geoff Hayes on 31 Jan 2020
i am running following code on matlab 2017 to run turtlebot2 (ubuntu 14 , ros indigo). iusing followign code i can easily plot laser scan data 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). and program terminates succefully. but it doe snot moves turtlebot even a single inch. here is my code can any body tell what is worng with it.
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);
%Create a publisher for the /mobile_base/commands/velocity topic and the corresponding message containing the velocity values.
velpub = rospublisher('/mobile_base/commands/velocity') ;
odom = rossubscriber('/odom');
imsubR = rossubscriber('/camera/rgb/image_raw');
laser = rossubscriber('/scan');
%Wait for the subscriber to return data, then extract the data and assign it to variables x, y, and z:
pause(0.7);
%Receive Scan Data
scan = receive(laser,3);
figure
plot(scan);
%Create a subscriber for the odometry messages
odom = rossubscriber('/odom');
velmsg = rosmessage(velpub)
odomdata = receive(odom,3);
pose = odomdata.Pose.Pose;
%Wait for the subscriber to return data, then extract the data and assign it to variables x, y, and z:
tic;
while toc < 10
scan = receive(laser,3);
plot(scan);
end
rostopic info /mobile_base/commands/velocity
%Simple Obstacle Avoidance
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
% Collect information from laser scan
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);
% Compute distance of the closest obstacle
dist = sqrt(x.^2 + y.^2);
minDist = min(dist);
% Command robot action
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 using showdetails(velmsg) , 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

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by