Interfacing STM32 boards to ROS using mbed

If Arduino is not enough for your application, the STM 32 boards are ready to serve you. To demonstrate ROS interfacing, we are going to use an STM 32 NUCLEO L476RG (https://developer.mbed.org/platforms/ST-Nucleo-L476RG/). Before we begin programming, let's understand the mbed platform. The mbed platform is a software platform for programming 32-bit ARM Cortex-M microcontrollers. The mbed platform developed as a collaborative project by ARM its technology partners. We can use the online mbed IDE or offline compilers for programming the boards. The advantage of using the online IDE is it will be updated and will have more hardware support.

Let's start programming the STM 32 board:

  1. The first step is to create an account on the mbed website, which is https://developer.mbed.org.
  2. After creating an account, go to the following link to check our board has support in the mbed platform: https://developer.mbed.org/platforms/.
  3. You can select your board from this website; for this demo, you should choose the NUCLEO L476RG board, which is available at https://developer.mbed.org/platforms/ST-Nucleo-L476RG/.
  4. You can see an option called Add to your mbed compiler on the right-hand side of this page. You have to click on this button to add this board to the mbed compiler. We can add any number of boards to the mbed compiler; also, we can choose the board before compiling.
  5. After adding the board to the compiler, we can compile a ROS node for this board. As we've already discussed, we can program the board using the online IDE or an offline compiler such as gcc4embed (https://github.com/adamgreen/gcc4mbed). Using offline compilers, we can only program a limited number of boards, but the online IDE can handle the latest boards.
  6. The programming APIs of the ROS node in STM 32 are the same as those for Arduino, only the environment and tools are different.
  7. The online ros_lib files for mbed are available at https://developer.mbed.org/users/garyservin/code/. You can find ros_lib for the Kinetic, Jade, and Indigo versions. You can try with the ROS version you are working on.
  8. You can look at Hello World code for each ROS distribution from the preceding link.
  1. You can import the code into the compiler using the following option:
Figure 12: Importing code to mbed in the online compiler
  1. This will open the source code in the mbed online IDE, as shown in the next screenshot. Here, we are testing with Hello World code for ROS Indigo.
  2. The area marked 1 is the board we have added to the compiler. Area 2 is imported source code and ros_lib for mbed, and area 3 is the button to compile the source code. You can see the debugging details at the bottom of the compiler:
Figure 13: The mbed online compiler
  1. The APIs are the same as those of Arduino we saw in the previous section. In this code, we are publishing a string message, Hello from STM32 NUCLEO, to a topic called /chatter. You can display this string on a PC by running the ROS serial server.
  2. Click on the Compile button to download the binary file, which can be copied to the board. Plug the board to your PC, and you will see a flash drive of the board. You can copy the downloaded binary file to the flash storage, as shown here:
Figure 14: Binary file on flash drive
  1. When we copy the binary file, the board will automatically start running it. Now, the procedures have been completed. Just start the ROS server on the PC side to display topics from the board.
  2. Start roscore:
              $ roscore
  1. Start the ROS server:
              $ rosrun rosserial_python serial_node.py /dev/ttyACM0
  1. Now you can echo the topic using the following command:
             $ rostopic echo /chatter
  1. You will get following messages on the Terminal:
Figure 15: String message from an STM 32 board
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.63.41