rviz stops abnormally. Please let me know the cause.

asked 2021-10-22 12:03:31 -0500

yu_ki gravatar image

rviz stops abnormally. Please let me know the cause.

I am trying to display an arrow-shaped visualization marker in rviz.

So I wrote a program to subscribe to the location information of the arrow visualization markers and started it. The program is shown below.

#include <ros/ros.h>
#include <tf/transform_datatypes.h>
#include <ar_track_alvar_msgs/AlvarMarkers.h>
#include<tf/transform_broadcaster.h>
#include <tf/transform_listener.h>
#include<iostream>
#include <string>
#include <visualization_msgs/MarkerArray.h>

double ar1 = 0;
double ar2 = 0;
double ar3 = 0;

double ar4 = 0.1;
double ar5 = 0;
double ar6 = 0;

void cb(ar_track_alvar_msgs::AlvarMarkers req) {

  tf::TransformBroadcaster tf_br;
  tf::TransformListener listener;
  static  tf::Transform transform;

  if (!req.markers.empty()) {
    tf::Quaternion q(req.markers[0].pose.pose.orientation.x, req.markers[0].pose.pose.orientation.y, req.markers[0].pose.pose.orientation.z, req.markers[0].pose.pose.orientation.w);
    transform.setOrigin( tf::Vector3(ceil(req.markers[0].pose.pose.position.x), ceil(req.markers[0].pose.pose.position.y), ceil(req.markers[0].pose.pose.position.z)) );
    transform.setOrigin( tf::Vector3(req.markers[0].pose.pose.position.x, req.markers[0].pose.pose.position.y, req.markers[0].pose.pose.position.z) );
    transform.setRotation(tf::Quaternion( req.markers[0].pose.pose.orientation.x, req.markers[0].pose.pose.orientation.y, req.markers[0].pose.pose.orientation.z, req.markers[0].pose.pose.orientation.w));

    try{

      ar1 = req.markers[0].pose.pose.position.x;
      ar2 = req.markers[0].pose.pose.position.y;
      ar3 = req.markers[0].pose.pose.position.z;

      ar4 = req.markers[1].pose.pose.position.x;
      ar5 = req.markers[1].pose.pose.position.y;
      ar6 = req.markers[1].pose.pose.position.z;

        ROS_INFO("position1(x,y,z) = ( %3.3f : %3.3f : %3.3f )  \n", ar1, ar2, ar3);
        ROS_INFO("position2(x,y,z) = ( %3.3f : %3.3f : %3.3f )  \n", ar4, ar5, ar6);

    }
    catch (tf::TransformException ex){
      ROS_ERROR("%s",ex.what());
      ros::Duration(1.0).sleep();
    }
  }
}

int main(int argc, char **argv) {
  ros::init(argc, argv, "camera_tf_pose");
  ros::NodeHandle nh;

  // publisher
  ros::Publisher marker_pub = nh.advertise<visualization_msgs::MarkerArray>("marker_array", 1);

  // subscriber
  ros::Subscriber sub = nh.subscribe("ar_pose_marker", 10, &cb);

   ros::Rate loop_rate(10);


  while (ros::ok()){

    geometry_msgs::Vector3 arrow;  // config arrow shape
    arrow.x = 0.01;
    arrow.y = 0.01;
    arrow.z = 0.001;

    geometry_msgs::Point linear_start;
    linear_start.x = ar1;
    linear_start.y = ar2;
    linear_start.z = ar3;

    geometry_msgs::Point linear_end;
    linear_end.x = ar4;
    linear_end.y = ar5;
    linear_end.z = ar6;

    visualization_msgs::MarkerArray marker_array;
    marker_array.markers.resize(1);

    // marker0
    marker_array.markers[0].header.frame_id = "/camera_link";
    marker_array.markers[0].header.stamp = ros::Time::now();
    marker_array.markers[0].ns = "basic_shapes0";
    marker_array.markers[0].id = 5;
    marker_array.markers[0].lifetime = ros::Duration();

    marker_array.markers[0].type = visualization_msgs::Marker::ARROW;
    marker_array.markers[0].action = visualization_msgs::Marker::ADD;
    marker_array.markers[0].scale = arrow;

    marker_array.markers[0].points.resize(2);
    marker_array.markers[0].points[0] = linear_start;
    marker_array.markers[0].points[1] = linear_end;

    marker_array.markers[0].color.r = 0.0f;
    marker_array.markers[0].color.g = 1.0f;
    marker_array.markers[0].color.b = 0.0f;
    marker_array.markers[0].color.a = 1.0f ...
(more)
edit retag flag offensive close merge delete

Comments

What is your computer configuration? The reason I ask, it's that there is a similar error that occurs with ROS Kinetic with PR2 simulation: https://github.com/ros-planning/movei...

osilva gravatar image osilva  ( 2021-10-22 12:16:00 -0500 )edit

Thank you for your reply. The configuration of my pc is ・ubuntu16.04 ・ROS1 kinetic

The specifics of the above program is to read the position of the ar marker using ar_track_alvar, a library that can get the position of the ar marker from the camera. The program then tries to draw a visualization marker at the location of the read value in rviz.

Thank you in advance for your help.

yu_ki gravatar image yu_ki  ( 2021-10-22 13:57:57 -0500 )edit
1

Why is everyone still using Kinetic and Ubuntu 16.04?

@yu_ki: could you clarify why you are not using something more recent -- and supported -- such as Melodic or Noetic?

gvdhoorn gravatar image gvdhoorn  ( 2021-10-22 14:01:47 -0500 )edit