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

arrow not showing in rviz

asked 2016-07-08 17:55:07 -0600

dinesh gravatar image

updated 2016-07-08 19:38:10 -0600

I was trying to display an arrow inside rviz by using below code:

#include <ros/ros.h>
#include <visualization_msgs/Marker.h>
#include <cmath>

int main( int argc, char** argv )
{
  ros::init(argc, argv, "lines");
  ros::NodeHandle n;
  ros::Rate r(1);
  ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("lines", 10);

  while (ros::ok())
  {
      visualization_msgs::Marker arrow;
      arrow.header.frame_id = "/camera_depth_frame";
      arrow.header.stamp = ros::Time::now();

  arrow.ns = "lines";
  arrow.id = 1;

  arrow.type = visualization_msgs::Marker::ARROW;
  arrow.action = visualization_msgs::Marker::ADD;

  arrow.pose.position.x = 1;
  arrow.pose.position.y = 1;
  arrow.pose.position.z = 1;

  arrow.pose.orientation.x = 0.0;
  arrow.pose.orientation.y = 0.0;
  arrow.pose.orientation.z = 0.0;
  arrow.pose.orientation.w = 1.0;

  arrow.scale.x=1.0;
  arrow.scale.y=1.0;
  arrow.scale.z = 1.0;

  arrow.color.g = 1.0f;
  arrow.color.a = 1.0;
  arrow.color.r = 0.0f;
  arrow.color.b = 0.0f;

  arrow.lifetime = ros::Duration();

  while (marker_pub.getNumSubscribers() < 1)
     {
       if (!ros::ok())
       {
         return 0;
       }
       ROS_WARN_ONCE("Please create a subscriber to the marker");
       sleep(1);
     }

  marker_pub.publish(arrow);
  r.sleep();

} } but when i run rviz, what i'm seeing is a cylinder with a circle at the bottom. i'm not getting arrow marker. As i saw in tutorial code display shpae in this page also same shape comes in the name of arrow but what i want was an arrow line,vector with fixed position and direction no some shpae,my CmakeLists.txt is:

cmake_minimum_required(VERSION 2.8.3)
project(using_markers)

find_package(catkin REQUIRED COMPONENTS roscpp visualization_msgs)

catkin_package()

include_directories(${catkin_INCLUDE_DIRS})

add_executable(basic_shapes src/basic_shapes.cpp)
target_link_libraries(basic_shapes ${catkin_LIBRARIES})

add_executable(points_and_lines src/points_and_lines.cpp)
target_link_libraries(points_and_lines ${catkin_LIBRARIES})

add_executable(lines src/lines.cpp)
target_link_libraries(lines ${catkin_LIBRARIES})

Im using ros indigo. shouldn't i get a vector or line segment when i use arrow marker, i dont understand it.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-07-09 02:15:03 -0600

Caba gravatar image

Hi,

I did not run the code but I am pretty sure that it is because you set uncorrectly the scales of the arrow. For the tutorial you mean, they used a CUBE as shape, so what they want 1 meter for all the dimensions. But for the arrow the dimensions have a different meaning. See this in the section Objects Types they explain the meaning of the scale for the arrow. Moreover the dimensions definition depends on the way you used to specify the arrow Pose (Points or Quaternion).

In your case, you used quaternion, so:

scale.x is the shaft diameter

scale.y is the head diameter

scale.z is the head length

You set all those values equal to 1, so that is the reason to be of the cylinder.

Hope this help.

edit flag offensive delete link more

Comments

o, thanks for help, now i got it why my arrow was looking like some temple at starting. but as i changed the value of scale.y and scale.z im getting the arrow, he he.

dinesh gravatar image dinesh  ( 2016-07-09 03:39:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-07-08 17:55:07 -0600

Seen: 2,237 times

Last updated: Jul 09 '16