0
$\begingroup$

Rosanswers logo

Can anyone please point me to the documentation of how to add extra_packages to a platformio project? My project is currently built via the below commands in platformio:

pio lib install # Install dependencies
pio run # Build the firmware
pio run --target upload # Flash the firmware

I'm developing for micro-ROS, but there are gaps in the library and it seems impossible to find how to add custom packages. As above mentioned, I'm not using colcon build ... as one would normally when developing for ROS2, since I'm building with platformio for micro-ROS.

I do understand I need to "place" any additional packages into the "/workspace/extra_packages/" directory. But there are no clear instructions on how to achieve this, so that dependencies are properly established.

As per the documentation: https://github.com/micro-ROS/micro_ros_platformio#extra-packages

Extra packages

Colcon packages can be added to the build process using this two methods:

    Package directories copied on the <Project_directory>/extra_packages folder.
    Git repositories included on the <Project_directory>/extra_packages/extra_packages.repos yaml file.

This should be used for example when adding custom messages types or custom micro-ROS packages.

I have the following:

 1. copy the "example_interfaces" directory (ros2/example_interfaces) into /workspace/extra_packages
 2. used git clone in the empty /workspace/extra_packages on another attempt

In both cases I manually went through the included .h files and fixed all "path-issues" where there have been red squiggles (as you might be familiar with the syntax highlighting and error indication in VS-Code)

But still when using the above "build-steps" it fails with the following message:

.pio/build/teensy41/src/main.cpp.o: In function `setup': main.cpp:(.text.setup+0x54): undefined reference to `rosidl_typesupport_c__get_service_type_support_handle__example_interfaces__srv__AddTwoInts' collect2: error: ld returned 1 exit status *** [.pio/build/teensy41/firmware.elf] Error 1

And yes I did do a clean before, also deleted the .pio directory to force re-download of everything and also followed the pio run --target clean_microros # Clean library

But whatever I try, it simply won't compile. The entire source code can be found below. Attempt here is to create a simple service to add two numbers.

#include <Arduino.h>
#include <Wire.h>
#include <micro_ros_platformio.h>
#include <../extra_packages/example_interfaces/srv/add_two_ints.h>
#include <stdio.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#include <std_msgs/msg/int64.h>

rcl_node_t node;
rclc_support_t support;
rcl_allocator_t allocator;
rclc_executor_t executor;

rcl_service_t service;
rcl_wait_set_t wait_set;

example_interfaces__srv__AddTwoInts_Response res;
example_interfaces__srv__AddTwoInts_Request req;

#define RCCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){while(1){};}}
#define RCSOFTCHECK(fn) { rcl_ret_t temp_rc = fn; if((temp_rc != RCL_RET_OK)){}}

void service_callback(const void * req, void * res){
  example_interfaces__srv__AddTwoInts_Request * req_in = (example_interfaces__srv__AddTwoInts_Request *) req;
  example_interfaces__srv__AddTwoInts_Response * res_in = (example_interfaces__srv__AddTwoInts_Response *) res;

  //printf("Service request value: %d + %d.\n", (int) req_in->a, (int) req_in->b);

  res_in->sum = req_in->a + req_in->b;
}

void setup() {
  //set_microros_transports();
  set_microros_serial_transports(Serial);
  delay(1000); 

  allocator = rcl_get_default_allocator();

  // create init_options
  RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));

  // create node
  RCCHECK(rclc_node_init_default(&node, "add_twoints_client_rclc", "", &support));

  // create service
  RCCHECK(rclc_service_init_default(&service, &node, ROSIDL_GET_SRV_TYPE_SUPPORT(example_interfaces, srv, AddTwoInts), "/addtwoints"));

  // create executor
  RCCHECK(rclc_executor_init(&executor, &support.context, 1, &allocator));
  RCCHECK(rclc_executor_add_service(&executor, &service, &req, &res, service_callback));
}


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

I do believe the solution is rather simple and won't take much effort by a seasoned expert. Whoever the forthcoming, generous expert will be, please let me know, how I can thank you and buy a coffee for your troubles.


Originally posted by PointCloud on ROS Answers with karma: 120 on 2022-10-15

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Closed! Thanks to Acuadros95. Here is what needed to be done to successfully add the example_interface package.

  1. clone the correct branch into ws/extra_packages -> git clone -b humble https://github.com/ros2/example_interfaces.git
  2. ensure the package.xml file is not missing
  3. clean
  4. delete .pio directory (alternatively: pio run --target clean_microros)
  5. pio lib install
  6. pio run

==> compiled without errors, took a while, didn't try to hold my breath (wouldn't be writing this)

Looking forward to merging this back as an example


Originally posted by PointCloud with karma: 120 on 2022-10-19

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.