Scottapotamas / xsens-mti

C library for managing and reading xsens MTi IMU modules over serial.
Apache License 2.0
40 stars 5 forks source link

Issue with compiling for Arduino. #1

Closed niteshglx closed 2 years ago

niteshglx commented 2 years ago

I get this error every time I try to compile the example in basics. Any help with this?

image

Scottapotamas commented 2 years ago

A couple of things:

  1. I can't remember if I actually ran that example on hardware or just wrote it based on the basic example on another (non-Arduino) micro.
  2. I didn't include a library.properties, so working with this library in the Arduino IDE wouldn't have been a wonderful experience for you?
  3. The basics example/this library has a default configuration that uses just a bit too RAM for an Arduino UNO target. I can probably reduce this with a few seconds of work if you need to use a constrained target like a 328p!

The actual fault is talking about use of designated initalisers - supported in C, but not C++ which is what Arduino's assume as the default. Saying that, I don't think I used them in this library.

Try to get a better error message out of the Arduino IDE by configuring the compiler warnings

image

niteshglx commented 2 years ago
  1. That's okay, I can do that testing for you, I have a mti-7 and mti-1 dk boards for testing. If you want I can help you with updating this repo with that as well.
  2. I haven't really fiddled with it much, just tried to run your example code before dwelling further.
  3. That would be very helpful actually, for now I am just trying to get some output, although I do want to enable GPS functionality as well so later on I was thinking of using the ESP32 for this.

These are the errors I am getting with those options enabled

Arduino: 1.8.19 (Linux), Board: "Arduino Uno"

/home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/arduino-builder -dump-prefs -logger=machine -hardware /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/hardware -hardware /home/xxxx/.arduino15/packages -tools /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/tools-builder -tools /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/hardware/tools/avr -tools /home/xxxx/.arduino15/packages -built-in-libraries /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/libraries -libraries /home/xxxx/Arduino/libraries -fqbn=arduino:avr:uno -ide-version=10819 -build-path /tmp/arduino_build_50173 -warnings=default -build-cache /tmp/arduino_cache_763322 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=/home/xxxx/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/xxxx/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=/home/xxxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/xxxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -verbose /home/xxxx/Arduino/ins_test/ins_test.ino /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/arduino-builder -compile -logger=machine -hardware /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/hardware -hardware /home/xxxx/.arduino15/packages -tools /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/tools-builder -tools /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/hardware/tools/avr -tools /home/xxxx/.arduino15/packages -built-in-libraries /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/libraries -libraries /home/xxxx/Arduino/libraries -fqbn=arduino:avr:uno -ide-version=10819 -build-path /tmp/arduino_build_50173 -warnings=default -build-cache /tmp/arduino_cache_763322 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=/home/xxxx/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=/home/xxxx/.arduino15/packages/arduino/tools/arduinoOTA/1.3.0 -prefs=runtime.tools.avr-gcc.path=/home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=/home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=/home/xxxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=/home/xxxx/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17 -verbose /home/xxxx/Arduino/ins_test/ins_test.ino Using board 'uno' from platform in folder: /home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5 Using core 'arduino' from platform in folder: /home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5 Detecting libraries used... /home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/cores/arduino -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/variants/standard /tmp/arduino_build_50173/sketch/ins_test.ino.cpp -o /dev/null Alternatives for xsens_mti.h: [xsens-mti] ResolveLibrary(xsens_mti.h) -> candidates: [xsens-mti] /home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/cores/arduino -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/variants/standard -I/home/xxxx/Arduino/libraries/xsens-mti /tmp/arduino_build_50173/sketch/ins_test.ino.cpp -o /dev/null Generating function prototypes... /home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/cores/arduino -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/variants/standard -I/home/xxxx/Arduino/libraries/xsens-mti /tmp/arduino_build_50173/sketch/ins_test.ino.cpp -o /tmp/arduino_build_50173/preproc/ctags_target_for_gcc_minus_e.cpp /home/xxxx/Downloads/arduino-1.8.19-linux64/arduino-1.8.19/tools-builder/ctags/5.8-arduino11/ctags -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives /tmp/arduino_build_50173/preproc/ctags_target_for_gcc_minus_e.cpp Compiling sketch... /home/xxxx/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++ -c -g -Os -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/cores/arduino -I/home/xxxx/.arduino15/packages/arduino/hardware/avr/1.8.5/variants/standard -I/home/xxxx/Arduino/libraries/xsens-mti /tmp/arduino_build_50173/sketch/ins_test.ino.cpp -o /tmp/arduino_build_50173/sketch/ins_test.ino.cpp.o /home/xxxx/Arduino/ins_test/ins_test.ino:18:3: sorry, unimplemented: non-trivial designated initializers not supported }; ^ /home/xxxx/Arduino/ins_test/ins_test.ino:18:3: sorry, unimplemented: non-trivial designated initializers not supported Using library xsens-mti in folder: /home/xxxx/Arduino/libraries/xsens-mti (legacy) exit status 1 Error compiling for board Arduino Uno.

Scottapotamas commented 2 years ago

Ok. Nothing in that error log that helps much...

I have the library and basics.ino building successfully for the Uno (1.8.19, on Linux). Try this branch - it should better integrate with the Arduino IDE's library manager, along with a typo in basic.ino and some small docs improvements.

https://github.com/Scottapotamas/xsens-mti/tree/arduino-fixes

If you're actually using an Arduino Uno, you'll run out of RAM due to xsens specifying 2kb packet sizes. There's a note in the README on that branch describing where to modify the library define to reduce the buffer size.

Beyond this, you'll have to provide ins_test.ino for me to troubleshoot anything in your code different from the example.

YohanHadji commented 2 years ago

The error can be "fixed" by changing the definition of xsens_interface_t in xsens_mti.h The two parameters are placed at the top instead of the bottom of the declaration

typedef struct
{
    callback_event_t    event_cb;
    callback_data_out_t output_cb;

    xsens_parser_state_t state;
    xsens_packet_buffer_t packet;
    uint16_t        payload_pos;
    uint8_t         crc;

} xsens_interface_t;

Instead of previously :

typedef struct
{ 
    xsens_parser_state_t state;
    xsens_packet_buffer_t packet;
    uint16_t        payload_pos;
    uint8_t         crc;

    callback_event_t    event_cb;
    callback_data_out_t output_cb;

} xsens_interface_t;

I can't be sure that it's solving the initial issue if there was one but it's definitely solving the same error message while trying to compile on PlatformIO for a Teensy4.1

I'll now try to get data from my MTI-7 to a Teensy4.1 using the library and report.

Scottapotamas commented 2 years ago

In the example sketch, I only partially filled out the xsens_interface_t instantiation. Leaving fields blank, or reordering them isn't supported by C++ (but is by C, hence the designated init warning).

I've added a helper macro which hides the longform structure init from end-users, and the sketch has been updated to match.

https://github.com/Scottapotamas/xsens-mti/blob/e1907b351cf6af29d117d8ad30564aef68d9c6ca/examples/basics/basics.ino#L21


@niteshglx I'm not sure if you're still working on your project, but I'd expect the master branch of this repo to build more easily now, providing you use something with a bit more RAM than a Uno or change the size of the input buffer as I mentioned above.

@YohanHadji You should be able to use the current master build without modification. As I've submitted the library to the Arduino Registry, it should also become available on platformio within a day or so.