micro-ROS / freertos_apps

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

Float64 msg Support #58

Closed Kelly-Coffey closed 3 years ago

Kelly-Coffey commented 3 years ago

Hello, I have a new feature suggestion for a new example. Do you have any examples, using any RTOS, using topics with Float64 data?

I am using the TIMx encoder hardware from the STM32F407 on the Olimex board to populate a sensor_msgs/JointState.msg.

http://docs.ros.org/en/melodic/api/sensor_msgs/html/msg/JointState.html

The firmware encoder data is float, but the JointState,position and JointState.velocity are float64.

Casting doesn’t to work to assign the fw encoder data to the msg data. Any suggestions how to configure to solve?

I have an imu publisher working with float data without any problems.

Thanks for your time…

pablogs9 commented 3 years ago

Why does casting does not work?

JointState.velocity is an array of doubles: float64[], have you tried to initialize it like:

#define ARRAY_SIZE 1

sensor_msgs__msg__JointState msg;
msg.velocity.capacity = ARRAY_SIZE;
msg.velocity.size = ARRAY_SIZE;

// Using static memory
static double buffer[ARRAY_SIZE]
msg.velocity.data = buffer;

// Using dinamic memory
msg.velocity.data = (double*) malloc(ARRAY_SIZE*sizeof(double));

// Using just one data if ARRAY_SIZE == 1
double my_data = 3.14;
msg.velocity.data = &my_data;

Have you tried something like this?

Kelly-Coffey commented 3 years ago

I have not, I will give this a try and report back. Thank you for the guidance.

Kelly-Coffey commented 3 years ago

I verified both your static and dynamic examples compile and run. Thank you for the examples.