从MATLAB发布makers到Rviz中(转)

Publishing markers in RViz from MATLAB

Testing basic shape example

This example demonstrates how to publish different types of markers from MATLAB to RViz. In order to publish ROS messages, we use Robotics System Toolbox which is supported in MATLAB version above R2015a.

Kazam_screenshot_00001,

  • We first run roscore and rviz in a computer running Ubuntu as follows:
    roscore
    rosrun rviz rviz
  • In the computer running ROS, we publish a tf for a fixed frame, named my_frame as follows:
    rosrun tf static_transform_publisher 0.0 0.0 0.0 0.0 0.0 0.0 map my_frame 100
  • In matlab, we run following script:
%=== set the address for the connection
% IP address of the computer running roscore (ros server)
setenv('ROS_MASTER_URI','http://IP_address:11311'); 
rosinit; % connect to the ros server      
%=== specify data to publish
markerPub = rospublisher('/visualization_marker','visualization_msgs/Marker');
marker = rosmessage(markerPub);
   
%- set the frame information and names of marker
marker.Header.FrameId = 'my_frame';
marker.Ns = 'basic_shapes';
marker.Text = 'cube';
   
%- set the time
marker.Header.Stamp = rostime('now','system');
   
%- set the ID of the shape
marker.Id = 0;   
%- set the scale of the shape
marker.Scale.X = 1;
marker.Scale.Y = 1;
marker.Scale.Z = 1;
   
%- set position and orientation
Pos = rosmessage('geometry_msgs/Point');
Pos.X = 0;
Pos.Y = 0;
Pos.Z = 0;                
Ori = rosmessage('geometry_msgs/Quaternion');
Ori.W = 1;
marker.Pose.Position = Pos; 
marker.Pose.Orientation = Ori;  
%- set color
Color = rosmessage('std_msgs/ColorRGBA');
Color.R = 1;
Color.G = 0.5;
Color.B = 0;
Color.A = 1;
marker.Color = Color;  
%- set the type of the shape
type = [1 2 3]; % 1: cube, 2: sphere, 3: cylinder
   
while (1)
  for i=1:3
      %- set the time
      marker.Header.Stamp = rostime('now','system');
      marker.Type = type(i); 
      send(markerPub,marker);
      pause(1);
      disp(i)
  end            
end
  • In rviz, we add a marker and set the Fixed Frame as follows:
    Kazam_screenshot_00000
  • Then you will be able to see the marker displayed in RViz like below:

Hope this example will be helpful for making visualization in ROS easier! If you have any problems or questions, please leave comments!

来源:http://www.whatisrobot.com/?p=28&i=1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值