我现在知道使用ROS话题消息的功能包的命名空间是在哪里定义的了

 

确实是会基于msg文件生成对应头文件,打开头文件,一切都明了了。

 

比如这是DroneState.msg对应生成的头文件DroneState.h,是在devel文件夹下面,是编译生成的。这里一开头就明确定义了工作空间namespace,以后再看到prometheus_msgs::DroneSate就不会有疑问了,我一直对这个细节抓着不放彻底弄明白弄清楚是对的,是可以真正完全弄清楚的。看来msg文件可以写那么简单完全是为了方便我们啊,实际的头文件内容还是非常多的。

// Generated by gencpp from file prometheus_msgs/DroneState.msg
// DO NOT EDIT!


#ifndef PROMETHEUS_MSGS_MESSAGE_DRONESTATE_H
#define PROMETHEUS_MSGS_MESSAGE_DRONESTATE_H


#include <string>
#include <vector>
#include <map>

#include <ros/types.h>
#include <ros/serialization.h>
#include <ros/builtin_message_traits.h>
#include <ros/message_operations.h>

#include <std_msgs/Header.h>
#include <geometry_msgs/Quaternion.h>

namespace prometheus_msgs
{
template <class ContainerAllocator>
struct DroneState_
{
  typedef DroneState_<ContainerAllocator> Type;

  DroneState_()
    : header()
    , connected(false)
    , armed(false)
    , landed(false)
    , mode()
    , time_from_start(0.0)
    , position()
    , velocity()
    , attitude()
    , attitude_q()
    , attitude_rate()  {
      position.assign(0.0);

      velocity.assign(0.0);

      attitude.assign(0.0);

      attitude_rate.assign(0.0);
  }
  DroneState_(const ContainerAllocator& _alloc)
    : header(_alloc)
    , connected(false)
    , armed(false)
    , landed(false)
    , mode(_alloc)
    , time_from_start(0.0)
    , position()
    , velocity()
    , attitude()
    , attitude_q(_alloc)
    , attitude_rate()  {
  (void)_alloc;
      position.assign(0.0);

      velocity.assign(0.0);

      attitude.assign(0.0);

      attitude_rate.assign(0.0);
  }



   typedef  ::std_msgs::Header_<ContainerAllocator>  _header_type;
  _header_type header;

   typedef uint8_t _connected_type;
  _connected_type connected;

   typedef uint8_t _armed_type;
  _armed_type armed;

   typedef uint8_t _landed_type;
  _landed_type landed;

   typedef std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other >  _mode_type;
  _mode_type mode;

   typedef float _time_from_start_type;
  _time_from_start_type time_from_start;

   typedef boost::array<float, 3>  _position_type;
  _position_type position;

   typedef boost::array<float, 3>  _velocity_type;
  _velocity_type velocity;

   typedef boost::array<float, 3>  _attitude_type;
  _attitude_type attitude;

   typedef  ::geometry_msgs::Quaternion_<ContainerAllocator>  _attitude_q_type;
  _attitude_q_type attitude_q;

   typedef boost::array<float, 3>  _attitude_rate_type;
  _attitude_rate_type attitude_rate;





  typedef boost::shared_ptr< ::prometheus_msgs::DroneState_<ContainerAllocator> > Ptr;
  typedef boost::shared_ptr< ::prometheus_msgs::DroneState_<ContainerAllocator> const> ConstPtr;

}; // struct DroneState_

typedef ::prometheus_msgs::DroneState_<std::allocator<void> > DroneState;

typedef boost::shared_ptr< ::prometheus_msgs::DroneState > DroneStatePtr;
typedef boost::shared_ptr< ::prometheus_msgs::DroneState const> DroneStateConstPtr;

// constants requiring out of line definition



template<typename ContainerAllocator>
std::ostream& operator<<(std::ostream& s, const ::prometheus_msgs::DroneState_<ContainerAllocator> & v)
{
ros::message_operations::Printer< ::prometheus_msgs::DroneState_<ContainerAllocator> >::stream(s, "", v);
return s;
}


template<typename ContainerAllocator1, typename ContainerAllocator2>
bool operator==(const ::prometheus_msgs::DroneState_<ContainerAllocator1> & lhs, const ::prometheus_msgs::DroneState_<ContainerAllocator2> & rhs)
{
  return lhs.header == rhs.header &&
    lhs.connected == rhs.connected &&
    lhs.armed == rhs.armed &&
    lhs.landed == rhs.landed &&
    lhs.mode == rhs.mode &&
    lhs.time_from_start == rhs.time_from_start &&
    lhs.position == rhs.position &&
    lhs.velocity == rhs.velocity &&
    lhs.attitude == rhs.attitude &&
    lhs.attitude_q == rhs.attitude_q &&
    lhs.attitude_rate == rhs.attitude_rate;
}

template<typename ContainerAllocator1, typename ContainerAllocator2>
bool operator!=(const ::prometheus_msgs::DroneState_<ContainerAllocator1> & lhs, const ::prometheus_msgs::DroneState_<ContainerAllocator2> & rhs)
{
  return !(lhs == rhs);
}


} // namespace prometheus_msgs

namespace ros
{
namespace message_traits
{





template <class ContainerAllocator>
struct IsFixedSize< ::prometheus_msgs::DroneState_<ContainerAllocator> >
  : FalseType
  { };

template <class ContainerAllocator>
struct IsFixedSize< ::prometheus_msgs::DroneState_<ContainerAllocator> const>
  : FalseType
  { };

template <class ContainerAllocator>
struct IsMessage< ::prometheus_msgs::DroneState_<ContainerAllocator> >
  : TrueType
  { };

template <class ContainerAllocator>
struct IsMessage< ::prometheus_msgs::DroneState_<ContainerAllocator> const>
  : TrueType
  { };

template <class ContainerAllocator>
struct HasHeader< ::prometheus_msgs::DroneState_<ContainerAllocator> >
  : TrueType
  { };

template <class ContainerAllocator>
struct HasHeader< ::prometheus_msgs::DroneState_<ContainerAllocator> const>
  : TrueType
  { };


template<class ContainerAllocator>
struct MD5Sum< ::prometheus_msgs::DroneState_<ContainerAllocator> >
{
  static const char* value()
  {
    return "2e58976f7e6bb6fb3559cb004475bce0";
  }

  static const char* value(const ::prometheus_msgs::DroneState_<ContainerAllocator>&) { return value(); }
  static const uint64_t static_value1 = 0x2e58976f7e6bb6fbULL;
  static const uint64_t static_value2 = 0x3559cb004475bce0ULL;
};

template<class ContainerAllocator>
struct DataType< ::prometheus_msgs::DroneState_<ContainerAllocator> >
{
  static const char* value()
  {
    return "prometheus_msgs/DroneState";
  }

  static const char* value(const ::prometheus_msgs::DroneState_<ContainerAllocator>&) { return value(); }
};

template<class ContainerAllocator>
struct Definition< ::prometheus_msgs::DroneState_<ContainerAllocator> >
{
  static const char* value()
  {
    return "std_msgs/Header header\n"
"\n"
"## 机载电脑是否连接上飞控,true已连接,false则不是\n"
"bool connected\n"
"## 是否解锁,true为已解锁,false则不是\n"
"bool armed\n"
"## 是否降落,true为已降落,false则代表在空中\n"
"bool landed\n"
"## PX4飞控当前飞行模式\n"
"string mode\n"
"\n"
"## 系统启动时间\n"
"float32 time_from_start             ## [s]\n"
"\n"
"## 无人机状态量:位置、速度、姿态\n"
"float32[3] position                 ## [m]\n"
"float32[3] velocity                 ## [m/s]\n"
"float32[3] attitude                 ## [rad]\n"
"geometry_msgs/Quaternion attitude_q ## 四元数\n"
"float32[3] attitude_rate            ## [rad/s]\n"
"================================================================================\n"
"MSG: std_msgs/Header\n"
"# Standard metadata for higher-level stamped data types.\n"
"# This is generally used to communicate timestamped data \n"
"# in a particular coordinate frame.\n"
"# \n"
"# sequence ID: consecutively increasing ID \n"
"uint32 seq\n"
"#Two-integer timestamp that is expressed as:\n"
"# * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')\n"
"# * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')\n"
"# time-handling sugar is provided by the client library\n"
"time stamp\n"
"#Frame this data is associated with\n"
"string frame_id\n"
"\n"
"================================================================================\n"
"MSG: geometry_msgs/Quaternion\n"
"# This represents an orientation in free space in quaternion form.\n"
"\n"
"float64 x\n"
"float64 y\n"
"float64 z\n"
"float64 w\n"
;
  }

  static const char* value(const ::prometheus_msgs::DroneState_<ContainerAllocator>&) { return value(); }
};

} // namespace message_traits
} // namespace ros

namespace ros
{
namespace serialization
{

  template<class ContainerAllocator> struct Serializer< ::prometheus_msgs::DroneState_<ContainerAllocator> >
  {
    template<typename Stream, typename T> inline static void allInOne(Stream& stream, T m)
    {
      stream.next(m.header);
      stream.next(m.connected);
      stream.next(m.armed);
      stream.next(m.landed);
      stream.next(m.mode);
      stream.next(m.time_from_start);
      stream.next(m.position);
      stream.next(m.velocity);
      stream.next(m.attitude);
      stream.next(m.attitude_q);
      stream.next(m.attitude_rate);
    }

    ROS_DECLARE_ALLINONE_SERIALIZER
  }; // struct DroneState_

} // namespace serialization
} // namespace ros

namespace ros
{
namespace message_operations
{

template<class ContainerAllocator>
struct Printer< ::prometheus_msgs::DroneState_<ContainerAllocator> >
{
  template<typename Stream> static void stream(Stream& s, const std::string& indent, const ::prometheus_msgs::DroneState_<ContainerAllocator>& v)
  {
    s << indent << "header: ";
    s << std::endl;
    Printer< ::std_msgs::Header_<ContainerAllocator> >::stream(s, indent + "  ", v.header);
    s << indent << "connected: ";
    Printer<uint8_t>::stream(s, indent + "  ", v.connected);
    s << indent << "armed: ";
    Printer<uint8_t>::stream(s, indent + "  ", v.armed);
    s << indent << "landed: ";
    Printer<uint8_t>::stream(s, indent + "  ", v.landed);
    s << indent << "mode: ";
    Printer<std::basic_string<char, std::char_traits<char>, typename ContainerAllocator::template rebind<char>::other > >::stream(s, indent + "  ", v.mode);
    s << indent << "time_from_start: ";
    Printer<float>::stream(s, indent + "  ", v.time_from_start);
    s << indent << "position[]" << std::endl;
    for (size_t i = 0; i < v.position.size(); ++i)
    {
      s << indent << "  position[" << i << "]: ";
      Printer<float>::stream(s, indent + "  ", v.position[i]);
    }
    s << indent << "velocity[]" << std::endl;
    for (size_t i = 0; i < v.velocity.size(); ++i)
    {
      s << indent << "  velocity[" << i << "]: ";
      Printer<float>::stream(s, indent + "  ", v.velocity[i]);
    }
    s << indent << "attitude[]" << std::endl;
    for (size_t i = 0; i < v.attitude.size(); ++i)
    {
      s << indent << "  attitude[" << i << "]: ";
      Printer<float>::stream(s, indent + "  ", v.attitude[i]);
    }
    s << indent << "attitude_q: ";
    s << std::endl;
    Printer< ::geometry_msgs::Quaternion_<ContainerAllocator> >::stream(s, indent + "  ", v.attitude_q);
    s << indent << "attitude_rate[]" << std::endl;
    for (size_t i = 0; i < v.attitude_rate.size(); ++i)
    {
      s << indent << "  attitude_rate[" << i << "]: ";
      Printer<float>::stream(s, indent + "  ", v.attitude_rate[i]);
    }
  }
};

} // namespace message_operations
} // namespace ros

#endif // PROMETHEUS_MSGS_MESSAGE_DRONESTATE_H

 

我任打开一个其他的话题消息的头文件,每个都写了namespace prometheus_msgs

 

 

我似乎也搜到了对应的头文件

http://docs.ros.org/en/diamondback/api/geometry_msgs/html/Pose_8h_source.html

00001 /* Auto-generated by genmsg_cpp for file /tmp/buildd/ros-diamondback-common-msgs-1.4.0/debian/ros-diamondback-common-msgs/opt/ros/diamondback/stacks/common_msgs/geometry_msgs/msg/Pose.msg */
00002 #ifndef GEOMETRY_MSGS_MESSAGE_POSE_H
00003 #define GEOMETRY_MSGS_MESSAGE_POSE_H
00004 #include <string>
00005 #include <vector>
00006 #include <ostream>
00007 #include "ros/serialization.h"
00008 #include "ros/builtin_message_traits.h"
00009 #include "ros/message_operations.h"
00010 #include "ros/message.h"
00011 #include "ros/time.h"
00012 
00013 #include "geometry_msgs/Point.h"
00014 #include "geometry_msgs/Quaternion.h"
00015 
00016 namespace geometry_msgs
00017 {
00018 template <class ContainerAllocator>
00019 struct Pose_ : public ros::Message
00020 {
00021   typedef Pose_<ContainerAllocator> Type;
00022 
00023   Pose_()
00024   : position()
00025   , orientation()
00026   {
00027   }
00028 
00029   Pose_(const ContainerAllocator& _alloc)
00030   : position(_alloc)
00031   , orientation(_alloc)
00032   {
00033   }
00034 
00035   typedef  ::geometry_msgs::Point_<ContainerAllocator>  _position_type;
00036    ::geometry_msgs::Point_<ContainerAllocator>  position;
00037 
00038   typedef  ::geometry_msgs::Quaternion_<ContainerAllocator>  _orientation_type;
00039    ::geometry_msgs::Quaternion_<ContainerAllocator>  orientation;
00040 
00041 
00042 private:
00043   static const char* __s_getDataType_() { return "geometry_msgs/Pose"; }
00044 public:
00045   ROS_DEPRECATED static const std::string __s_getDataType() { return __s_getDataType_(); }
00046 
00047   ROS_DEPRECATED const std::string __getDataType() const { return __s_getDataType_(); }
00048 
00049 private:
00050   static const char* __s_getMD5Sum_() { return "e45d45a5a1ce597b249e23fb30fc871f"; }
00051 public:
00052   ROS_DEPRECATED static const std::string __s_getMD5Sum() { return __s_getMD5Sum_(); }
00053 
00054   ROS_DEPRECATED const std::string __getMD5Sum() const { return __s_getMD5Sum_(); }
00055 
00056 private:
00057   static const char* __s_getMessageDefinition_() { return "# A representation of pose in free space, composed of postion and orientation. \n\
00058 Point position\n\
00059 Quaternion orientation\n\
00060 \n\
00061 ================================================================================\n\
00062 MSG: geometry_msgs/Point\n\
00063 # This contains the position of a point in free space\n\
00064 float64 x\n\
00065 float64 y\n\
00066 float64 z\n\
00067 \n\
00068 ================================================================================\n\
00069 MSG: geometry_msgs/Quaternion\n\
00070 # This represents an orientation in free space in quaternion form.\n\
00071 \n\
00072 float64 x\n\
00073 float64 y\n\
00074 float64 z\n\
00075 float64 w\n\
00076 \n\
00077 "; }
00078 public:
00079   ROS_DEPRECATED static const std::string __s_getMessageDefinition() { return __s_getMessageDefinition_(); }
00080 
00081   ROS_DEPRECATED const std::string __getMessageDefinition() const { return __s_getMessageDefinition_(); }
00082 
00083   ROS_DEPRECATED virtual uint8_t *serialize(uint8_t *write_ptr, uint32_t seq) const
00084   {
00085     ros::serialization::OStream stream(write_ptr, 1000000000);
00086     ros::serialization::serialize(stream, position);
00087     ros::serialization::serialize(stream, orientation);
00088     return stream.getData();
00089   }
00090 
00091   ROS_DEPRECATED virtual uint8_t *deserialize(uint8_t *read_ptr)
00092   {
00093     ros::serialization::IStream stream(read_ptr, 1000000000);
00094     ros::serialization::deserialize(stream, position);
00095     ros::serialization::deserialize(stream, orientation);
00096     return stream.getData();
00097   }
00098 
00099   ROS_DEPRECATED virtual uint32_t serializationLength() const
00100   {
00101     uint32_t size = 0;
00102     size += ros::serialization::serializationLength(position);
00103     size += ros::serialization::serializationLength(orientation);
00104     return size;
00105   }
00106 
00107   typedef boost::shared_ptr< ::geometry_msgs::Pose_<ContainerAllocator> > Ptr;
00108   typedef boost::shared_ptr< ::geometry_msgs::Pose_<ContainerAllocator>  const> ConstPtr;
00109 }; // struct Pose
00110 typedef  ::geometry_msgs::Pose_<std::allocator<void> > Pose;
00111 
00112 typedef boost::shared_ptr< ::geometry_msgs::Pose> PosePtr;
00113 typedef boost::shared_ptr< ::geometry_msgs::Pose const> PoseConstPtr;
00114 
00115 
00116 template<typename ContainerAllocator>
00117 std::ostream& operator<<(std::ostream& s, const  ::geometry_msgs::Pose_<ContainerAllocator> & v)
00118 {
00119   ros::message_operations::Printer< ::geometry_msgs::Pose_<ContainerAllocator> >::stream(s, "", v);
00120   return s;}
00121 
00122 } // namespace geometry_msgs
00123 
00124 namespace ros
00125 {
00126 namespace message_traits
00127 {
00128 template<class ContainerAllocator>
00129 struct MD5Sum< ::geometry_msgs::Pose_<ContainerAllocator> > {
00130   static const char* value() 
00131   {
00132     return "e45d45a5a1ce597b249e23fb30fc871f";
00133   }
00134 
00135   static const char* value(const  ::geometry_msgs::Pose_<ContainerAllocator> &) { return value(); } 
00136   static const uint64_t static_value1 = 0xe45d45a5a1ce597bULL;
00137   static const uint64_t static_value2 = 0x249e23fb30fc871fULL;
00138 };
00139 
00140 template<class ContainerAllocator>
00141 struct DataType< ::geometry_msgs::Pose_<ContainerAllocator> > {
00142   static const char* value() 
00143   {
00144     return "geometry_msgs/Pose";
00145   }
00146 
00147   static const char* value(const  ::geometry_msgs::Pose_<ContainerAllocator> &) { return value(); } 
00148 };
00149 
00150 template<class ContainerAllocator>
00151 struct Definition< ::geometry_msgs::Pose_<ContainerAllocator> > {
00152   static const char* value() 
00153   {
00154     return "# A representation of pose in free space, composed of postion and orientation. \n\
00155 Point position\n\
00156 Quaternion orientation\n\
00157 \n\
00158 ================================================================================\n\
00159 MSG: geometry_msgs/Point\n\
00160 # This contains the position of a point in free space\n\
00161 float64 x\n\
00162 float64 y\n\
00163 float64 z\n\
00164 \n\
00165 ================================================================================\n\
00166 MSG: geometry_msgs/Quaternion\n\
00167 # This represents an orientation in free space in quaternion form.\n\
00168 \n\
00169 float64 x\n\
00170 float64 y\n\
00171 float64 z\n\
00172 float64 w\n\
00173 \n\
00174 ";
00175   }
00176 
00177   static const char* value(const  ::geometry_msgs::Pose_<ContainerAllocator> &) { return value(); } 
00178 };
00179 
00180 template<class ContainerAllocator> struct IsFixedSize< ::geometry_msgs::Pose_<ContainerAllocator> > : public TrueType {};
00181 } // namespace message_traits
00182 } // namespace ros
00183 
00184 namespace ros
00185 {
00186 namespace serialization
00187 {
00188 
00189 template<class ContainerAllocator> struct Serializer< ::geometry_msgs::Pose_<ContainerAllocator> >
00190 {
00191   template<typename Stream, typename T> inline static void allInOne(Stream& stream, T m)
00192   {
00193     stream.next(m.position);
00194     stream.next(m.orientation);
00195   }
00196 
00197   ROS_DECLARE_ALLINONE_SERIALIZER;
00198 }; // struct Pose_
00199 } // namespace serialization
00200 } // namespace ros
00201 
00202 namespace ros
00203 {
00204 namespace message_operations
00205 {
00206 
00207 template<class ContainerAllocator>
00208 struct Printer< ::geometry_msgs::Pose_<ContainerAllocator> >
00209 {
00210   template<typename Stream> static void stream(Stream& s, const std::string& indent, const  ::geometry_msgs::Pose_<ContainerAllocator> & v) 
00211   {
00212     s << indent << "position: ";
00213 s << std::endl;
00214     Printer< ::geometry_msgs::Point_<ContainerAllocator> >::stream(s, indent + "  ", v.position);
00215     s << indent << "orientation: ";
00216 s << std::endl;
00217     Printer< ::geometry_msgs::Quaternion_<ContainerAllocator> >::stream(s, indent + "  ", v.orientation);
00218   }
00219 };
00220 
00221 
00222 } // namespace message_operations
00223 } // namespace ros
00224 
00225 #endif // GEOMETRY_MSGS_MESSAGE_POSE_H
00226 

细看一下它类里面其实就是写个结构体,所以可以像下面这么写

geometry_msgs::Pose pose

pose.position.x

pose是对象名,position可能是结构体,感觉似乎又不对

 

讲道理一个消息就是一种类,你包含了其他的消息就是包含了其他的类啊,

所以你看pose这个消息的头文件里面是include了的poin和quaternion这两个消息的头文件的

上面写的struct似乎也是定义类的。

这应该就是一个函数。这应该是多重继承的写法

http://m.biancheng.net/view/2277.html

这也应该是继承的写法。

我想起java是不能多重继承的,得用接口,是不是C++可以多重继承。

而且我刚刚发现上面正是多重继承下的构造函数!!!!!Pose_()正是构造函数!!!!!

http://m.biancheng.net/view/2277.html

所以ROS里面一个消息类型是由其他小消息类型组合而成的,在C++层面上是通过多重继承实现的。

 

 

 

 

 

http://docs.ros.org/en/diamondback/api/geometry_msgs/html/PoseStamped_8h.html

 

 

从这里也可以看出  geometry_msgs  确实就是个功能包,我理解得没有错,话题消息的定义都是写在一个专门的功能包里面的

http://wiki.ros.org/geometry_msgs

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值