micro_ros_arduino: Int64MultiArray subscriber not working

Issue template

using OpenCR to control dynamixels. The subscriber(Int64MultiArray) is not working. When I change the message type to Int32 it is working. I read the documentation and initialized the array(mentioned below). kindly inform me how to implement it.

int64_t array_tic[2]= {left_tick,right_tick};
int64_t value[10] = {0,0,0,0,0,0,0,0,0,0};

goal_vel = std_msgs__msg__Int64MultiArray__create();
      goal_vel->data.capacity = 10;
      goal_vel->data.data = (int64_t*)malloc(goal_vel->data.capacity * sizeof(int64_t));
      goal_vel->data.size = sizeof(value)/sizeof(int64_t);memcpy(goal_vel->data.data, value,sizeof(value));
//            
      ticks = std_msgs__msg__Int64MultiArray__create();  
      ticks->data.capacity = 2;
      ticks->data.data = (int64_t*)malloc(sizeof(array_tic));   
      ticks->data.size = sizeof(array_tic)/sizeof(int64_t);memcpy(ticks->data.data,array_tic,sizeof(array_tic));

//////Callback function:

void subscription_callback(const void * msgin)
{  
    const std_msgs__msg__Int64MultiArray * goal_vel = (const std_msgs__msg__Int64MultiArray *)msgin;
    int64_t left_front; 
    
//    value[0] = int64_t(goal_vel->data.data[0]);    
    //left_front = int32_t(msg->data);
    dxl.setGoalVelocity(DXL_ID,value[0]);
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

That’s correct, you need to init all the members of the type recursively:

std_msgs__msg__Int64MultiArray msg;

msg.data.capacity = 100; 
msg.data.size = 0;
msg.data.data = (int64_t*) malloc(msg.data.capacity * sizeof(int64_t));

msg.layout.dim.capacity = 100;
msg.layout.dim.size = 0;
msg.layout.dim.data = (std_msgs__msg__MultiArrayDimension*) malloc(msg.layout.dim.capacity * sizeof(std_msgs__msg__MultiArrayDimension));

for(size_t i = 0; i < msg.layout.dim.capacity; i++){
    msg.layout.dim.data[i].label.capacity = 20;
    msg.layout.dim.data[i].label.size = 0;
    msg.layout.dim.data[i].label.data = (char*) malloc(msg.layout.dim.data[i].label.capacity * sizeof(char));
}

Remember that if you are using micro-ROS Galactic you have available micro_ros_utilities that can be used as explained here.

HI,

Thanks a lot for the example. It is working fine.

Sorry for the late reply.