2016-01-08 43 views
1

我的ROS消息對ROS發送數組c很簡單:使用郵件

int8[64] packet1 

我在我的談話節點與發佈方:

terp::Packet1 msg; 
msg.packet1={0,1,0,1,0,1}; 
ROS_INFO("Packet in string form: %s", msg->packet1); 
chatter_pub.publish(msg); 
ros::spinOnce(); 

我在我的聽力節點檢索與:

void resolve_input1(const uint8_t msg[]) { 
    if (sizeof(msg->packet1)/sizeof(msg->packet1[0])<MAX_MSG_LEN) { 
    memcpy(msg1,msg->packet1); 
    ROS_INFO("I heard: [%s]\n",msg1); 
    } else 
    ROS_ERROR("Message from node 1 too long"); 
} 

但是,在進行項目時,我收到以下錯誤:

listener.cpp:16:19: error: request for member 'packet1' in '*msg', 
which is of non-class type 'const uint8_t {aka const unsigned char} 
    if (sizeof(msg->packet1)/sizeof(msg->packet1[0])<MAX_MSG_LEN) { 

更改resolve_input1的聲明:

void resolve_input1(const terp::Packet1 msg) { 

編輯: 擺脫了這個錯誤,但現在一個新的出現,這是類似;強調我的困惑有關消息:

listener.cpp:16:17 error: base operand of '->' has non-pointer type 
'const Packet1 {aka const terp::Packet1_<std::allocator<void> >}' 
    if (sizeof(msg->packet1)/sizeof(msg->packet1[0])<MAX_MSG_LEN) { 
       ^
+0

你的代碼沒有意義,msg是一個數組,你試圖訪問它的一個成員,它不存在(在「msg-> packet1」中)。 –

+1

我相信ROS消息(即* .msg文件)被編譯成源代碼並通過catkin_make鏈接到一個項目。在那個過程中,消息變成一個結構。 – errolflynn

回答

1

resolve_input1msgconst uint8_t*類型的,所以你訪問字段之前可能要reinterpret_castconst terp::Packet1*

更新: 鑑於您的編輯,只是改變msg->msg.

+0

你可否詳細說明reinterpret_cast? – errolflynn