Ask Your Question
-1

How to initialize a subscriber only when a 'if' condition meets?

asked 2019-07-06 00:54:52 -0500

JeyP4 gravatar image

updated 2019-07-06 05:05:03 -0500

Hello. I want to initialize a subscriber only when

if(i>0){              // 'i' is received as node argument
  ros::Subscriber sub = nh.subscribe("/image_rect_color/compressed", 1, imageCallback);
  }

Problem I am facing is: main thread comes into if-scope but couldn't initialize the subscriber. I guess problem is introduction of new scope.

BTW:This code is in main().

How can this problem be solved?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-07-06 15:56:40 -0500

JeyP4 gravatar image
ros::Subscriber sub;

if(i>0){              // 'i' is received as node argument
sub = nh.subscribe("/image_rect_color/compressed", 1, imageCallback);
}

This worked for me.

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: 2019-07-06 00:54:52 -0500

Seen: 17 times

Last updated: Jul 06