2017-02-11 3 views
2

ROS 데이터 타입 Float64MultiArray을 사용하는 C++ Arduino 스케치를 컴파일하려고합니다. examples은 다음과 같이 초기화해야한다고 말합니다 :Non-class 타입의 Float64MultiArray에서 'resize'멤버에 대한 요청

std_msgs::Float64MultiArray array_msg; 
array_msg.data.resize(9); 

하지만, 내 최소한의 스케치를 컴파일하려고 :

main.ino: In function 'void setup()': 
main.ino:6:19: error: request for member 'resize' in 'vec3_msg.std_msgs::Float64MultiArray::data', which is of non-class type 'std_msgs::Float64MultiArray::_data_type* {aka float*}' 
    vec3_msg.data.resize(3); 
       ^
:

#include <std_msgs/Float64MultiArray.h> 

std_msgs::Float64MultiArray vec3_msg; 

void setup() { 
    vec3_msg.data.resize(3); 
} 

void loop() { 
} 

나에게 오류를 제공

내가 뭘 잘못하고 있니? (볼이 때문에 아두 이노 특이성에, 일반 float 배열 가능성이 디폴트,

The message structure has a single field called data which can be treated as a std::vector type in your C++ node.

을하지만 그 기본이되는 std::vector -like 구현을 사용하는 대신에 있기 때문에, 귀하의 경우에는 적용되지 않습니다

답변

2

예는 상태 rosserial).

다른 일반 배열과 마찬가지로 vec3_msg.data과 작업해야합니다. 따라서 :

vec3_msg.data = (float*)malloc(sizeof(float) * 9); 
for (int i = 0; i < 9; ++i) 
{ 
    vec3_msg.data[i] = someValue; 
} 

은 편도입니다.

어딘가에서 작업하는 정적 배열을 유지하고 메시지의 데이터를 가리 키기를 원할 수도 있습니다.

float myGlobalArray[9]; 

setup() 
{ 
    vec3_msg.data = myGlobalArray; 
} 

// change myGlobalArray here and the 
// data will update too. 

귀하의 경우에 대비하여 vec3_msg.data_length을 9로 설정해야합니다. 추가 정보는 this answerMultiArrayLayout docs을 참조하십시오.

+0

스폿이 켜져 있습니다. 라이브러리에서 구현을 전환한다고 언급 한 문서는 없지만 그렇게 할 수도 있습니다. – Cerin