+ All Categories
Home > Documents > Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof....

Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof....

Date post: 18-Oct-2020
Category:
Upload: others
View: 11 times
Download: 0 times
Share this document with a friend
60
Prof. Dr.-Ing. Otto Parzhuber Labor D204 14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik Datei: Raspberry.docx Seite 1 - 60 RaspberryPi/Turtlebot/NodeMCU/JetsonNano Prof. Dr.-Ing. Otto Parzhuber Hochschule München FK 06 Version vom 14.03.2021
Transcript
Page 1: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 1 - 60

RaspberryPi/Turtlebot/NodeMCU/JetsonNano

Prof. Dr.-Ing. Otto Parzhuber

Hochschule München FK 06

Version vom 14.03.2021

Page 2: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 2 - 60

Inhaltsverzeichnis

1.1 Suchen im Netz mit Nmap ................................................................................................... 4 1.2 Flashen einer SD-Card ......................................................................................................... 6

1.2.1 WinDiskImager ................................................................................................................ 6

1.2.2 Etcher ............................................................................................................................... 6 1.3 Welche Version ist installiert? ............................................................................................. 7

1.3.1 Upgrade von Stretch auf Buster ....................................................................................... 7 1.4 VNC-Viewer ........................................................................................................................ 8

1.4.1 Raspi 4 Problem VNC...................................................................................................... 8

1.4.2 Netzwerkeinstellung dhcpcd.conf .................................................................................... 8 1.4.3 Netzwerkkonfiguration mit wicd-curses .......................................................................... 9 1.4.4 Dateien editieren mit Administratorrechten ..................................................................... 9

1.4.5 Einstellen der Bildschirmauflösung des VNC Servers .................................................. 10 1.5 Programmierung mit VC++ ............................................................................................... 11

1.5.1 Verbinden mit dem Remote Host : ................................................................................ 11

1.5.2 Bash Skript ..................................................................................................................... 12 1.6 WiringPi ............................................................................................................................. 13 1.7 Parallele Schnittstellen ....................................................................................................... 13

1.7.1 GPIO .............................................................................................................................. 13 1.7.2 PWM .............................................................................................................................. 14

1.8 Serielle Schnittstellen ......................................................................................................... 15 1.8.1 UART ............................................................................................................................. 15 1.8.2 Bluetooth Serial.............................................................................................................. 15

1.8.2.1 Einstellungen .......................................................................................................... 15

1.8.2.2 Programmgerüst in C ............................................................................................. 17 1.8.3 I2C-Bus .......................................................................................................................... 19

1.8.3.1 Programgerüst in C ................................................................................................ 19 1.8.4 SPI-Bus .......................................................................................................................... 21

1.9 Installieren von Visual Code .............................................................................................. 22 1.10 ROS installieren: ................................................................................................................ 23

1.10.1 Praktische Tools: ........................................................................................................ 24 1.10.1.1 rosversion ........................................................................................................... 24 1.10.1.2 rospack ............................................................................................................... 24

1.10.1.3 roscd ................................................................................................................... 25 1.10.1.4 rosnode ............................................................................................................... 25 1.10.1.5 rosedit ................................................................................................................. 26 1.10.1.6 Erstellen eines Package ...................................................................................... 26

1.11 Arbeiten mit ROS............................................................................................................... 28

1.12 ROS-Topics ........................................................................................................................ 29 1.12.1 Programm rqt_graph .................................................................................................. 29

1.12.2 Programm Turtlesim .................................................................................................. 29 1.12.2.1 Turtlesim mit der Tastatur laufen lassen ........................................................... 30

1.12.3 Turtlesim automatisch im Kreis laufen lassen ........................................................... 31 1.12.3.1 rostopic ............................................................................................................... 32 1.12.3.2 Rostopic echo ..................................................................................................... 32

Page 3: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 3 - 60

1.12.4 Build einzelner Packages (Tutorials) ......................................................................... 33 1.12.4.1 Publisher und Subscriber ................................................................................... 33

1.12.4.2 Server und Client ............................................................................................... 34 1.13 Turtlebot ............................................................................................................................. 35

1.13.1 Netzwerkeinstellungen ............................................................................................... 35 1.13.1.1 RemotePC: ......................................................................................................... 36 1.13.1.2 TurtleBot: ........................................................................................................... 36

1.13.2 Erstes Starten des TurtleBot ....................................................................................... 37 1.13.3 Erkennen eines Hindernisses ..................................................................................... 40

1.14 Can-Bus .............................................................................................................................. 41 1.15 Mosquitto Broker installieren ............................................................................................ 42

1.15.1 Wie kann ich den cc3100 mqtt Client mit Mosquitto Broker verbinden? ................. 42 1.16 On-Board LED als GPIO ................................................................................................... 43 1.17 Webmin .............................................................................................................................. 43

1.18 VPN .................................................................................................................................... 43 1.18.1 Installieren .................................................................................................................. 43 1.18.2 Verwenden ................................................................................................................. 43

1.19 Watchdog aktivieren und einrichten .................................................................................. 45 1.20 Pairing mit Bluetooth (Beispiel ES32)............................................................................... 46 1.21 Pinbelegung ........................................................................................................................ 49

1.22 WiringPi Zuordnung .......................................................................................................... 50 1.23 Raspi als WLAN Bridge .................................................................................................... 51

1.23.1 WLAN-AP-Host konfigurieren (hostapd) ................................................................. 51

1.23.2 Anwendungsbeispiel TurtleBot 3 über Bridge mit Router verbinden ....................... 54 1.24 RemoteDesktopverbindung Ubuntu ................................................................................... 55

2 Matlab und Raspberrypi ............................................................................................................. 55 3 Matlab und ROS......................................................................................................................... 56 4 Jetson Nano ................................................................................................................................ 56

5 NodeMCU .................................................................................................................................. 57

Page 4: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 4 - 60

Das folgende Dokument ist eine kleine Sammlung von Programmieranleitungen für den

RaspberryPi. Als Betriebssystem wird Raspbian Stretch eingesetzt. Ausführliche Beschreibungen

zu Installation und Software für den RaspberryPi gibt es viele1.

Die erste Inbetriebnahme wird in diesem Dokument nicht beschrieben, da es dafür viele Tutorials

im Internet gibt, z.B.:

https://www.elektronik-kompendium.de/sites/raspberry-pi/1906261.htm

https://tutorials-raspberrypi.de/raspberry-pi-einstieg-wie-starte-ich/

1.1 Suchen im Netz mit Nmap

Die IP-Adressen des RaspberryPi sucht man am einfachsten mit dem Programm Zenmap (GUI für

Nmap)2:

Mit einem der vielen Terminalprogramme (z.B. putty) können Sie sich nun mit dem RaspberryPi

verbinden:

1 http://www.netzmafia.de/skripten/hardware/RasPi/RasPi_Network.html#stretchnet 2 https://nmap.org/zenmap/

Page 5: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 5 - 60

Die geladenen Module finden Sie beispielsweise mit lsmod:

Den freien Speicherplatz in kByte oder MByte finden Sie mit:

pi@raspberrypi:~ $ df –h

Eine Konfiguration wichtiger Parameter können Sie mit dem folgenden Befehl durchführen:

pi@raspberrypi:~ $ sudo raspi-config

Sie erhalten das folgende Dialogfenster zur Einstellung der Parameter:

Page 6: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 6 - 60

1.2 Flashen einer SD-Card

Das wichtigste Programm bei Problemen ist das Konsolenprogramm diskmgmt.msc.

Mit diesem Windowsprogramm kann die SD-Card formatiert und bestehende Partitionen gelöscht

werden.

Das nebenstehende Bild

zeigt das Programm ohne

eingesteckte SD-Karte,

diese würde als Datenträger

1 auftauchen.

Datenträger 0 ist die 1.

Festplatte und ist

selbstverständlich tabu!!

1.2.1 WinDiskImager

Mit diesem Programm kann eine SD-Card kopiert werden.

Im ersten Schritt wird das Image von der SD-Card gelesen und auf die Festplatte gespeichert, in

dem Beispiel auf dem Desktop mit Filenamen kernel8.img.

Im zweiten Schritt kann dann dieses Image (im Beispiel umbenannt in Raspi4.img) mit demselben

Programm auf eine neue SD-Card geschrieben werden.

1.2.2 Etcher

Eine zweite Möglichkeit bietet das Programm Etcher. Beim Starten des Programms ist das weitere

Vorgehen weitgehend selbsterklärend.

Page 7: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 7 - 60

1.3 Welche Version ist installiert?3

Die installierte Version des Raspbian Betriebssystems finden Sie mit der folgenden Anweisung:

Weitere Infos geben die folgenden Anweisungen:

pi@raspberrypi:~ $ hostnamectl

Static hostname: raspberrypi

Icon name: computer

Machine ID: dcdda99c50c5436986e1e0d70daaa24a

Boot ID: ab9489e94c8d4a9bbd1b5b1c46852eda

Operating System: Raspbian GNU/Linux 10 (buster)

Kernel: Linux 4.19.93-v7+

Architecture: arm

1.3.1 Upgrade von Stretch auf Buster

Für die Durchführung dieses Upgrade gibt es ein sehr gutes Tutorial:

https://devdrik.de/upgrade-stretch-auf-buster/

https://pimylifeup.com/upgrade-raspbian-stretch-to-raspbian-buster/

3 https://www.elektronik-kompendium.de/sites/raspberry-pi/1911231.htm

Page 8: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 8 - 60

1.4 VNC-Viewer

Der VNC Viewer ist eine komfortable Möglichkeit über einen Remotezugang mit dem RaspberryPi

zu kommunizieren. Auf dem RaspberryPi ist mit Raspbian bereits der RealVNC Server installiert,

er muss gegebenenfalls im SetupMenu „enabled“ werden.

Für die Verbindungsaufnahme starten Sie den VNC Viewer und geben die IP-Adresse des

RaspberryPi und anschließend das Kennwort ein.

Sie haben nun Zugriff auf den RaspberryPi und können auf der Konsolenebene oder auch wie in

Windows gewohnt grafisch arbeiten:

1.4.1 Raspi 4 Problem VNC

Bei Raspi 4 muss die Auflösung in der Datei /boot/config.txt eingestellt werden:

# uncomment to force a console size. By default it will be display's size minus

# overscan.

framebuffer_width=1280

framebuffer_height=720

1.4.2 Netzwerkeinstellung dhcpcd.conf

Die Datei /etc/dhcp.conf dient zur Einstellung der IP-Adresse. Die Einstellungen in der Datei sind

selbsterklärend. Fall ein dhcp Server vorhanden ist wird eine IP automatisch vergeben, ansonsten

wird die statische IP in der Datei dhcpcd.conf verwendet.

Page 9: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 9 - 60

1.4.3 Netzwerkkonfiguration mit wicd-curses

Wem die Netzwerkkonfiguration von Hand zu kompliziert ist kann dieses grafische Tool

verwenden.

Zuerst muss diese Software installiert werden: sudo apt-get install wicd-curses

Danach kann das Tool einfach ausgeführt werden: sudo wicd-curses

1.4.4 Dateien editieren mit Administratorrechten

Der grafische Editor Leafpad ist für Windowsnutzer angenehmer zu bedienen als die

Kommandozeileneditoren nano, vi oder emacs. Um auch Dateien mit Administratorrechten

bearbeiten zu können müssen Sie den Editor von der Kommandozeile starten.

Dieses erste Beispiel zeigt die Editierung der Datei /etc/dhcpcd.conf. In diesem Beispiel werden die

Netzwerkeinstellungen für einen RaspberryPi im Labor D204 vorgenommen:

Im zweiten Beispiel wird die Datei .bashrc im Homeverzeichnis des Users editiert:

Page 10: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 10 - 60

Im dritten Beispiel wird der Treiber für das Shield des CAN-Bus konfiguriert:

1.4.5 Einstellen der Bildschirmauflösung des VNC Servers

Diese Auflösung kann in der folgenden Datei eingestellt werden:

pi@turtlepi:~ $ sudo leafpad /boot/config.txt

In dieser Datei gibt es eine Sektion, die so aussieht und dabei sind die Parameter framebuffer_width

und framebuffer_height auskommentiert. Lösche das Doppelkreuz und hinterlege die gewünschte

Bildschirmauflösung. framebuffer_width ist für die Breite und ramebuffer_height für die Höhe

zuständig.

# uncomment to force a console size. By default it will be display's size minus

# overscan.

framebuffer_width=1280

framebuffer_height=1024

Page 11: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 11 - 60

1.5 Programmierung mit VC++4

Unter Windowsprogrammierern ist Visual Studio sehr beliebt. Ohne großen Aufwand kann diese

Programmierumgebung auch für die Programmierung eines RaspberryPi eingesetzt werden:

1.5.1 Verbinden mit dem Remote Host :

Beim ersten Erstellen des Projekts wird das

Dialogfenster automatisch geöffnet:

Für spätere Änderungen der

Zugangsdaten zum RaspberryPi geht

der Weg über den Menüeintrag

->Optionen:

4 https://developer-blog.net/raspberry-pi-als-visual-studio-linux-remotesystem/

Page 12: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 12 - 60

Das Programm kann nun ausgeführt werden, entweder aus der Programmierumgebung Visual

Studio im Debugmodus:

oder auf der Kommandozeile via putty oder VNC-Viewer:

Die Pinzuordnung bei WiringPi ist im Anhang

1.5.2 Bash Skript

Da die Eingabe des langen Pfadnamens nicht sehr benutzerfreundlich ist, empfiehlt sich ein

einfaches Bash Skript:

#!/bin/bash

./projects/Blink1666/bin/ARM/Debug/Blink1666.out

Dieses Skript muss nun noch die passenden Rechte bekommen um es ausführen zu können.

pi@raspberrypi_d204:~ $ chmod +x blink.sh

Page 13: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 13 - 60

Das Programm kann nun ganz einfach mit dem folgenden Befehl gestartet werden.

pi@raspberrypi_d204:~ $ ./blink.sh

An Skriptdateien können natürlich auch Kommandos übergeben werden, und vieles weitere5

1.6 WiringPi

Wiring Pi ist eine ältere Bibliothek, aber ermöglicht einen einfachen „Arduino-kompatiblen“

Zugang zu verschiedenenen Schnittstellen des RaspberryPi. Unter dem Betriebssystem RaspBian ist

WiringPi üblicherweise vorinstalliert:

pi@raspberrypi:~ $ sudo apt-get install wiringpi

Paketlisten werden gelesen... Fertig

Abhängigkeitsbaum wird aufgebaut.

Statusinformationen werden eingelesen.... Fertig

wiringpi ist schon die neueste Version (2.50).

0 aktualisiert, 0 neu installiert, 0 zu entfernen und 4 nicht aktualisiert.

1.7 Parallele Schnittstellen

1.7.1 GPIO

Mit WiringPi ist es wie bei Arduino:

int main(void) { wiringPiSetupSys(); pinMode(LED, OUTPUT); printf("Hallo Welt\r\n"); // 1) while (true) { static int i = 0; digitalWrite(LED, HIGH); // Ein delay(150); // ms digitalWrite(LED, LOW); // Aus delay(150); printf("counter = %d\r\n", i++); } return 0; }

1) Die Ausgabe auf die Konsole ist die einfachste und sehr effiziente Debugmöglichkeit!

5 https://wiki.ubuntuusers.de/Shell/Bash-Skripting-Guide_f%C3%BCr_Anf%C3%A4nger/

Page 14: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 14 - 60

1.7.2 PWM

Kleines Beispiel für die Einstellung um PWM verwenden zu können:

#define OUTPUT 1 #define PWM 1 int main(void) { int32_t pw = 100; if (wiringPiSetup() == -1) { printf("Error wiringPiSetup: %d", errno); exit(1); } printf("Reminder: this program must be run with sudo. Delay 5 seconds.\r\n"); delay(5000); pinMode(LED, OUTPUT); delayMicroseconds(1E6); // muss aufgerufen werden, um den pwm mode zu aktivieren // ansonsten gehts nicht if (wiringPiSetup() == -1) { printf("Error wiringPiSetup: %d", errno); exit(1); } pinMode(PWM, PWM_OUTPUT); pwmSetMode(PWM_MODE_MS); //pwmSetClock(192); // 19.2 MHz /192= 100 kHz //pwmSetRange(10); // 100kHz/10 = 10 kHz, nur 10 unterschiedliche pw möglich pwmSetClock(2); // 19.2 MHz /2= 9.6 MHz pwmSetRange(480); // 480/9.6 = 50 us -> 20kHz printf("Blinklicht mit Wire Notation LED %d und PWM %d\r\n", LED, PWM); while (1) { digitalWrite(LED, HIGH); printf("%d ", pw); pwmWrite(PWM, pw); if (pw > 480) { pw = 0; printf("\r\n"); } else pw++; delay(50); digitalWrite(LED, LOW); delay(50); } }

Page 15: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 15 - 60

1.8 Serielle Schnittstellen

1.8.1 UART

Der folgende Code zeigt ein einfaches Beispiel für die UART Kommunikation mit Verwendung der

Wiring Pi Bibliothek:

/* mit wiringPi */ void testUART(void) { int fd; const int baud = 115200; fd = serialOpen("/dev/tty/ttyS0", baud); if (fd < 0) printf("Error UART: %d", errno); serialPutchar(fd, 'H'); serialPuts(fd, "allo Welt\r\n"); serialClose(fd); }

1.8.2 Bluetooth Serial

1.8.2.1 Einstellungen

Zunächst muss das SP Profil zu dem Raspi hinzugefügt werden:

pi@raspberrypi_d204:~ $ sudo leafpad /etc/systemd/system/dbus-org.bluez.service

In dieser Datei müssen diese beiden Zeilen stehen:

. . .

ExecStart=/usr/lib/bluetooth/bluetoothd -C

ExecStartPost=/usr/bin/sdptool add SP

. . . .

Mit dem folgenden Kommando können Sie die serielle Bluetoothkommunrikation überwachen:

pi@raspberrypi_d204:~ $ sudo rfcomm watch hci0

Waiting for connection on channel 1

Zuerst müssen Sie „scan, „pair“ und „trust“ durchführen. Dies geht auf der Kommandozeile mit

dem Kommando "bluetoothctl". Führen Sie dazu Folgendes in der Befehlszeile Ihres Terminals aus: pi@raspberrypi:~ $ bluetoothctl -a [NEW] Controller B8:27:EB:10:3D:2B raspberrypi [default] [NEW] Device 3C:71:BF:AA:99:CE ESP32_InvPendel [NEW] Device B0:10:41:D8:29:D9 BRAVIA

Page 16: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 16 - 60

[NEW] Device 9C:8C:6E:47:E8:85 [TV] Samsung 6 Series (55) Agent registered [bluetooth]#

Der Vorgang “pair” und “trust” sieht folgendermaßen aus: [bluetooth]# pair 3C:71:BF:AA:99:CE Attempting to pair with 3C:71:BF:AA:99:CE Failed to pair: org.bluez.Error.AlreadyExists [bluetooth]# trust 3C:71:BF:AA:99:CE Changing 3C:71:BF:AA:99:CE trust succeeded [bluetooth]# Beenden von bluetoothctl:

[bluetooth]# quit Agent unregistered [DEL] Controller B8:27:EB:10:3D:2B raspberrypi [default] pi@raspberrypi:~ $ Diese Einstellungen bleiben beim Neustart erhalten und sind im Verzeichnis /var/lib/bluetooth

abgelegt!!6

Der Vorgang „pair“ und „trust“ kann auch im VNC-Viewer

durchgeführt werden:

Nun muss nur noch bind durchgeführt werden sudo rfcomm bind /dev/rfcomm0 3C:71:BF:AA:99:CE 1 Am besten arbeitet man mit zwei Konsolen:

6 https://pi-buch.info/bluetooth-konfiguration-mit-bluetoothctl/

Page 17: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 17 - 60

Wenn man die MAC nicht weiß ist folgendes recht praktisch:

pi@raspberrypi:~ $ hcitool scan

Scanning ...

3C:71:BF:AA:A5:9E ESP32_InvPendel

B0:10:41:D8:29:D9 BRAVIA

pi@raspberrypi:~ $

Für das Ansehen der Daten eignet sich unter Linux das Terminalprogramm cutecom . Dieses

Programm entspricht dem Programm Teraterm unter Windows.

1.8.2.2 Programmgerüst in C

Einige Teile eines C-programms werden nachfolgend gezeigt:

/* Das vollständige Programm ist auf der Homepage*/ int main(void) { int fd; /* Filehandle for Serial Bluetooth Communication */ char buffer[512]; fd = serialOpen("/dev/rfcomm0", 115200, MAXLINE); if (fd < 1) { perror("ungültiges Handle"); exit(1); } else cout << "Bluetooth Open fd = " << fd << endl; . . . . . serialGets(buffer, 512, fd); /* Read */ } /* main*/ /* Funktion für das Lesen eines char Feldes */ char* serialGets(char* buf, const int n, const int fd) {

Page 18: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 18 - 60

int i = 0; do { buf[i] = serialGetchar(fd); if (buf[i] == '\0') break; i++; } while (serialDataAvail(fd)); tcflush(fd, TCIFLUSH); /* den Rest entfernen*/ return (buf); }

Page 19: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 19 - 60

1.8.3 I2C-Bus

Prüfen ob und welche i2c-Bus Module geladen sind:

Zuerst mal das System updaten:

I2-Tools installieren, das sind praktische Tools für die Kommandozeile:

In der aktuellen Version sind diese Tools bereits installiert wie der obige Aufruf zeigt. Die

folgenden Programme sind in i2c-tools enthalten:

1.8.3.1 Programgerüst in C

1.8.3.1.1 Mit WiringPi

Am einfachsten erfolgt der Zugriff auf den I2C-Bus über die WiringPi Library.

Der folgende Code zeigt den Zugriff auf das 7-Segmentdisplay im Praktikum:

#define ADR7BIT 0x27

Page 20: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 20 - 60

void testI2C_7Segment(void) { const unsigned char segm7[] = { 0xEE, 0x48, 0xAB, 0x6B, 0x4D, 0x67, 0xE7, 0x4A, 0xEF, 0x6F }; // 1) int fd; fd = wiringPiI2CSetup(ADR7BIT); if (fd < 0) printf("Error I2C: %d", errno); wiringPiI2CWriteReg8(fd, 0x03, 0x00); // alle Pins auf Ausgang stellen while (true) { for (int i = 0; i < 10; i++) { // 2) wiringPiI2CWriteReg8(fd, 0x01, segm7[i]); digitalWrite(LED, HIGH); // Ein delay(1500); digitalWrite(LED, LOW); // Aus delay(1500); } } }

1) Diese Bitkombinationen sind durch die Hardware der Platine bedingt.

2) Die Schleife gibt dim Abstand von 3 Sekunden die Ziffern 0 bis 9 aus.

1.8.3.1.2 Ohne WiringPi

Der folgende Code zeigt den I2C-Bus Zugriff ohne die WiringPi Library:

int main(void) { const unsigned char adr7Bit = 0x27; unsigned char writeBytes[10], readBytes[10], wlen, rlen; if (wiringPiSetup() == -1) { printf("Error wiringPiSetup: %d", errno); exit(1); } // Einfacher Test für die Funktion des I2C-Bus ohne die wiringpi library zu verwenden writeBytes[0] = 0xF0; wlen = 1; rlen = 2; testI2CMaster(adr7Bit, writeBytes, wlen, readBytes, rlen); //ohne wiringpi library printf("I2C Daten = %d, %d\r\n", readBytes[0], readBytes[1]); }

Page 21: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 21 - 60

1.8.4 SPI-Bus

Kleines Beispiel für das Lesen des WhoAmI Registers des Beschleunigungssensors LIS33. Es wird

die WiringPi Library verwendet.

/* Beispiel LIS33 Abfrage des WhoAmi Registers */ #define WHOAMI 0x0F; void main(void) { unsigned char buffer[10]; int fd; const int channel = 0; // Kanal 0 oder 1 möglich fd = wiringPiSPISetup(channel, 1E6); // 1MHz Datenrate if (fd < 0)

printf("Error SPI: %d", errno); buffer[0] = WHOAMI;

buffer[1] = 0x00; //Dummy… wird überschrieben fd = wiringPiSPIDataRW(channel, buffer, 2); //schreiben und lesen von 2 Byte if (fd < 0)

printf("Error SPI: %d", errno); printf("WhoAmI Lis33 = %x\r\n", buffer[1]); //0x33 dann passt alles siehe unten delay(1000); }

Page 22: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 22 - 60

1.9 Installieren von Visual Code7

Eine IDE für das programmieren

wget https://packagecloud.io/headmelted/codebuilds/gpgkey -O - | sudo apt-key

add –

curl -L https://code.headmelted.com/installers/apt.sh | sudo bash

Die aktuelle Version geht auf dem Raspi leider nicht, “Black Screen”, aber es funktioniert mit der

Version 1.29:

apt-get install code-oss=1.29.0-1539702286

apt-mark hold code-oss

7 https://medium.com/@melzoghbi/install-visual-studio-code-on-raspbian-eedc566c616d

Page 23: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 23 - 60

1.10 ROS installieren:

Welche Raspbian Version ist installiert?

Für die Installation von ROS Buster bitte die folgende Webseite verwenden:

http://wiki.ros.org/ROSberryPi/Installing%20ROS%20Melodic%20on%20the%20Raspberry%20Pi

veraltet:

Nach der folgenden Anleitung ROS Kinetic installieren. Es wird hier von den Sourcen installiert:

http://wiki.ros.org/ROSberryPi/Installing%20ROS%20Kinetic%20on%20the%20Raspberry%20Pi

Die Umgebungsvariablen müssen mit source gesetzt werden:

Mit den folgenden Zeilen ist man sicher dass die aktuellste Version von ros installiert ist:

sudo apt-get update

sudo apt-get upgrade

sudo apt-get install -y python-rosdep python-rosinstall-generator python-wstool

python-rosinstall build-essential cmake

Page 24: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 24 - 60

sudo rosdep init

rosdep update

Pfad überprüfen

1.10.1 Praktische Tools:

1.10.1.1 rosversion

Die auf dem Rechner installierte Version von ROS findet man mit dem Kommando rosversion:

pi@raspberrypi_d204:~ $ rosversion -d

kinetic

pi@raspberrypi_d204:~ $ rosversion roscpp

1.12.14

pi@raspberrypi_d204:~ $

Im Beispiel ist es die Version Kinetic und die roscpp Version 1.12.14.

1.10.1.2 rospack

Es ist oftmals sehr mühselig die Installationspfade zu finden, dies geht mit dem Kommando

rospack sehr einfach:

pi@raspberrypi:~ $

pi@raspberrypi:~ $ rospack find roscpp

/opt/ros/kinetic/share/roscpp

pi@raspberrypi:~ $

Die vielen Möglichkeiten von rospack zeigt der folgende Aufruf:

pi@raspberrypi_d204:~ $ rospack help

USAGE: rospack <command> [options] [package]

Allowed commands:

help

cflags-only-I [--deps-only] [package]

cflags-only-other [--deps-only] [package]

depends [package] (alias: deps)

depends-indent [package] (alias: deps-indent)

depends-manifests [package] (alias: deps-manifests)

depends-msgsrv [package] (alias: deps-msgsrv)

depends-on [package]

depends-on1 [package]

depends-why --target=<target> [package] (alias: deps-why)

depends1 [package] (alias: deps1)

export [--deps-only] --lang=<lang> --attrib=<attrib> [package]

Page 25: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 25 - 60

find [package]

langs

libs-only-L [--deps-only] [package]

libs-only-l [--deps-only] [package]

libs-only-other [--deps-only] [package]

list

Die Abhängigkeiten eines Packages findet man beispielsweise mit dem Kommando:

pi@raspberrypi_d204:~ $ rospack depends1 beginner_tutorials

roscpp

rospy

std_msgs

pi@raspberrypi_d204:~ $

Die Abhängigkeit des in beginner_tutorials verwendeten Packages roscpp zeigt dann beispielsweise

der folgende Aufruf von rospack: pi@raspberrypi_d204:~ $ rospack depends1 roscpp

cpp_common

message_runtime

rosconsole

roscpp_serialization

roscpp_traits

rosgraph_msgs

rostime

std_msgs

xmlrpcpp

pi@raspberrypi_d204:~ $

1.10.1.3 roscd

Für den Wechsel in die ROS Verzeichnisse benützt man am einfachsten roscd: pi@raspberrypi_d204:~ $

pi@raspberrypi_d204:~ $ roscd roscpp

pi@raspberrypi_d204:/opt/ros/kinetic/share/roscpp $

1.10.1.4 rosnode

Ein Node in ROS ist ein ausführbares Programm das über ROS mit anderen Node kommunizieren

kann.

Das Kommando rosnode zeigt die laufenden Nodes an, falls kein Node läuft erhalten Sie die

folgende Ausgabe:

pi@raspberrypi_d204:~ $ rosnode list

ERROR: Unable to communicate with master!

Sobald Sie einen Node mit roscore gestartet haben sehen Sie in einem zweiten Terminal die

folgende Ausgabe:

pi@raspberrypi_d204:~ $ rosnode list

/rosout

Page 26: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 26 - 60

Details über den rosnode liefert:

pi@raspberrypi_d204:~ $ rosnode info /rosout

--------------------------------------------------------------------------------

Node [/rosout]

Publications:

* /rosout_agg [rosgraph_msgs/Log]

Subscriptions:

* /rosout [unknown type]

Services:

* /rosout/get_loggers

* /rosout/set_logger_level

contacting node http://raspberrypi_d204:42121/ ...

Pid: 1995

pi@raspberrypi_d204:~ $

1.10.1.5 rosedit

Mit dem Kommando rosedit können Dateien eines Packages ohne die lange Pfadangabe editiert

werden.

Als Defaulteditor ist vim eingestellt. Mit dem folgenden Kommando kann dies geändert werden:

pi@raspberrypi_d204:~ $ export EDITOR='leafpad'

Das Ergebnis: pi@raspberrypi_d204:~ $ echo $EDITOR

leafpad

Das Editieren der Datei Logger.msg im Package roscpp ist nun mit dem Editor leafpad möglich:

pi@raspberrypi_d204:~ $ rosed roscpp Logger.msg

pi@raspberrypi_d204:~ $

Wichtig:

Das Kommando rosed unterstützt auch die gewohnte Vervollständigung von eingegeben Pfaden

bzw. Dateinamen. Dies geschieht mit <Tab> <Tab>.

1.10.1.6 Erstellen eines Package

Page 27: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 27 - 60

Build aller ROS-Module:

$ cd ..

$ catkin_make

Page 28: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 28 - 60

1.11 Arbeiten mit ROS8

Um setup.bash automatisch beim Starten der Shell auszuführen fügen Sie in die .bashrc Datei die

folgende Zeile ein:

# für die Verwendung von ROS OParz

source /opt/ros/kinetic/setup.bash

Dann muss das Programm roscore gestartet werden:

pi@raspberrypi:~ $ roscore

... logging to /home/pi/.ros/log/d93ce1e8-41e3-11e9-8c35-b827eb64585c/roslaunch-raspberrypi-

13422.log

Checking log directory for disk usage. This may take awhile.

Press Ctrl-C to interrupt

Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://raspberrypi:37145/

ros_comm version 1.12.14

SUMMARY

========

PARAMETERS

* /rosdistro: kinetic

* /rosversion: 1.12.14

NODES

auto-starting new master

process[master]: started with pid [13432]

ROS_MASTER_URI=http://raspberrypi:11311/

setting /run_id to d93ce1e8-41e3-11e9-8c35-b827eb64585c

process[rosout-1]: started with pid [13445]

started core service [/rosout]

Ab jetzt können Sie die mit den verschiedenen ROS Programmen und Tools arbeiten.

8 http://wiki.ros.org/ROS/Tutorials

Page 29: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 29 - 60

1.12 ROS-Topics

ROS Nodes können Nachrichten (Messages) zu einem Topic „publishen“ oder an ein Topic

„subscriben“ um diese Nachrichten zu erhalten. Es gibt dazu ein Kommandotool rostopic (siehe

nächstes Kapitel.

Der turtlesim_node und der turtle_teleop_key node kommunizieren über eine ROS Topic.

turtle_teleop_key ist der publisher für die Tastenbetätigunggen an einem Topic, der Subscriber

ist turtlesim der an dieses Topic subscribed um die Tastenbetätigungen zu erhalten. Mit dem

Kommando rqt_graph können gerade laufenden Nodes und die Topics online betrachtet werden.

1.12.1 Programm rqt_graph

Das Programm rqt_graph zeigt die Abhängigkeiten zwischen publish und subscribe. Sie müssen

dafür eine neue Konsole öffnen:

pi@raspberrypi:~ $ rosrun rqt_graph rqt_graph

libEGL warning: DRI2: failed to authenticate

inotify_add_watch("/home/pi/.config/qt5ct") failed: "No such file or directory"

Da kein Publisher gestartet ist wird ein leerer Bildschirm angezeigt:

1.12.2 Programm Turtlesim

Öffnen Sie nun eine neue Konsole und starten das Programm turtlesim mit dem Parameter

turtlesim_node:

pi@raspberrypi:~ $ rosrun turtlesim turtlesim_node

libEGL warning: DRI2: failed to authenticate

qt5ct: using qt5ct plugin

[ INFO] [1552079949.310965513]: Starting turtlesim with node name /turtlesim

[ INFO] [1552079949.357351144]: Spawning turtle [turtle1] at x=[5,544445], y=[5,544445], theta=[0,000000]

inotify_add_watch("/home/pi/.config/qt5ct") failed: "No such file or directory"

Wenn es geklappt hat wird eine Schildkröte angezeigt:

Page 30: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 30 - 60

Jetzt machen Sie ein neues Terminal auf und starten wieder das Kommando rosnode, aber mit dem

Parameter list:

pi@raspberrypi_d204:~ $ rosnode list

/rosout

/turtlesim

pi@raspberrypi_d204:~ $

Sie erhalten nun zwei laufende Nodes wie das Bild zeigt.

Die Kommunikation mit dem Node turtlesim kann nun mit einem „klassischen“ Ping überprüft

werden:

pi@raspberrypi_d204:~ $ rosnode ping turtlesim

rosnode: node is [/turtlesim]

pinging /turtlesim with a timeout of 3.0s

xmlrpc reply from http://raspberrypi_d204:34415/ time=2.321959ms

xmlrpc reply from http://raspberrypi_d204:34415/ time=3.224850ms

xmlrpc reply from http://raspberrypi_d204:34415/ time=3.185987ms

xmlrpc reply from http://raspberrypi_d204:34415/ time=3.258944ms

xmlrpc reply from http://raspberrypi_d204:34415/ time=3.131866ms

xmlrpc reply from http://raspberrypi_d204:34415/ time=3.461838ms

xmlrpc reply from http://raspberrypi_d204:34415/ time=3.319979ms

^Cping average: 3.129346ms

pi@raspberrypi_d204:~ $

1.12.2.1 Turtlesim mit der Tastatur laufen lassen

Mit dem Node turtle_teleop_key können Sie den simulierten Roboter mit der Tastatur bewegen:

Page 31: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 31 - 60

pi@raspberrypi_d204:~ $ rosrun turtlesim

turtle_teleop_key

Reading from keyboard

---------------------------

Use arrow keys to move the turtle.

1.12.3 Turtlesim automatisch im Kreis laufen lassen

Sie müssen wieder eine neue Konsole starten, das Programm turtlesim darf nicht beendet werden.

Mit dem folgenden rostopic Kommando können Sie nun die Schildkröte im Kreis laufen lassen:

pi@raspberrypi:~ $ rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0,0.0,0.0]'

'[0.0,0.0,1.8]'

Die Schildkröte läuft nun im Kreis. Sie können mit den Parametern spielen und unterschiedliche

Kreise laufen lassen.

Page 32: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 32 - 60

1.12.3.1 rostopic

In diesem Beispiel wird das Tool rostopic verwendet. Mit diesem Tool erhalten Sie Informationen

über ROS Topics. Die Möglichkeiten zeigt der folgende Aufruf:

pi@raspberrypi_d204:~ $ rostopic -h

rostopic is a command-line tool for printing information about ROS Topics.

Commands:

rostopic bw display bandwidth used by topic

rostopic delay display delay of topic from timestamp in header

rostopic echo print messages to screen

rostopic find find topics by type

rostopic hz display publishing rate of topic

rostopic info print information about active topic

rostopic list list active topics

rostopic pub publish data to topic

rostopic type print topic or field type

Type rostopic <command> -h for more detailed usage, e.g. 'rostopic echo -h'

pi@raspberrypi_d204:~ $

Starten Sie nun rqt_graph neu oder betätigen Sie den Refresh-Button:

Das Bild zeigt die beiden Nodes teleop_turtle und turtlesim. Das Topic, mit dem diese beiden

Nodes kommunizieren ist turtle1/command_velocity.

1.12.3.2 Rostopic echo

Mit diesem Kommando werden die Daten die über das Topic gesendet werden angezeigt.

pi@raspberrypi_d204:~ $ rostopic echo /turtle1/cmd_vel

linear:

x: 0.0

y: 0.0

z: 0.0

angular:

x: 0.0

y: 0.0

z: -2.0

---

Page 33: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 33 - 60

1.12.4 Build einzelner Packages (Tutorials)

Mit der folgenden Anweisung werden die Tutorials übersetzt:

~/ros_catkin_ws $ sudo ./src/catkin/bin/catkin_make_isolated --pkg ros_tutorials

Zuerst muss gesourct werden:

~/ros_catkin_ws $ source ./devel_isolated/setup.bash

1.12.4.1 Publisher und Subscriber

Dann kann der Talker (Publisher) gestartet werden:

~/ros_catkin_ws $ rosrun roscpp_tutorials talker

und anschließend der Listener

~/ros_catkin_ws $ rosrun roscpp_tutorials listener

Die beiden Programme talker + listener können auch aus dem home Verzeichnis gestartet werden:

pi@raspberrypi:~ $ rosrun roscpp_tutorials talker

und

pi@raspberrypi:~ $ rosrun roscpp_tutorials listener

und das ist das Ergebnis:

Page 34: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 34 - 60

1.12.4.2 Server und Client

Zuerst wird der Server gestartet:

pi@raspberrypi:~ $ rosrun roscpp_tutorials add_two_ints_server

Anschließend starten Sie in einem weiteren Terminal den Client:

pi@raspberrypi:~ $ rosrun roscpp_tutorials add_two_ints_client 1 3

[ INFO] [1553447768.446576763]: Sum: 4

Im Serverfenster sehen Sie nun die Antwort:

pi@raspberrypi:~ $ rosrun roscpp_tutorials add_two_ints_server

[ INFO] [1553447768.445733330]: request: x=1, y=3

[ INFO] [1553447768.446003224]: sending back response: [4]

Im folgenden Bild ist zunächst im rechten Terminal der Start des Systems mit Aufruf von roscore

zu sehen und links die Terminals mit Server und Client:

Page 35: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 35 - 60

1.13 Turtlebot Dies ist eine kleine Sammlung von Hilfen für die Installation des Turtlepi.

Eine unverzichtbare Schritt für Schritt Anleitung zur Installation findet man unter:

http://emanual.robotis.com/docs/en/platform/turtlebot3/overview/

Wenn man als „Steuerrechner“ kein Linux aufsetzen möchte bietet die Oracle VirtualBox eine

ausgezeichnete Virtual Machine. Der Download ist selbsterklärend, für die Installation gibt es viele

Tutorials:

https://www.wintotal.de/tipp/virtualbox-anleitung/

Nach der erfolgreichen Installation steht Ihnen ein vollständiges Ubuntu zur Verfügung.

Das Bild zeigt Ubuntu als VM unter Windows.

1.13.1 Netzwerkeinstellungen

Für die Remoteverbindung mit dem TurtleBot gibt es mehrere Möglichkeiten. Selbstverständlich

benötigen Sie die Zugangsdaten:

User: pi

Passwort: turtlepi

Page 36: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 36 - 60

Eine Möglichkeit für den Remotezugang ist der Remote Desktop Viewer, dieser ist bereits in

Ubuntu vorhanden, ist intuitiv zu bedienen und funktioniert sehr gut. Für die Anmeldung

benötigen Sie nun die IP Adresse (im Beispiel 192.168.178.131) und die Anmeldedaten:

Falls ein zweiter Bildschirm verwendet wird ist es übersichtlicher auf dem ersten Bildschirm

z.B. mit VNC oder Remotedesktop mit dem TurtleBot zu verbinden (z.B. unter Windows) und

auf dem zweiten Bildschirm die Oracle VirtualBox mit Ubuntu laufen zu lassen.

Die ersten wichtigen Einstellugen sind die Netzwerkzugangsdaten zu dem TurtleBot. Details liefert

auch das das Online E-Manual:

Je nach Standort des Turtlebot die Einstellungen für die IP-Adressen des Turtlebot und des Host PC

passend geändert werden.

Am besten fügt man diese Einstellungen sowohl beim TurtleBot als auch beim RemotePC in die

Datei bashrc ein:

1.13.1.1 RemotePC:

1.13.1.2 TurtleBot:

#labor D204

#export ROS_MASTER_URI=http://192.168.10.189:11311

#export ROS_HOSTNAME=192.168.10.131

#daheim

export ROS_MASTER_URI=http://192.168.178.189:11311

export ROS_HOSTNAME=192.168.178.131

Page 37: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 37 - 60

1.13.2 Erstes Starten des TurtleBot

TurtleBot RemotePC 1

2 Eingabe am TurtleBot:

pi@turtlepi:~ $ roslaunch turtlebot3_bringup turtlebot3_robot.launch Ausschnitt der Antwort:

. . . .

Page 38: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 38 - 60

3 $ roslaunch turtlebot3_bringup turtlebot3_remote.launch

4 $ rosrun rviz rviz -d `rospack find turtlebot3_description`/rviz/model.rviz

5 $rosrun rqt_graph rqt_graph

Page 39: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 39 - 60

6 $ rostopic -- damit können viele Infos über die einzelnen Topics erhalten werden

Page 40: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 40 - 60

1.13.3 Erkennen eines Hindernisses

TurtleBot RemotePC

wie oben 1 – 2 $ roslaunch turtlebot3_example turtlebot3_obstacle.launch

Ausgabe am Terminal:

Page 41: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 41 - 60

1.14 Can-Bus9

sudo apt-get install can-utils

Die folgende Seite zeigt den Schaltpan eines CAN-Boards und die Schritte für das installieren des

Treibers:

https://github.com/GBert/misc/tree/master/RPi-MCP2517

cd /tmp

wget "https://github.com/GBert/misc/raw/master/RPi-MCP2517/bin/mcp2517fd-

rasp1+2+3.tar.gz"

cd / ; tar zxvf /tmp/mcp2517fd-rasp1+2+3.tar.gz

cat << EOF > /boot/config.txt

core_freq=250

kernel=ms7/zImage

device_tree=ms7/bcm2710-rpi-3-b.dtb

overlay_prefix=ms7/overlays/

dtoverlay=mcp2517fd-can0

dtparam=interrupt=25

dtparam=oscillator=4000000

dtparam=i2c_arm=on

EOF

reboot

Das Ändern der Datei /boot/config.txt kann mit VNC und dem Editor leafpad auch wie im

folgenden Bild gezeigt erfolgen:

9 https://www.raspberrypi.org/forums/viewtopic.php?t=141052

Page 42: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 42 - 60

1.15 Mosquitto Broker installieren

sudo apt-get install -y mosquitto mosquitto-clients

Nun sollte der Moquitto-Server bereits laufen. Das kann wie folgt einfach getestet werden:

mosquitto_sub -h localhost -v -t test

Mit diesem Befehl wird ein MQTT Subscriber gestartet, der auf Nachrichten im “Test”-Kanal

wartet.

Ansonsten starten Sie den Broker mit der Eingabe:

Mosquito -v

Jetzt kann man eine zweite Verbindung zum Raspberry Pi starten und eine Nachricht absetzen:

mosquitto_pub -h localhost -t test -m "Hello world, Mosquitto"

1.15.1 Wie kann ich den cc3100 mqtt Client mit Mosquitto Broker verbinden?

Wie ist der Hostname des Brokers? Es ist ganz einfach der Hostname des raspberrypi, siehe unten:

Also muss in mqtt_config.h der folgende Server eingetragen werden:

//#define SERVER_ADDRESS "broker.mqttdashboard.com" //#define SERVER_ADDRESS "iot.eclipse.org" #define SERVER_ADDRESS "raspberrypi"

Page 43: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 43 - 60

1.16 On-Board LED als GPIO

Sie müssen in der config.txt Datei die folgende Anweisung hinzufügen. Nach dem Reboot können

Sie über den GPIO20 die LED blinken lassen:

1.17 Webmin

Über Webmin gibt es eine weitere Möglichkeit den Raspberry über eine Weboberfläche zu

konfigurieren. Ob dies sinnvoll ist muss jeder für sich entscheiden:

https://192.168.178.112:10000/

1.18 VPN

1.18.1 Installieren

Mit Openconnect ist eine Verbindung des RaspberryPi über VPN möglich:

pi@raspberrypi_d204:~ $ sudo apt-get install openconnect

pi@raspberrypi_d204:~ $ sudo apt-get install network-manager-openconnect

1.18.2 Verwenden

Das Verbinden ist nun einfach:

pi@turtlepi:~ $ sudo openconnect -u [email protected] -b asa-cluster.lrz.de

Anschließend wird der Benutzer zur Eingabe der Gruppe aufgefordert. Hier wird aus den

angebotenen Alternativen „Anyconnect“ eingetragen.

Die Gruppe kann auch bereits auf der Kommandozeile eingetragen werden:

pi@turtlepi:~ $ sudo openconnect -g AnyConnect -u [email protected] -b asa-cluster.lrz.de

Nicht wundern über die unterschiedlichen Benutzernamen und –verzeichnisse. Es wurde am

„normalen“ Raspi3, am Turtlebot und am JetsonNano getestet.

Page 44: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 44 - 60

Dann wird der Benutzer zur Eingabe des Passworts aufgefordert. Ab diesem Zeitpunkt steht die

VPN Verbindung (gezeigt am Jetson Nano Board)

Die Verbindungsdaten liefert das Kommando ifconfig:

tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1350

inet 129.187.52.140 netmask 255.255.255.255 destination 129.187.52.140

inet6 fe80::3b30:cd8f:f7dc:5acc prefixlen 64 scopeid 0x20<link>

inet6 2001:4ca0:6fff:1::38 prefixlen 64 scopeid 0x0<global>

unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC)

RX packets 4821 bytes 326520 (318.8 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 5251 bytes 1122201 (1.0 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Die IP-Adresse des VPN Zugangs ist in diesem Fall 129.187.52.140.

Page 45: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 45 - 60

1.19 Watchdog aktivieren und einrichten10

Laden des Kernelmoduls und anschließende Installation des Deamons: $ sudo apt-get install watchdog

$ sudo modprobe bcm2835_wdt

$ echo "bcm2835_wdt" | sudo tee -a /etc/modules

Anschließend muss noch die Konfigurationsdatei des Watchdog-Daemon angepasst werden, um die

Gerätedatei des Watchdogs und die Bedingungen für einen Reset festzulegen.

$ sudo leafpad /etc/watchdog.conf

In der Konfigurationsdatei müssen folgende beiden Zeilen auskommentiert werden (Raute-Zeichen

am Anfang der Zeile entfernen):

watchdog-device = /dev/watchdog

max-load-1 = 24

Betrifft nur Raspbian Jessie / Stretch (!) Bei Raspbian Jessie muss in der Datei /lib/systemd/system/watchdog.service noch folgender Eintrag

ergänzt werden:

[Install]

WantedBy=multi-user.target

!!Keine Ahnung ob dies auch bei Stretch gemacht werden muss?? Ich habs mal eingefügt (OP)

Zum Abschluss der Konfiguration muss der Watchdog-Daemon nun noch neu gestartet werden.

Fertig.

1.19.1.1.1 Raspbian Jessie / Stretch

$ sudo systemctl enable watchdog.service

$ sudo systemctl start watchdog.service

Wireshark installieren und starten

$ sudo apt-get install wireshark und starten

$ sudo wireshark

10 https://www.datenreise.de/raspberry-pi-stabiler-24-7-dauerbetrieb/

Page 46: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 46 - 60

1.20 Pairing mit Bluetooth (Beispiel ES32)1112 Das Beispiel zeigt die Verbindung mit der MAC 3C:71:BF:AA:99:CE.

In die folgende Datei müssen 2 Einträgein der folgenden Datei geändert werden:

pi@raspberrypi:~ $ sudo leafpad /etc/systemd/system/dbus-org.bluez.service

ExecStart=/usr/lib/bluetooth/bluetoothd -C

ExecStartPost=/usr/bin/sdptool add SP

Zuerst müssen Sie „scan, „pair“ und „trust“ durchführen. Dies geht auf der Kommandozeile mit

"bluetoothctl". Führen Sie dazu Folgendes in der Befehlszeile Ihres Terminals aus:

pi@raspberrypi:~ $ bluetoothctl -a [NEW] Controller B8:27:EB:10:3D:2B raspberrypi [default] [NEW] Device 3C:71:BF:AA:99:CE ESP32_InvPendel [NEW] Device B0:10:41:D8:29:D9 BRAVIA [NEW] Device 9C:8C:6E:47:E8:85 [TV] Samsung 6 Series (55) Agent registered [bluetooth]#

Der Vorgang “pair” und “trust” sieht folgendermaßen aus: [bluetooth]# pair 3C:71:BF:AA:99:CE Attempting to pair with 3C:71:BF:AA:99:CE Failed to pair: org.bluez.Error.AlreadyExists [bluetooth]# trust 3C:71:BF:AA:99:CE Changing 3C:71:BF:AA:99:CE trust succeeded [bluetooth]# Beenden von bluetoothctl:

[bluetooth]# quit Agent unregistered [DEL] Controller B8:27:EB:10:3D:2B raspberrypi [default] pi@raspberrypi:~ $ Diese Einstellungen bleiben beim Neustart erhalten und sind im Verzeichnis /var/lib/bluetooth

abgelegt!!13

11 https://raspberrypi.stackexchange.com/questions/53408/automatically-connect-trusted-bluetooth-speaker 12 https://www.raspberrypi.org/forums/viewtopic.php?p=947185#p947185 13 https://pi-buch.info/bluetooth-konfiguration-mit-bluetoothctl/

Page 47: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 47 - 60

Der Vorgang „pair“ und „trust“ kann auch im VNC-Viewer

durchgeführt werden:

Nun muss nur noch bind durchgeführt werden sudo rfcomm bind /dev/rfcomm0 3C:71:BF:AA:99:CE 1 Am besten arbeitet man mit zwei Konsolen:

Wenn man die MAC nicht weiß ist folgendes recht praktisch:

pi@raspberrypi:~ $ hcitool scan

Scanning ...

3C:71:BF:AA:A5:9E ESP32_InvPendel

B0:10:41:D8:29:D9 BRAVIA

pi@raspberrypi:~ $

Für das Ansehen der Daten eignet sich am besten das Terminalprogramm cutecom . Dieses

Programm entpricht dem Programm Teraterm unter Windows.

Page 48: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 48 - 60

Page 49: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 49 - 60

1.21 Pinbelegung

Page 50: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 50 - 60

1.22 WiringPi Zuordnung

Der Befehl liefert allerding die Zuordnung für die Revision 2. Für die Revision 1 gibt es drei

Unterschiede bei den Zuordnungen zu den BCM GPIO Bezeichnungen:

Page 51: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 51 - 60

1.23 Raspi als WLAN Bridge

Als Basis für eine funktionsfähige Konfiguration gibt es mehrere Tutorials, mit Änderungen 14.

Zuerst immer das Betriebssystem aktualisieren:

sudo apt-get update

sudo apt-get upgrade

Der folgende Text stammt aus der obengenannten Webseite:

„Dann brauchen wir zwei Dinge: Einmal einen Access-Point-Daemon und eine Software für die

Netzwerk-Brücke. Der Host Access Point Daemon (HostAPD), kurz "hostapd", ist ein WLAN-

Authenticator. Er kümmert sich darum, WLAN-Funktionen verschlüsselt anzubieten und die dazu

notwendige Authentifizierung der WLAN-Clients vorzunehmen. Beispielsweise per WPA2-PSK.

"bridge-utils" enthält Bibliotheken und Kommandos, um Netzwerk-Brücken einzurichten.

sudo apt-get install hostapd bridge-utils

Nach der Installation geht es an die Konfiguration des WLAN-AP-Hosts und der Netzwerk-

Brücke.“

1.23.1 WLAN-AP-Host konfigurieren (hostapd)

Die Konfiguration des WLAN-AP-Hosts:

sudo leafpad /etc/hostapd/hostapd.conf

Die Datei sollte noch nicht vorhanden und somit leer sein. Wenn die Datei doch vorhanden ist, dann

muss sie vollständig überschrieben werden.

In die Datei tragen wir folgende Minimal-Konfiguration ein. Selbstverständlich gibt es noch mehr

Parameter, die in diesem Fall keine Rolle spielen:

# Test oparz

# Bridge-Betrieb

interface=wlan0

bridge=br0

#driver=nl80211

ssid=NameOfNetwork

hw_mode=g

channel=7

wmm_enabled=0

macaddr_acl=0

auth_algs=1

ignore_broadcast_ssid=0

wpa=2

wpa_passphrase=testtest

wpa_key_mgmt=WPA-PSK

wpa_pairwise=TKIP

rsn_pairwise=CCMP

14 https://www.elektronik-kompendium.de/sites/raspberry-pi/2002161.htm

Page 52: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 52 - 60

Nun muss die folgende Datei modifiziert werden

sudo leafpad /etc/dhcpcd.conf

Diese beiden Zeilen müssen eingefügt werden:

# For use as a bridge oparz

denyinterfaces wlan0

denyinterfaces eth0

Die Zeilen müssen vor den (interface eth0 bzw. interface wlan0) Anweisungen eingefügt werden!!

Nun wird mit dem folgenden Tutorial gearbeitet15

Fügen Sie eine neue Bridge ein, in dem Fall br0

sudo brctl addbr br0

Nun wird der Port eth0 zur Bridge br0 verbunden.

sudo brctl addif br0 eth0

Da im Beispiel mit systemd gearbeitet wird müssen nun noch einige Files erstellt bzw. editiert

werden:

sudo leafpad /etc/systemd/network/bridge-br0.netdev

[NetDev]

Name=br0

Kind=bridge

Anschließend muss das Bridge Interface br0 und das Slave-Interface eth0 mit .network konfiguriert

werden:

sudo leafpad /etc/systemd/network/bridge-br0-slave.network

[Match]

Name=eth0

15 https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md

Page 53: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 53 - 60

[Network]

Bridge=br0

sudo nano /etc/systemd/network/bridge-br0.network

[Match]

Name=br0

[Network]

Address=192.168.178.190/24

Gateway=192.168.178.1

#DNS=8.8.8.8

DNS=192.168.178.1

Neustarten des Daemons:

sudo systemctl restart systemd-networkd

Nun muss der Raspi neu gestartet werden

sudo reboot now

Nach den folgenden Befehlen ist die Bridge funkrionsfähig:

sudo systemctl unmask hostapd

sudo systemctl enable hostapd

sudo systemctl start hostapd

Der Befehl ifconfig liefert nun die Einstellung der Bridge br0, die Schnittstellen eth0 und wlan0

haben nun keine IP-Adressen mehr:

pi@raspberrypi:~ $ ifconfig

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.178.190 netmask 255.255.255.0 broadcast 192.168.178.255

inet6 fe80::ba27:ebff:fe16:daaf prefixlen 64 scopeid 0x20<link>

ether b8:27:eb:16:da:af txqueuelen 1000 (Ethernet)

RX packets 46470 bytes 4937124 (4.7 MiB)

RX errors 0 dropped 25426 overruns 0 frame 0

TX packets 6928 bytes 2798667 (2.6 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Page 54: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 54 - 60

1.23.2 Anwendungsbeispiel TurtleBot 3 über Bridge mit Router verbinden

Page 55: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 55 - 60

1.24 RemoteDesktopverbindung Ubuntu

Zunächst muss installiert werden:

apt-get install mate-core mate-desktop-environment mate-notification-daemon xrdp

2 Matlab und Raspberrypi

>> rpi = raspi('192.168.178.180','pi','raspberry');

>> showLEDs(rpi);

>> led = rpi.AvailableLEDs{1};

>> writeLED(rpi, led, 0);

>> writeLED(rpi, led, 1);

>> for i = 1:10

writeLED(rpi, led, 0);

pause(0.5);

writeLED(rpi, led, 1);

pause(0.5);

end

>> system(rpi, 'ls -al /home/pi')

ans =

'insgesamt 124

drwxr-xr-x 19 pi pi 4096 Jan 20 11:23 .

drwxr-xr-x 3 root root 4096 Mai 27 2020 ..

. . . . . . . . .

-rw-r--r-- 1 pi pi 8781 Jul 9 2020 .xscreensaver

-rw------- 1 pi pi 881 Jan 20 11:24 .xsession-errors

-rw------- 1 pi pi 881 Jan 20 09:02 .xsession-errors.old

'

Page 56: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 56 - 60

Die Befehle können natürlich in einem Script gespeichert werden (test.mlx):

3 Matlab und ROS

Zuerst muss Python installiert sein (Anleitung im Internet).

>> pe=pyenv;

Einstellen der Python Umgebung:

>> pe = pyenv('Version',"C:\Python27\Python.exe")

pe =

PythonEnvironment with properties:

Version: "2.7"

Executable: "C:\Python27\Python.exe"

Library: "C:\Windows\system32\python27.dll"

Home: "C:\Python27"

Status: NotLoaded

ExecutionMode: InProcess

Damit sind die Vorbereitungen abgeschlossen und ROS kann gestartet werden.

4 Jetson Nano

1. Remotedesktop verbindung mit dem jetson nano…vnc ist langsam (nicht

empfehlenswert)

2. Vorlesungsanleitung für Demonstration:

1. Terminalverbinding über putty: user oparz und pw 1234567

2. Remotedesktop um die Bilder anzuzeigen, die von der Software erzeugt

werden

3. WinSCP um neue Bilder vom Windows PC zu laden

3. Verzeichnis der Beispiel Binaries auswählen:

1. oparz@oparz-desktop:~/jetson-inference/build/aarch64/bin$

Page 57: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 57 - 60

4. Es gibt zwei Beispielanwendungen für Deep Learning Algos:

1. Bilderkennung mit Wahrscheinlichkeite dass Objekte erkannt werden:

• ./imagenet-console --network=resnet-152 peds-002.jpg output_0.jpg

2. Objekterkennung über begrenzende Rechtecke

• ./detectnet-console peds-002.jpg output_0.jpg

• Es können hier auch verschiedene „Netzwerke“ angegeben werden:

• facenet für Gesichtserkennung

• Multiped für mehrere Menschen

• Etc…

5. https://github.com/dusty-nv/jetson-inference/blob/master/docs/detectnet-console-

2.md

Webseiten:

Statistik über Temperatur etc..

https://pypi.org/project/jetson-stats/

Tutorials:

https://github.com/dusty-nv/jetson-inference/blob/master/docs/pytorch-transfer-learning.mdypi

5 NodeMCU Kleines und sehr preiswertes Mikrocontrollerboard mit integrtriertem WLAN, ideal für das

„Internet of Things“. Die Basis bildet der ESP32 bzw. ESP8266 Mikrocontroller von Espressif.

Für die Programmierung bietet sich die Arduino IDE bzw. das Visual Studio Plugin (vMicro16) an.

16 www.visualmicro.com

Page 58: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 58 - 60

Die verschiedenen erhältlichen ESP8266/ESP32 -Module unterscheiden sich nicht in der

Programmierung. Die wesentlichen Unterschiede sind die Anzahl und die Art der bereitgestellten

Ports (GPIOs) als auch der verfügbare Speicherplatz. Das kleine ESP-01-Modul hat beispielsweise

512 kB Flash-Speicher und das beliebte ESP-12E 4 MByte Flash-Speicher.

Das Board eignet sich gut für C-Programmierer. Im Grunde braucht man nur das USB-Kabel

einstecken und kann loslegen, es muss nichts mehr speziell für die Programmierung verkabelt

werden, was die Sache sehr komfortabel macht.

Für die Projekterstellung mit der Arduino IDE gibt es ausgezeichnete Tutorials:

https://randomnerdtutorials.com/installing-the-esp32-board-in-arduino-ide-windows-instructions/

https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/

Page 59: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 59 - 60

Vergleich der beiden häufigsten Vertreter der Mikrocontroller auf den NodeMCU Boards:

Page 60: Prof. Dr.-Ing. Otto Parzhuber Labor D204dodo.fb06.fh-muenchen.de/parzhuber/Raspberry.pdf · Prof. Dr.-Ing. Otto Parzhuber Labor D204 07.10.2020 Prof. Dr.-Ing. O. Parzhuber, Email:

Prof. Dr.-Ing. Otto Parzhuber Labor D204

14.03.2021 Prof. Dr.-Ing. O. Parzhuber, Email: [email protected], Hochschule München FK 06, Mechatronik

Datei: Raspberry.docx Seite 60 - 60

Beispielprojekt MQTT


Recommended