在ros绑定advertiseService的回调函数时,通过boost::bind函数,将需要传递的其他参数,在触发回调的时候,一并传入。
-
- bool callback(path_planner::CreateP2PPath::Request &req, path_planner::CreateP2PPath::Response& res, CPathTools& path){
- //do something
- return true;
- }
-
- int main(int argc, char **argv) {
- ros::init(argc, argv, "path_planner_node");
- ros::NodeHandle nh;
-
- CPathTools path(atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]), atof(argv[5]));
-
- auto service = nh.advertiseService
("CreateP2PPath", boost::bind(callback, _1, _2, path)); -
- ros::spin();
-
- return 0;
- }