rosserial STM32 wrong checksum for topic id and msg

asked 2021-01-17 03:37:20 -0500

Roman41 gravatar image

updated 2021-01-18 03:50:35 -0500

I am trying to use rosserial for STM32F411 discovery board. I successfully publish the std_msgs/string type message, but as soon as I changed the msgs type to sensor_msgs/Imu, got the error saying "wrong checksum for topic id and msg". here

Followed the rosserial for STM32 from github rosserial_stm32 the code snippet of main.cpp is as below:

  #include "main.h"
#include "ros.h"
#include <stdio.h>
#include "std_msgs/String.h"
#include "stm32f4xx_hal.h"
#include "sensor_msgs/Imu.h"
#include "tf/transform_broadcaster.h"

I2C_HandleTypeDef hi2c1;

UART_HandleTypeDef huart2;
DMA_HandleTypeDef hdma_usart2_rx;
DMA_HandleTypeDef hdma_usart2_tx;

void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_I2C1_Init(void);
static void MX_USART2_UART_Init(void);

RawData_Def myAccelRaw, myGyroRaw;
ScaledData_Def myAccelScaled, myGyroScaled;


int main(void)
{
  /* USER CODE BEGIN 1 */
    ros::NodeHandle nh;


       sensor_msgs::Imu imu_raw; // sensor messages - named imu_raw
       ros::Publisher imu("imu", &imu_raw);


    geometry_msgs::TransformStamped t;
    tf::TransformBroadcaster imu_broadcaster;

    char base_link[] = "/base_link";
    char odom[] = "/odom";
    char frameid[] = "/imu";

  HAL_Init();

  SystemClock_Config();

  MX_GPIO_Init();
  MX_DMA_Init();
  MX_I2C1_Init();
  MX_USART2_UART_Init();
  MPU6050_Init(&hi2c1);

  myMpuConfig.Accel_Full_Scale = AFS_SEL_4g;
  myMpuConfig.ClockSource = Internal_8MHz;
  myMpuConfig.CONFIG_DLPF = DLPF_184A_188G_Hz;
  myMpuConfig.Gyro_Full_Scale = FS_SEL_500;
  myMpuConfig.Sleep_Mode_Bit = 0;  //1: sleep mode, 0: normal mode
  MPU6050_Config(&myMpuConfig);

  nh.initNode();
  nh.advertise(imu);
  imu_broadcaster.init(nh);
  nh.negotiateTopics();

  t.header.frame_id = odom;
  t.child_frame_id = base_link;


  uint8_t seq = 0;
  imu_raw.header.frame_id = frameid;

  while (!nh.connected())
         nh.spinOnce();

  while (1)
  {
    /* USER CODE END WHILE */
      if(nh.connected())
      {

         t.header.frame_id = odom;
         t.child_frame_id = base_link;

         t.transform.translation.x = 1.0;
         t.transform.rotation.x = 0.0;
         t.transform.rotation.y = 0.0;
         t.transform.rotation.z = 0.0;
         t.transform.rotation.w = 1.0;
                 t.header.stamp = nh.now();

          imu_raw.header.seq = seq;


          imu_raw.orientation_covariance[0] = -1;
          imu_raw.orientation.x = 0;
          imu_raw.orientation.y = -1;
          imu_raw.orientation.z = -5;
          imu_raw.orientation.w = 6;

          imu_raw.linear_acceleration_covariance[0] = -1;

         imu_raw.linear_acceleration.x = 0.01;
         imu_raw.linear_acceleration.y = 0.02;
         imu_raw.linear_acceleration.z = 0.03;

         imu_raw.angular_velocity_covariance[0] = -1;
         imu_raw.angular_velocity.x = 0.5;
         imu_raw.angular_velocity.y = 0.6;
         imu_raw.angular_velocity.z = 0.7;

         imu_broadcaster.sendTransform(t);
         imu_raw.header.stamp = nh.now();
         imu.publish(&imu_raw);


         nh.spinOnce();
         HAL_Delay(1000);
      }

  }

  return 0;
}
edit retag flag offensive close merge delete

Comments

Imu messages are much larger than simple Strings. Have you checked the buffer size?

There are quite a few Q&As about this topic here on ROS Answers. I would suggest you search for those and see whether they help.

gvdhoorn gravatar image gvdhoorn  ( 2021-01-17 04:46:25 -0500 )edit

@gvdhoorn, I already tried changing buffer size still didn't see any improvement.

Roman41 gravatar image Roman41  ( 2021-01-17 06:37:08 -0500 )edit

Where do you mention that in your question text?

gvdhoorn gravatar image gvdhoorn  ( 2021-01-17 07:04:07 -0500 )edit

@gvdhoorn I forget to mention that but now I have edited the above code snippet in which I have added the frameId for the Imu. While running this I do get the sensor data for once but in slow rate, again I start getting the same INFO message.

Roman41 gravatar image Roman41  ( 2021-01-18 03:52:38 -0500 )edit