service客户端发命令后,出现报错 ERROR: service [/service_name] responded with an error: b’’ ,原因在于service服务端的回调函数必须 return true
advertiseService的部分源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
boolServiceManager::advertiseService(const AdvertiseServiceOptions& ops) { boost::recursive_mutex::scoped_lock shutdown_lock(shutting_down_mutex_); if (shutting_down_) { returnfalse; } { boost::mutex::scoped_lock lock(service_publications_mutex_); // 如果service已经发布,就报错,然后返回,其实这里改成报警比较合适 if (isServiceAdvertised(ops.service)) { ROS_ERROR("Tried to advertise a service that is already advertised in this node [%s]", ops.service.c_str()); returnfalse; }
其中的bool ros::ServiceManager::unadvertiseService(const std::string& serv_name)作用是 Unadvertise a service. This call unadvertises a service, which must have been previously advertised, using advertiseService().
Matrix3x3 & getBasis()//Return the basis matrix for the rotation const Vector3 & getOrigin()//Return the origin vector translation Quaternion getRotation()//Return a quaternion representing the rotation Transform operator* (const Transform &t)const//Return the product of this transform and the other. Transform inverse()//Return the inverse of this transform
//get the starting pose of the robot tf::Stamped<tf::Pose> global_pose; if(!planner_costmap_ros_->getRobotPose(global_pose)) { ROS_WARN("Unable to get starting pose of robot, unable to create global plan"); returnfalse; } geometry_msgs::PoseStamped start_pose; tf::poseStampedTFToMsg(global_pose, start_pose);
还有类似的函数: poseTFToMsg 和 transformMsgToTF
angles包
static double from_degrees (double degrees): Convert degrees to radians
typedef std::vector<std::string> ros::V_string // Retreives the currently-known list of nodes from the master. 放入 ROSCPP_DECL boolgetNodes(V_string &nodes)
用这个函数很简单:
1 2 3 4 5 6 7
std::vector<std::string> nodes; ros::master::getNodes(nodes); // bool int len = nodes.size(); for (int i =0; i < len; i ++) { cout<<"node: "<<nodes.at(i)<<endl; }
获得当前运行的所有话题名
1 2 3 4 5 6 7 8 9 10 11
structros::master::TopicInfo { TopicInfo () TopicInfo (const std::string &_name, const std::string &_datatype) public: std::string datatype // Datatype of the topic. std::string name // Name of the topic. } typedef std::vector<TopicInfo> ros::master::V_TopicInfo ROSCPP_DECL boolgetTopics(V_TopicInfo &topics)
使用是类似的:
1 2 3 4 5 6 7 8
std::vector<ros::master::TopicInfo> topics; ros::master::getTopics(topics); int len = topics.size(); for (int i =0; i < len; i ++) { cout<<"topic: "<<topics.at(i).name<<" type: " <<topics.at(i).datatype<<endl; }
// Get the hostname where the master runs. ROSCPP_DECL const std::string & getHost() // Get the port where the master runs. ROSCPP_DECL uint32_tgetPort() // Get the full URI to the master (eg. http://host:port/) ROSCPP_DECL const std::string & getURI()