Ask Your Question
0

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

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

ziyeshanwai gravatar image

Hey!guys,I have a problem with gazebo.I do as http://wiki.ros.org/Robots/Husky.And then I setup ROS I/O Package(https://www.mathworks.com/hardware-support/files/ros-io-package-getting-started-guide.pdf).Everything 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

  clc;
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 = '127.0.0.1';localhostIp = '127.0.1.1';
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(0,pi/4);
    pause(0.1);
    message.getZ();
   % My_husky2(10,5);
   % My_husky3(5,2.5);
end

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); 
%subscriber.setOnNewMessageListeners({@display_vel});
% 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);
publisher.publish(msg);

end

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
0

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 398 times

Last updated: Mar 29 '15