Convert long to int32

Hi,

I have ESP32 programmed to talk to ROS. ROS subscribes to encoder data from Arduino. I am using the below integer type.

#include <std_msgs/Int32.h>
std_msgs::Int32 encoder_msg

On the Arduino side, I have an encoder count is an array or type 'long'. When I use the below statement on Arduino, it throws an error.

encoder_msg = (int32_t)pos[0];

no match for 'operator=' (operand types are 'std_msgs::Int32' and 'int32_t' {aka 'int'})

Can someone please help out in getting these messages out? I tried type casting to (std_msgs::Int32), but it does not seem to work.

where is encoder_msg_f1 defined (i.e. what is it)?

Typo. Its

encoder_msg

I have corrected in the original post.

???

On the Arduino Uno (and other ATmega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1).

try accessing .data

I am not sure what you mean by accessing it. This is what the deceleration is. Isnt long same as Int32?

  class Int32 : public ros::Msg
  {
    public:
      typedef int32_t _data_type;
      _data_type data;

    Int32():
      data(0)
    {
    }

@gcjr , its defined here:

std_msgs::Int32 encoder_msg

@Idahowalker , I am using Int32 which is as per my assumption long.


encoder_msg.data = (int32_t)pos[0];

Perfect. It worked. Thank you. It compiles well.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.