Calling a function in a function
Hi, can help me to check what is my mistake in the following code please? I did try to refer to http://wiki.ros.org/roscpp_tutorials/Tutorials/UsingClassMethodsAsCallbacks but fail. Thank you.
#include "ros/ros.h"
#include <visualization_msgs/Marker.h>
#include <pcl/ros/conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl_ros/point_cloud.h>
ros::Subscriber sub_;
ros::Publisher markerpub_;
class Listener{
public:
double publishBbox();
};
void cloudcb(const PointCloud::ConstPtr& cloud){
publishBbox();
}
double Listener::publishBbox(){
double x = (min_x_ + max_x_)/2;
double y = (min_y_ + max_y_)/2;
double z = (0 + max_z_)/2;
double scale_x = (max_x_ - x)*2;
double scale_y = (max_y_ - y)*2;
double scale_z = (max_z_ - z)*2;
visualization_msgs::Marker marker;
marker.header.frame_id = "/camera_rgb_optical_frame";
marker.header.stamp = ros::Time();
marker.ns = "my_namespace";
marker.id = 1;
marker.type = visualization_msgs::Marker::CUBE;
marker.action = visualization_msgs::Marker::ADD;
marker.pose.position.x = x;
marker.pose.position.y = -y;
marker.pose.position.z = z;
marker.pose.orientation.x = 0.0;
marker.pose.orientation.y = 0.0;
marker.pose.orientation.z = 0.0;
marker.pose.orientation.w = 1.0;
marker.scale.x = scale_x;
marker.scale.y = scale_y;
marker.scale.z = scale_z;
marker.color.a = 0.5;
marker.color.r = 0.0;
marker.color.g = 1.0;
marker.color.b = 0.0;
//only if using a MESH_RESOURCE marker type:
bboxpub_.publish( marker );
}
int main(int argc, char** argv){
ros::init(argc, argv, "my_tf_broadcaster");
ros::NodeHandle nh;
sub_= nh.subscribe("camera/depth/points", 1, cloudcb);
Listener bbox;
bboxpub_ = nh.advertise<visualization_msgs::Marker>("bbox",1, &Listener::publishBbox, &bbox);
ros::spin();
return 0;
};
Could you post the error messages please?
hi VC, my apologies. the error message was "error: ‘publishBbox’ was not declared in this scope". hav tried the suggestion given by Ben_S and it worked. Thanks :)