Can't resubscribe to a topic after shutdown
I, I'm having some issues. The code works fine until the shutdown of the subscriber, after that, the specific topics are not resubscribed, so I cannot do anything more.
Ps: the code works fine without the shutdowns, but I want to shutdown the subscribers when I don't need them.
This is my code:
class ObjectDetection
{
public:
ObjectDetection(ros::NodeHandle *nh)
{
nh->getParam("/point_cloud", path_cloud);
nh->getParam("/image", path_image);
nh->getParam("/output_cloud", path_outcloud);
pub_cloud= nh->advertise<sensor_msgs::PointCloud2>(path_outcloud, 1, true);
subcloud= nh->subscribe(path_cloud, 1, &ObjectDetection::cloud_callback, this);
image_transport::ImageTransport it(*nh);
subimage = it.subscribe("/imagetimer", 1, &ObjectDetection::cloud_processing, this);
}
//Receive point cloud
void cloud_callback (const sensor_msgs::PointCloud2& cloud_msg){
//do stuff
}
void cloud_processing(const sensor_msgs::ImageConstPtr& msg)
{
//do stuff
pub_cloud.publish(point_cloud_result);
subcloud.shutdown();
subimage.shutdown();
}
private:
std::string path_cloud, path_image, path_outcloud;
ros::Subscriber subcloud;
ros::Publisher pub_cloud;
pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr primary_cloud;
image_transport::Subscriber subimage;
};
int main (int argc, char **argv)
{
ros::init(argc, argv, "ObjectDetectionServer");
ros::NodeHandle nh;
ObjectDetection ObjectD= ObjectDetection(&nh);
ros::spin();
}
Thank you,