micro-ROS / micro_ros_arduino

micro-ROS library for Arduino
Apache License 2.0
449 stars 117 forks source link

Communication with a simple publisher code with ARDUINO DUE and micro ros #1868

Open Minaygt opened 3 days ago

Minaygt commented 3 days ago

Issue template

Steps to reproduce the issue

Expected behavior

i'm running an agent with docker. sudo docker run -it --rm -v /dev:/dev --privileged --net=host microros/micro-ros-agent:humble serial --dev /dev/ttyACM0 -v6 I have a publisher code, I'm running this code with python. I'm waiting for the data I put on the Arduino to arrive.

Actual behavior

I'm getting error from Arduino "/home/mina/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-gcc" -mcpu=cortex-m3 -mthumb -Os -Wl,--gc-sections "-T/home/mina/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/linker_scripts/gcc/flash.ld" "-Wl,-Map,/tmp/arduino_build_390385/basic.ino.ino.map" -o "/tmp/arduino_build_390385/basic.ino.ino.elf" "-L/tmp/arduino_build_390385" -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--start-group -u _sbrk -u link -u _close -u _fstat -u _isatty -u _lseek -u _read -u _write -u _exit -u kill -u _getpid "/tmp/arduino_build_390385/sketch/basic.ino.ino.cpp.o" "/tmp/arduino_build_390385/libraries/micro_ros_arduino-2.0.7-humble/default_transport.cpp.o" "/tmp/arduino_build_390385/libraries/micro_ros_arduino-2.0.7-humble/native_ethernet_transport.cpp.o" "/tmp/arduino_build_390385/libraries/micro_ros_arduino-2.0.7-humble/wifi_transport.cpp.o" "/tmp/arduino_build_390385/core/variant.cpp.o" "/home/mina/.arduino15/packages/arduino/hardware/sam/1.6.12/variants/arduino_due_x/libsam_sam3x8e_gcc_rel.a" "/tmp/arduino_build_390385/../arduino_cache_577918/core/core_arduino_sam_arduino_due_x_7e293e264b1e0312c8d5597ef3b45ebf.a" -Wl,--end-group -lm -lgcc /tmp/arduino_build_390385/sketch/basic.ino.ino.cpp.o: In functionloop': /home/mina/Arduino/basic.ino/basic.ino.ino:54: undefined reference to rclc_executor_spin_some' /tmp/arduino_build_390385/sketch/basic.ino.ino.cpp.o: In functionset_microros_transports': /home/mina/Arduino/libraries/micro_ros_arduino-2.0.7-humble/src/micro_ros_arduino.h:40: undefined reference to rmw_uros_set_custom_transport' /tmp/arduino_build_390385/sketch/basic.ino.ino.cpp.o: In functionsetup': /home/mina/Arduino/basic.ino/basic.ino.ino:33: undefined reference to rclc_support_init' /home/mina/Arduino/basic.ino/basic.ino.ino:36: undefined reference torclc_node_init_default' /home/mina/Arduino/basic.ino/basic.ino.ino:43: undefined reference to rosidl_typesupport_c__get_message_type_support_handle__std_msgs__msg__Float32' /home/mina/Arduino/basic.ino/basic.ino.ino:43: undefined reference torclc_subscription_init_default' /home/mina/Arduino/basic.ino/basic.ino.ino:46: undefined reference to rclc_executor_init' /home/mina/Arduino/basic.ino/basic.ino.ino:47: undefined reference torclc_executor_add_subscription' collect2: error: ld returned 1 exit status Using library micro_ros_arduino-2.0.7-humble at version 2.0.7-humble in folder: /home/mina/Arduino/libraries/micro_ros_arduino-2.0.7-humble exit status 1 Error compiling for board Arduino Due (Native USB Port).`

Additional information

My python code = ` import rclpy from rclpy.node import Node

      from std_msgs.msg import Float32

  class MinimalPublisher(Node):

      def __init__(self):
          super().__init__('minimal_publisher')
          self.publisher_ = self.create_publisher(Float32, 'topic', 10)
          timer_period = 0.5  # seconds
          self.timer = self.create_timer(timer_period, self.timer_callback)
          self.i = 0

      def timer_callback(self):
          msg = Float32()
          msg.data = 4.1
          self.publisher_.publish(msg)
          self.get_logger().info('Publishing: "%s"' % msg.data)
          self.i += 1

  def main(args=None):
      rclpy.init(args=args)

      minimal_publisher = MinimalPublisher()

      rclpy.spin(minimal_publisher)

      # Destroy the node explicitly
      # (optional - otherwise it will be done automatically
      # when the garbage collector destroys the node object)
      minimal_publisher.destroy_node()
      rclpy.shutdown()

  if __name__ == '__main__':
      main()

`

My Arduino code

`

include

      #include <rcl/rcl.h>
      #include <rclc/executor.h>
      #include <rclc/rclc.h>
      #include <std_msgs/msg/float32.h>

  rcl_subscription_t subscriber;
  std_msgs__msg__Float32 received_msg;
  rclc_executor_t executor;
  rcl_node_t node;
  rclc_support_t support;  

  void subscription_callback(const void *msgin)
  {
      const std_msgs__msg__Float32 *msg = (const std_msgs__msg__Float32 *)msgin;
      Serial.print("Alınan Değer: ");
      Serial.println(msg->data);
  }

  void setup()
  {
      Serial.begin(115200);
      delay(2000);

      set_microros_transports();  

      const char * arguments[] = {"arduino_due_subscriber"};
      rclc_support_init(&support, 0, arguments, NULL);  
      // Node başlatma
      rclc_node_init_default(&node, "arduino_due_subscriber", nullptr, &support);

      rclc_subscription_init_default(
          &subscriber,
          &node,
          ROSIDL_GET_MSG_TYPE_SUPPORT(std_msgs, msg, Float32),
          "topic");

      rclc_executor_init(&executor, &support.context, 1, NULL);
      rclc_executor_add_subscription(&executor, &subscriber, &received_msg, &subscription_callback, ON_NEW_DATA);
  }

  void loop()
  {
      rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100));
  }

`

THANK YOU!
hippo5329 commented 2 days ago

You cannot use serial print and micro-ros serial transport at the same time.