Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merger not subscribing to gazebo generated laser topics #5

Open
schultza opened this issue Jan 28, 2016 · 5 comments
Open

Merger not subscribing to gazebo generated laser topics #5

schultza opened this issue Jan 28, 2016 · 5 comments

Comments

@schultza
Copy link

Hello,
while trying to set up my system in Gazebo, I was noticing that the merger doesn't subscribe to the laser topics generated by 3 hokuyo lidars in Gazebo.
My config is the following:
3 lasers mounted at robot -> publishing topics: /scan_hokuyo1 /scan_hokuyo2 and /scan_ibeo1
See my output of rostopic list:

rostopic list
/scan_hokuyo1
/scan_hokuyo2
/scan_ibeo1
/scan_multi_merged


You also see the topic `/scan_multi_merged` which is published by the laser merger node as you can see here:

rosnode info /laserscan_multi_merger

Node [/laserscan_multi_merger]
Publications:

  • /laserscan_multi_merger/parameter_descriptions [dynamic_reconfigure/ConfigDescription]
  • /merged_cloud [sensor_msgs/PointCloud2]
  • /rosout [rosgraph_msgs/Log]
  • /laserscan_multi_merger/parameter_updates [dynamic_reconfigure/Config]
  • /scan_multi_merged [sensor_msgs/LaserScan]

Subscriptions:

  • /tf [tf2_msgs/TFMessage]
  • /tf_static [tf2_msgs/TFMessage]
  • /clock [rosgraph_msgs/Clock]

Services:

  • /laserscan_multi_merger/set_parameters
  • /laserscan_multi_merger/set_logger_level
  • /laserscan_multi_merger/get_loggers

contacting node http://aschultz-ThinkPad-T450s:42260/ ...
Pid: 21244
Connections:

You can see the node isn't subscribing to the topics mentioned above. I started the node with the following part of my launch file:

<node pkg="ira_laser_tools" name="laserscan_multi_merger" type="laserscan_multi_merger" output="screen">
     <param name="destination_frame" value="/ibeo_frame"/>
     <param name="cloud_destination_topic" value="/merged_cloud"/>
     <param name="scan_destination_topic" value="/scan_multi_merged"/>
     <param name="laserscan_topics" value ="/scan_hokuyo1 /scan_hokuyo2 /scan_ibeo1" /> 
</node>

If I try to echo the topic of the laser merger the following output appears and also ROS_DEBUG messages are published:

rostopic echo /scan_multi_merged 
WARNING: no messages received and simulated time is active.
Is /clock being published?

[DEBUG] [1453887963.432518126, 100.157000000]: Incoming queue full for topic "/clock". Discarding oldest message (current queue size [0])

So I don't think that the subscription to topics is done correctly.
Thanks in advance

@cyborg-x1
Copy link

I guess the problem here is that the node checks if the topic is already there and then subscribes it.
Well if you launch it in a launchfile probably the node of the scan merger is launched in the beginning... topics not there ... topics not subscribed

change the topic parser function like this, and it should work, as far as it does ...

void LaserscanMerger::laserscan_topic_parser()
{
    // LaserScan topics to subscribe
    ros::master::V_TopicInfo topics;
    ros::master::getTopics(topics);
    istringstream iss(laserscan_topics);
    vector<string> tokens;
    copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));
    vector<string> tmp_input_topics;
    for(int i=0;i<tokens.size();++i)
    {
//          for(int j=0;j<topics.size();++j)
//      {
//          if( (tokens[i].compare(topics[j].name) == 0) && (topics[j].datatype.compare("sensor_msgs/LaserScan") == 0) )
//          {
                tmp_input_topics.push_back(tokens[i]);
//          }
//      }
    }

awesomebytes added a commit to uts-magic-lab/ira_laser_tools that referenced this issue Jun 20, 2017
#0  0xb29183ee in ?? () from /lib/libc.so.6
iralabdisco#1  0x080c85a2 in Eigen::internal::handmade_aligned_free(void*) ()
iralabdisco#2  0x080c85ef in Eigen::internal::aligned_free(void*) ()
iralabdisco#3  0x080cf4d8 in void Eigen::internal::conditional_aligned_free<true>(void*) ()
iralabdisco#4  0x080d5a6f in void Eigen::internal::conditional_aligned_delete_auto<float, true>(float*, unsigned int) ()
iralabdisco#5  0x080d350e in Eigen::DenseStorage<float, -1, -1, -1, 0>::~DenseStorage() ()
iralabdisco#6  0x080ce018 in Eigen::PlainObjectBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> >::~PlainObjectBase() ()
iralabdisco#7  0x080ce030 in Eigen::Matrix<float, -1, -1, 0, -1, -1>::~Matrix() ()
iralabdisco#8  0x080c4a65 in LaserscanMerger::scanCallback(boost::shared_ptr<sensor_msgs::LaserScan_<std::allocator<void> > const> const&, std::string) ()
@EwingKang
Copy link

EwingKang commented Dec 24, 2018

change the topic parser function like this, and it should work, as far as it does ...

I've bump into the same problem, and thanks to @cyborg-x1, the fix worked. Guess this behavior is more desirable considering the ROS philosophy....

shannon112 added a commit to shannon112/ira_laser_tools that referenced this issue Sep 13, 2019
@Fellfalla
Copy link

try this fix: https://answers.ros.org/question/225183/ira_laser_tools-merger-doesnt-subscribe-to-topics-from-laser-in-gazebo/

Basically he adds a success return value and loops over laserscan_topic_parser() until the topics are published.

@ryanduringhours
Copy link

try this fix: https://answers.ros.org/question/225183/ira_laser_tools-merger-doesnt-subscribe-to-topics-from-laser-in-gazebo/

Basically he adds a success return value and loops over laserscan_topic_parser() until the topics are published.

I saw that thread and tried to make that fix. I feel like I'm doing it wrong. Could you post the modified source code or help me find where exactly im supposed to add this ros::Rate loop_rate(0.5); //-- 0.5 [Hz] -> 2.0 [s] while( !this->laserscan_topic_parser() ) { ROS_DEBUG("LaserscanMerger: Retrying to detect the topics to subscribe to..."); loop_rate.sleep(); }
Thanks

@SmitRmb
Copy link

SmitRmb commented Aug 21, 2020

// LaserScan topics to subscribe
	ros::master::V_TopicInfo topics;
	ros::master::getTopics(topics);

    istringstream iss(laserscan_topics);
	vector<string> tokens;
	copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter<vector<string> >(tokens));

	vector<string> tmp_input_topics;
	while(tokens.size() != tmp_input_topics.size())
	{	
		ros::master::getTopics(topics);
		
		for(int i=0;i<tokens.size();++i)
		{
			for(int j=0;j<topics.size();++j)
			{
				if( (tokens[i].compare(topics[j].name) == 0) && (topics[j].datatype.compare("sensor_msgs/LaserScan") == 0) )
				{
					tmp_input_topics.push_back(topics[j].name);
				}
			}
		}

		sort(tmp_input_topics.begin(),tmp_input_topics.end());
		std::vector<string>::iterator last = std::unique(tmp_input_topics.begin(), tmp_input_topics.end());
		tmp_input_topics.erase(last, tmp_input_topics.end());
		ROS_INFO_STREAM_THROTTLE(2.0, "Laserscan merger waiting for specified input topics. " <<  tmp_input_topics.size() << "/" << tokens.size() << " input topics found");
		if(tokens.size() == tmp_input_topics.size()) //Do not sleep if all input topics are found
		{
			break; 
		}
		ros::Duration(1.0).sleep(); 		
	}


	// Do not re-subscribe if the topics are the same
	if( (tmp_input_topics.size() != input_topics.size()) || !equal(tmp_input_topics.begin(),tmp_input_topics.end(),input_topics.begin()))
	{
....

This fix works for me. Waits until all input topics are available, and outputs a throttled ROS_INFO to let a user know how many of its selected input topics are available and how many are still to come.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants