frankjoshua / rosserial_arduino_lib

56 stars 46 forks source link

Teensy 4.0 Compile error #14

Closed fjp closed 3 years ago

fjp commented 3 years ago

On ROS noetic, I am trying to compile a script for the Teensy 4.0 that works on Teensy 3.2. Compiling for 4.0 gives me the following error:

In file included from /home/fjp/Arduino/libraries/Rosserial_Arduino_Library/src/ros.h:39:0,
                 from /home/fjp/git/diffbot/diffbot_base/scripts/encoders/encoders/encoders.ino:12:
/home/fjp/Arduino/libraries/Rosserial_Arduino_Library/src/ArduinoHardware.h: In constructor 'ArduinoHardware::ArduinoHardware()':
/home/fjp/Arduino/libraries/Rosserial_Arduino_Library/src/ArduinoHardware.h:54:16: error: cannot convert 'usb_serial_class*' to 'HardwareSerial*' in assignment
       iostream = &Serial;
                ^
Error compiling for board Teensy 4.0.

I have checked for updates in the Arduino IDE and ubuntu ros packages but it seems that I have the latest Arduino rosserial 0.7.9 installed and all ubuntu packages are up to date. Anything else that I need to take care of?

I am not using the ubuntu Arduino IDE because it is not possible to install the Teensyduino addon to it. Instead I had to download the Arduino IDE separately.

It seems related to this rosserial issue.

fjp commented 3 years ago

When I try to use the latest commit 9ead2cf on master I get:

In file included from /home/fjp/programs/arduino-1.8.13/hardware/teensy/avr/cores/teensy4/WProgram.h:41:0,
                 from /tmp/arduino_build_640678/pch/Arduino.h:6:
/home/fjp/programs/arduino-1.8.13/hardware/teensy/avr/cores/teensy4/avr/pgmspace.h:35:39: error: data causes a section type conflict with rosserial_msgs::REQUESTPARAM
 #define PSTR(str) ({static const char data[] PROGMEM = (str); &data[0];})
                                       ^
/home/fjp/Arduino/libraries/rosserial_arduino_lib-master/src/std_msgs/Empty.h:41:41: note: in expansion of macro 'PSTR'
         const char * getMD5() { return  PSTR("d41d8cd98f00b204e9800998ecf8427e");};
                                         ^
In file included from /home/fjp/Arduino/libraries/rosserial_arduino_lib-master/src/ros/node_handle.h:43:0,
                 from /home/fjp/Arduino/libraries/rosserial_arduino_lib-master/src/ros.h:38,
                 from /home/fjp/git/diffbot/diffbot_base/scripts/encoders/encoders/encoders.ino:1:
/home/fjp/Arduino/libraries/rosserial_arduino_lib-master/src/rosserial_msgs/RequestParam.h:15:23: note: 'rosserial_msgs::REQUESTPARAM' was declared here
     static const char REQUESTPARAM[] PROGMEM = "rosserial_msgs/RequestParam";
                       ^
Error compiling for board Teensy 4.0.
fjp commented 3 years ago

Here are the lines that are mentioned in the error message:

This line in pgmspace.h

#define PSTR(str) ({static const char data[] PROGMEM = (str); &data[0];})

And the line with REQUESTPARAM in it is here rosserial_msgs/RequestParam.h:

https://github.com/frankjoshua/rosserial_arduino_lib/blob/9ead2cf8c377f197c3e3cb66cea33371b07c8c69/src/rosserial_msgs/RequestParam.h#L12-L16

The main problem seems to be that with the PSTR macro the strings are stored in the flash (see PROGMEM). To fix this for the Teensy 4.0 I had to use regular strings (to use RAM instead of flash). Just like it is done for the ESP8266 in source files where the PSTR macro is used. For example in the std_msgs/Empty.h

https://github.com/frankjoshua/rosserial_arduino_lib/blob/9ead2cf8c377f197c3e3cb66cea33371b07c8c69/src/std_msgs/Empty.h#L33-L42

@frankjoshua Is there a macro that is set when the Teensy 4.0 is used, like there is one for the ESP8266? In that case the a solution could be similar to: #if defined(ESP8266) || defined(Teensy40)

frankjoshua commented 3 years ago

This should be working now. I updated to ROS Serial version 0.9.1 and tested with a Teensy 4.0