• Non ci sono risultati.

Rosserial configuration

STM32H7 configuration

5.4 Rosserial configuration

Finally, three GPIO as led were configured. These three LEDs are used to pro-vide feedback on the status of the programme by only looking at the board. For example based on the led that is switched on, can be tell if the board is performing a certain task.

Once these peripherals have been configured with the graphical interface pro-vided by IDE, the C code that will be loaded onto the board is generated. This just described represents the configuration required to operate the board. How-ever, it is necessary to modify a few more parameters in order to make the board able to recive the command from the PC through USB. By adding a few files to the firmware’s board, it will be able to receive data from ROS, via the rosserial protocol, these steps will be described later.

5.4 Rosserial configuration

5.4.1 STM32H7

Figure 5.6: STM32H7 firmware file

In order to receive data from the PC via USB using the rosserial protocol, the board requires additional configuration. Once the parameters for the peripherals have been defined, the IDE automatically generates the

.c code containing all the peripheral information. The code for motor control was also written to this file.

The IDE automatically generates the main.c file, which contains the code that defines the peripheral con-figuration and code developed to control the robot. As can be seen from the image 5.6, the /src folder also contains files with the extension .cpp, meaning that the files are written in C++. Files with the extension .cpp

are externally imported files on which parameters for communication with ROS are defined, and on which publishers and subscriber are defined.

• main.c: The following file contains the peripherals configuration and the functions for sending commands to the motors via CAN. The functions used to communicate with the motors have the task of correctly creating the data frame to be transmitted via CAN. This file contains the code for communi-cation with the engines.

• mainpp.cpp: The following file was imported and is required for communica-tion via the rosserial protocol. Within this file, the publishers and subscribers that will communicate with the python node on the PC are defined. The files

STM32H7 configuration

needed for communication with ROS have the extension .cpp because ROS nodes can only be written in C++ or in python. This file contains the code for communication with the ROS nodes.

• main.h, mainpp.h: The following files represent the headers of the main.c and mainpp.cpp, in which the function definitions are listed.

• ros.h, STM32Hardware.h, node_handle.h: Finally, the following header files are imported and contain the re-configuration of the UART port in order to be able to use it with the rosserial protocol. Modifying these files it is possible to specify the maximum number of publishers and subscribers, the buad rate of the USB port and the buffer size of each publisher and subscriber and other technical parameters related to communication. In addition, the node_handle.h end contains all the functions necessary for formatting the message according to the parameters defined by the rosserial protocol.

After importing these files into the project folder (/src), a further modification of project parameters is necessary; these modifications are reported in the appendix.

5.4.2 PC

With this configuration, made using the IDE, the microcontroller is able to com-municate with the two devices, i.e. receive and send commands via CAN to the motors, and receive input and communicate the status of the robot to the PC. In this section will describe how the PC or RPi must be configured to allow POPUP control via ROS.

As described above, ROS is an open-source middleware that brings together various tools for robotics software development, but requires an operating system to run. By construction ROS 1 is based on the linux operating system Ubuntu, each ROS distribution requires a certain version of Ubuntu. A ROS distribution is a versioned set of ROS packages.

For this project it was decided to use the latest ROS 1 distro: ROS Noetic Ninjemys released in May 23rd, 2020, which it is based on Ubuntu 20.04. For the purposes of the project, the previous distribution could also be used: ROS Melodic Morenia, based on Ubuntu 18.04. It was decided to use the latest distribution in order to have support for longer period, (shown in the figure as EOL).

It was therefore necessary as a first step to install Ubuntu 20.04 on the PC.

Initially all the development part of the ROS nodes was done with the PC on which a virtual machine was installed there. In this way through one PC it was possible to write the firmware for the board, using the STM32CubeIDE software, installed on Windows 10, as well as develop the ROS nodes in python using ROS

5.4 – Rosserial configuration

Figure 5.7: ROS distribution

installed on the virtual machine present on Win 10.

The installation of the virtual machine and and configuration of Ubuntu was done by following the guide at this link 2.

Once the installation of the operating system is finished, the installation of the middleware is carried out. The procedure for installing ROS Noetic was done by following the guide in this book [6].

Finally, once these installations have been successfully completed, the rosserial package must be installed in order to enable communication between the PC and the microcontroller. Rosserial 3 is a protocol for wrapping standard ROS serial-ized messages and multiplexing multiple topics and services over a character device such as a serial port or network socket. The installation of this package was done by following the guide in this book [2].

Once the installation of this package is complete, the entire environment is ready for the node development.

Below are some basic commands used within ROS, other commands are col-lected within the ROS cheat sheet:

$ roscore : A collection of nodes and programs that are pre-requisites of a ROS-based system.roscore must run in order for ROS nodes to communicate.

$ rostopic:A tool for displaying debug information about ROS topics, including publishers, subscribers, publishing rate, and messages

$ rosrun: rosrun allows you to run an executable in an arbitrary package without having to cd (or roscd) there first.

2https://linuxhint.com/install_ubuntu_vmware_workstation/

3http://wiki.ros.org/rosserial

STM32H7 configuration

$ roslaunch: Starts ROS nodes locally and remotely via SSH, as well as setting parameters on the parameter server.

Documenti correlati