micro-ROS / freertos_apps

Sample applications for FreeRTOS + micro-ROS
Apache License 2.0
81 stars 50 forks source link

How can I increase the size of the data inside a message to be published? #59

Closed slahrberg closed 3 years ago

slahrberg commented 3 years ago

Following the apps/image_publisher/ example application I want to publish audio data. For now I just use dummy data. This code will work with 1024 elements. As soon as I change this to 2014*2 or larger, the publisher will fail. RCSOFTCHECK gives me: "Failed status on line 201: 1. Continuing.". I searched for the meaning of this error code, but it seems to be a generic error, which doesn't help me. Allocating with malloc does not fail, which I am checking with the print statement.

This is how I create my message:

    int ELEMENTS = 1024*1;
    msg->audio_data.capacity = ELEMENTS * sizeof(uint8_t);
    printf("allocating %d\n", msg->audio_data.capacity);
    msg->audio_data.data = (uint8_t *) malloc(msg->audio_data.capacity);
    if(msg->audio_data.data == NULL){
        printf("malloc failed!");
    }else{
        printf("malloc succeded!");
    }
    memset(msg->audio_data.data, 0x24, msg->audio_data.capacity);

    msg->audio_data.size = msg->audio_data.capacity;
    msg->sampling_rate = 16000;
    msg->chunk_width = 1024;
    msg->sample_size = 16;`

Which is then published with a timer:

void timer_callback(rcl_timer_t * timer, int64_t last_call_time)
{
    RCLC_UNUSED(last_call_time);
    if (timer != NULL) {
        printf("Publishing some data.\n");
        RCSOFTCHECK(rcl_publish(&publisher, msg, NULL));
    }
}

I have found other issues for example this one: https://github.com/micro-ROS/rmw-microxrcedds/issues/53 where a similar problem is being discussed. I tried changing my app-colcon.meta to set the history and MTU values with no change.

{
    "names": {
        "rmw_microxrcedds": {
            "cmake-args": [
                "-DRMW_UXRCE_MAX_NODES=1",
                "-DRMW_UXRCE_MAX_PUBLISHERS=1",
                "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=0",
                "-DRMW_UXRCE_MAX_SERVICES=0",
                "-DRMW_UXRCE_MAX_CLIENTS=0",
                "-DRMW_UXRCE_MAX_HISTORY=16",
                "-DRMW_UXRCE_STREAM_HISTORY=16",
            ]
        },
        "microxrcedds_client": {
            "cmake-args": [
                "-DUCLIENT_UDP_TRANSPORT_MTU=4096",
            ]
        }
    }
}

I have also changed a line in /firmware/mcu_ws/eProsima/Micro-XRCE-DDS-Client/CMakeLists.txt so now it says : set(UCLIENT_UDP_TRANSPORT_MTU 4096 CACHE STRING "Set the UDP transport MTU.") . This has changed nothing.

Am I editing the wrong files or is my problem somewhere else?

pablogs9 commented 3 years ago

Which type is your message?

slahrberg commented 3 years ago

I created a custom message type:

uint8[] audio_data,
uint16 sampling_rate,
uint16 chunk_width,
uint8 sample_size
pablogs9 commented 3 years ago

Does it work if you send audio_data with for example 10 elements?

slahrberg commented 3 years ago

I have tested with 3 elements and 1024, both work. Any multiplier of 1024 will not work. Btw: Is there a way to get a more precise error code from RCSOFTCHECK?

pablogs9 commented 3 years ago

Well, it should be fixed increasing DUCLIENT_UDP_TRANSPORT_MTU and/or DRMW_UXRCE_STREAM_HISTORY... the point is have you rebuilt the library?

Maybe it is still built with the default 512 B and 4 history slots, please try to rebuild the microros library from scratch and if it does not work I'll provide an example.

pablogs9 commented 3 years ago

Any update on this?

slahrberg commented 3 years ago

Sorry for the late answer to this issue. Yes, I got it working. I wasn't aware that i need to run the ros2 run micro_ros_setup configure_firmware.sh command in order for the changes to the parameters to have an effect. I thought building the app itself was enough. I guess this is what you meant with "rebuilding the library". Thank you for helping me.