ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Avoid global variables. it is bad practice. here is how you could do it:
class Node
{
public:
Node (ros::NodeHandle& nh) : nh_(nh) // your constructor and store
void callback (const sensor_msgs::Pointcloud2& cloud)
{
cloudIn_ = cloud; // copy the variable that the callback passes in to you class variable (attribute) cloudIn
}
process()
{
// do your processing here with cloudIn
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
sensor_msgs::Pointcloud2 cloudIn;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
Node* node = 0;
node = new Node (nh);
node->spin ();
return 0;
}
Hope this helps!
2 | No.2 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class Node
{
public:
Node (ros::NodeHandle& nh) : nh_(nh) nh_(nh){} // your constructor and store
void callback (const sensor_msgs::Pointcloud2& cloud)
{
cloudIn_ = cloud; // copy the variable that the callback passes in to you class variable (attribute) cloudIn
}
process()
{
// do your processing here with cloudIn
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
sensor_msgs::Pointcloud2 cloudIn;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
Node* node = 0;
node = new Node (nh);
node->spin ();
return 0;
}
Hope this helps!
3 | No.3 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class Node
{
public:
Node (ros::NodeHandle& nh) : nh_(nh){} // your constructor and store
store the passed node handle (nh) to your class attribute nh_
void callback (const sensor_msgs::Pointcloud2& cloud)
{
cloudIn_ = cloud; // copy the variable that the callback passes in to you class variable (attribute) cloudIn
}
process()
{
// do your processing here with cloudIn
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
sensor_msgs::Pointcloud2 cloudIn;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
Node* node = 0;
node = new Node (nh);
node->spin ();
return 0;
}
Hope this helps!
4 | No.4 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class Node
pass_cloud
{
public:
Node pass_cloud (ros::NodeHandle& nh) : nh_(nh){} nh_(nh)
{
sub = nh.subscribe ("/camera/depth_registered/points", 3,&pass_cloud::callback,this);
} // your constructor and store the passed node handle (nh) to your class attribute nh_
void callback (const sensor_msgs::Pointcloud2& cloud)
{
cloudIn_ = input= cloud; // copy the variable that the callback passes in to you class variable (attribute) cloudIn
input
}
process()
{
// do your processing here with cloudIn
std::cout << " " << input.points[i].x << " " << input.points[i].y << " " << input.points[i].z << std::endl; std::cout<<"reached here"<<std::endl;
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
sensor_msgs::Pointcloud2 cloudIn;
pcl::PointCloud& input;
cloud ros::Subscriber sub;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
Node* pass_cloud* node = 0;
node = new Node (nh);
pass_cloud(nh);
node->spin ();
return 0;
}
Hope this helps!
5 | No.5 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class pass_cloud
{
public:
pass_cloud (ros::NodeHandle& nh) : nh_(nh)
{
sub = nh.subscribe nh_.subscribe ("/camera/depth_registered/points", 3,&pass_cloud::callback,this);
} // your constructor and store the passed node handle (nh) to your class attribute nh_
void callback (const sensor_msgs::Pointcloud2& cloud)
{
input= cloud; // copy the variable that the callback passes in to you class variable (attribute) input
}
process()
{
std::cout << " " << input.points[i].x << " " << input.points[i].y << " " << input.points[i].z << std::endl; std::cout<<"reached here"<<std::endl;
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
pcl::PointCloud& input;
cloud ros::Subscriber sub;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
pass_cloud* node = 0;
node = new pass_cloud(nh);
node->spin ();
return 0;
}
Hope this helps!
6 | No.6 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class pass_cloud
{
public:
pass_cloud (ros::NodeHandle& nh) : nh_(nh)
{
sub = nh_.subscribe ("/camera/depth_registered/points", 3,&pass_cloud::callback,this);
} // your constructor and store the passed node handle (nh) to your class attribute nh_
void callback (const sensor_msgs::Pointcloud2& pcl::PointCloud& cloud)
{
input= cloud; // copy the variable that the callback passes in to you class variable (attribute) input
}
process()
{
std::cout << " " << input.points[i].x << " " << input.points[i].y << " " << input.points[i].z << std::endl; std::cout<<"reached here"<<std::endl;
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
pcl::PointCloud& input;
cloud ros::Subscriber sub;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
pass_cloud* node = 0;
node = new pass_cloud(nh);
node->spin ();
return 0;
}
Hope this helps!
7 | No.7 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class pass_cloud
{
public:
pass_cloud (ros::NodeHandle& nh) : nh_(nh)
nh_(nh), i(0)
{
sub = nh_.subscribe ("/camera/depth_registered/points", 3,&pass_cloud::callback,this);
} // your constructor and store the passed node handle (nh) to your class attribute nh_
void callback (const pcl::PointCloud& cloud)
{
input= cloud; // copy the variable that the callback passes in to you class variable (attribute) input
}
process()
{
std::cout << " " << input.points[i].x << " " << input.points[i].y << " " << input.points[i].z << std::endl; std::cout<<"reached here"<<std::endl;
i=i+1;
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
pcl::PointCloud& input;
cloud ros::Subscriber sub;
int i;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
pass_cloud* node = 0;
node = new pass_cloud(nh);
node->spin ();
return 0;
}
Hope this helps!
8 | No.8 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class pass_cloud
{
public:
pass_cloud (ros::NodeHandle& nh) : nh_(nh), i(0)
{
sub = nh_.subscribe ("/camera/depth_registered/points", 3,&pass_cloud::callback,this);
} // your constructor and store the passed node handle (nh) to your class attribute nh_
void callback (const pcl::PointCloud& cloud)
{
input= cloud; // copy the variable that the callback passes in to you class variable (attribute) input
i=i+1;
}
process()
{
std::cout << " " << input.points[i].x << " " << input.points[i].y << " " << input.points[i].z << std::endl; std::cout<<"reached here"<<std::endl;
i=i+1;
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
pcl::PointCloud& input;
cloud ros::Subscriber sub;
int i;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
pass_cloud* node = 0;
node = new pass_cloud(nh);
node->spin ();
return 0;
}
Hope this helps!
9 | No.9 Revision |
Avoid global variables. it is bad practice. here is how you could do it:
class pass_cloud
{
public:
pass_cloud (ros::NodeHandle& nh) : nh_(nh), i(0)
{
sub = nh_.subscribe ("/camera/depth_registered/points", 3,&pass_cloud::callback,this);
} // your constructor and store the passed node handle (nh) to your class attribute nh_
void callback (const pcl::PointCloud& cloud)
{
input= cloud; // copy the variable that the callback passes in to you class variable (attribute) input
i=i+1;
}
process()
{
//You might want to add an if statement here to only print if the input is not empty, I am not sure how but something like this if(input is not empty){
std::cout << " " << input.points[i].x << " " << input.points[i].y << " " << input.points[i].z << std::endl; std::cout<<"reached here"<<std::endl;
}
void spin ()
{
ros::Rate rate (30);
while (ros::ok ())
{
ros::spinOnce ();
rate.sleep ();
}
}
protected: // Your class attributes
ros::NodeHandle nh_;
pcl::PointCloud& input;
cloud ros::Subscriber sub;
int i;
}; // end of class
int main(int argc, char **argv)
{
ros::init(argc, argv, "pointcloud_node");
ros::NodeHandle nh;
pass_cloud* node = 0;
node = new pass_cloud(nh);
node->spin ();
return 0;
}
Hope this helps!