ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to make a robot rotate pi/2 accurately by ROS I/O Package

asked 2015-03-25 09:47:37 -0600

ziyeshanwai gravatar image

Hey!guys,I have a problem with gazebo.I do as then I setup ROS I/O Package( is OK.I can make Husky move forward and rotate.However I can't make it rotate pi/2 or other angles accurately .Following is my matalb code

clear all;
global msg;
global msgLin;
global msgAng;
global msg2;
global msgLin2;
global msgAng2;
global msg3;
global msgLin3;
global msgAng3;
global publisher;
global publisher2;
global publisher3;
global subscriber;
global subscriber2;
global subscriber3;
rosMasterIp = '';localhostIp = '';
node = rosmatlab.node('Node', rosMasterIp, 11311, 'rosIP', localhostIp);
node2 = rosmatlab.node('Node2', rosMasterIp, 11311, 'rosIP', localhostIp);
node3 = rosmatlab.node('Node3', rosMasterIp, 11311, 'rosIP', localhostIp);
msgLin = rosmatlab.message('geometry_msgs/Vector3', node);%creart message type
msg = rosmatlab.message('geometry_msgs/Twist', node);
msgAng = rosmatlab.message('geometry_msgs/Vector3', node);
msgLin2 = rosmatlab.message('geometry_msgs/Vector3', node2);%creart message type
msg2 = rosmatlab.message('geometry_msgs/Twist', node2);
msgAng2 = rosmatlab.message('geometry_msgs/Vector3', node2);
msgLin3 = rosmatlab.message('geometry_msgs/Vector3', node3);%creart message type
msg3 = rosmatlab.message('geometry_msgs/Twist', node3);
msgAng3 = rosmatlab.message('geometry_msgs/Vector3', node3);
subscriber= rosmatlab.subscriber('/robot/husky/cmd_vel', 'geometry_msgs/Twist',10,node); 
publisher = rosmatlab.publisher('/robot/husky/cmd_vel','geometry_msgs/Twist', node);
subscriber2= rosmatlab.subscriber('/robot2/husky/cmd_vel', 'geometry_msgs/Twist',10,node2); 
publisher2 = rosmatlab.publisher('/robot2/husky/cmd_vel','geometry_msgs/Twist', node2);
subscriber3= rosmatlab.subscriber('/robot3/husky/cmd_vel', 'geometry_msgs/Twist',10,node3); 
publisher3 = rosmatlab.publisher('/robot3/husky/cmd_vel','geometry_msgs/Twist', node3);
for i=1:20
   % My_husky2(10,5);
   % My_husky3(5,2.5);

Message Type is "Geometry?Twist".My_husky(My_husky2 My_husky3) are my defined function,the first parameter is the linear velocity,second parameter is angular speed.I think pi/4200.1=pi/2,it should rotate pi/2 rad,but in gazebo it doesn't.At different position,Husky rotates different angle with the same code. The Myhusky function

function My_husky(a,b)
global msg;
global msgLin;
global msgAng;
global publisher;
global subscriber;
% Create Subscriber to ROS TWIST Message, called husky/cmd_vel, with
% buffer size = 1;

%subscriber1= rosmatlab.subscriber('/robot/husky/cmd_vel', 'geometry_msgs/Twist',1,node); 
% When message is received, call function to show value 
%subscriber.setOnNewMessageListeners({@display_vel});%%%needed change
% Create a publisher for the ROS TWIST message, called husky/cmd_vel
%publisher1 = rosmatlab.publisher('/robot/husky/cmd_vel','geometry_msgs/Twist', node);
% Set Linear velocity components of command
 msgLin.setX(a);%here just setX is useful
% msgLin.setY(0);
% msgLin.setZ(0);
% Set Angular velocity components of command
msgAng.setZ(b);%here just setZ is useful
% msgAng.setX(0);
% msgAng.setY(0);
msg.setLinear (msgLin);
msg.setAngular (msgAng);


Could anyone tell me why?And how to make husky rotate accurately.Thx!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-03-29 04:47:16 -0600

ziyeshanwai gravatar image

I have solved the Question. I add a plugin in urdf.And then I subscribe the topic. refer to the link here in matlab ,I get the data.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-03-25 09:41:26 -0600

Seen: 597 times

Last updated: Mar 29 '15