Ask Your Question

STM32 with ROS , rosserial in Eclipse how?

asked 2017-12-04 23:46:40 -0600

nquantum gravatar image

updated 2017-12-05 01:25:26 -0600

I intend to use STM32 for communicating with ROS , rosserial look promising. Since arduino, raspberrypi can do. Other should work also. I've seen Adding Support for New Hardware , IDEs , STM32 Microcontroller for communication with ROS

I can read/write function uart to STM32 which use GNU ARM toolchain compiler and library from ST with Eclipse. Also I can import package that publish and subscribe message into Eclipse. Those import package in Eclipse can RUN, DEBUG no problem so far..

But NO IDEA how to somehow mix 2 together , ros packge and stm32 source , (#include "ros/ros.h" and stuff into STM32 source) and build them to flash into STM32 microcontroller. I intend to create node in STM32 and subscribe sensor to PC or SBC run ROS or Subscribe some motor control or other control. Since it has more more memory and horse power than arduino. Also benefit of RTOS

Any help please?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-12-22 00:19:50 -0600

nquantum gravatar image

updated 2017-12-31 00:30:44 -0600

"Update: add example subscribe and publish to main.cpp"

During wait for answer I've search and try some. I think I got it working now. Maybe not perfect since I'm still learning C++

Here is my file: image description

from install for arduino:

  1. I install rosserial libraries on PC-Linux sudo apt-get install ros-kinetic-rosserial sudo apt-get install ros-rosserial-arduino

  2. building Arduino library >> after this we get ros_lib for our microcontroller , can copy to linux or windows cd <some_empty_directory> rosrun rosserial_arduino .

  3. get ros_lib ready to import to Arduino or other micro

  4. get working project & set preprocessor c , c++ > I use from cubeF4 example project uart_polling to make sure usart work
  5. copy ros_lib into project
  6. exclude from build , right click folder then untick exclude so it will compile this source in this folder
  7. include ros_lib in project property for c, c++
  8. rename main.c to main.cpp
  9. in main try #include <ros.h> compile error because it for arduino ros.h,ArduinoHardware.h, ArduinoTcpHardware.h
  10. replace ros.h and copy STM32Hardware.h
  11. adjust usart parameter in main.h to usartx, x = your number , I should move these parameter to STM32Hardware.h or from STM32Hardware.h to main.h to make it centralize. Maybe later...

test 1st terminal 1. roscore

2nd terminal 1. rosrun rosserial_python _port:=/dev/ttyACM0 _baud:=57600

3rd terminal 1. rostopic list 2. rostopic echo /chatter

Now you can see from those topic. Which I adjust from Hello World (example publisher) - Arduino :

Also reference from AVR and Adding Support for New Hardware

Another example: These two also interface stm32 to rosserial but they use library C++ of HAL. I see it not convenience for me , new in C++ and I like to use ST HAL which can easy import to Eclipse and generate from CubeMX.

Let me know if it work or recommendation. Since I now learn to make it work with FreeRTOS. I'm also new in ROS so still learn from tutorial.

Now is more happy coz since Arduino Uno have SRAM 2048 or 2K, simple Hello World already take 1358 or 66%. If I try more code it take 70% above then it unable to communicate with rosserial already. But now I use STM32F469 Discovery Board have SRAM 320K with Hello World take for 1.3K-1.5K I've plenty of room to play with plus power of 32bit and HAL library.

I use HAL_UART function in polling mode in client-side rosserial implementation. Maybe interupt mode should be better. I don't know if/how I can use interupt mode for the rosserial coz it seem like function read() and void write(uint8_t* data, int length) get call periodically. Shold I interupt read then place in buffer and read from those buffer? Anyway so far it work in polling..

FYI ... (more)

edit flag offensive delete link more


What a great news!!!! you got it working!

I will try it this weekend with my STM32F4Discovery and let you know the result.

Thank for sharing!

elgarbe gravatar image elgarbe  ( 2017-12-22 20:09:52 -0600 )edit

wich IDE are you using? I'm stuck on step 4, 6 and 7. Becouse I'm using SystemWorkbench and those options are not available. Can you explain a litle more that steps, please?


EDIT: I get it working, comipilng part. I get Unable to sync.... error.... I'm debuging now...

elgarbe gravatar image elgarbe  ( 2017-12-24 15:23:31 -0600 )edit

It stuck on virtual int publish(int id, const Msg * msg) { if (id >= 100 && !configured_)

Id=125 and configured is false...

elgarbe gravatar image elgarbe  ( 2017-12-24 16:25:53 -0600 )edit

IT'S WORKING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! What a Christmas present!

Please, keep us informed about your progress!

elgarbe gravatar image elgarbe  ( 2017-12-24 16:59:23 -0600 )edit

Congratulation! More room open now with STM32! I'm open for any suggest/improve. It only two source link to rosserial: ros.h and STM32Hardware.h Now I tend to move from poll to interupt with buffer, then DMA since lost sync come often use with FreeRTOS. I'm brand new so it will take sometime

nquantum gravatar image nquantum  ( 2017-12-24 21:18:32 -0600 )edit

Order new toy, SQ200 Logic Analyzer from IKALOGIC so let see what hidden bug here! :-p

nquantum gravatar image nquantum  ( 2017-12-24 21:26:36 -0600 )edit

For the ref. I use Eclipse. Step4 is to config preprocessor-compiler the define ,include folder in both c and c++ since we will compile both source. Step6,7 is for eclipse, when e create new folders in eclipse project, by default it excludes for build so we set it include.

nquantum gravatar image nquantum  ( 2017-12-24 21:36:38 -0600 )edit

"Unable to sync" Mostly mean well... can not sync or communicate due to uart can not transmit and/or receive or wrong baudrate/port invote to rosserial_python parameter. Make it computer can't "talk" to uc

nquantum gravatar image nquantum  ( 2017-12-24 21:39:23 -0600 )edit

answered 2017-12-21 10:14:15 -0600

elgarbe gravatar image

The problem, I think, is that STM32 library (HAL or stdlib) are ANSI C, and rosserial is C++. So, I think that the first thing to do is convert STM32 project to C++. I'm working on this. Can you explain me how to use ros package onto eclipse? We can work together to get this working


edit flag offensive delete link more


C++ code can call C, so there's no need to convert your entire project to C++.

ahendrix gravatar image ahendrix  ( 2017-12-21 12:03:21 -0600 )edit

You need to convert the project to C++, not the files (.c/.h). The compiler should be C++, it will compile all .c and .cpp files. Right?

elgarbe gravatar image elgarbe  ( 2017-12-21 14:37:03 -0600 )edit

According to GNU ARM Embedded Toolchain "The GNU Embedded Toolchain for Arm is a ready-to-use, open source suite of tools for C, C++ and Assembly programming targeting Arm"

Change main.c to main.cpp then c compile on source.c cpp compile in source.cpp Just check c and cpp preprocessor/include also

nquantum gravatar image nquantum  ( 2017-12-22 01:13:46 -0600 )edit

see this article -, but article is in Russian

ivliev123 gravatar image ivliev123  ( 2019-07-20 12:18:38 -0600 )edit
ivliev123 gravatar image ivliev123  ( 2019-07-20 12:33:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-12-04 23:46:40 -0600

Seen: 3,474 times

Last updated: Dec 31 '17