diff --git a/doc/softwareSetup/stmSetup.txt b/doc/softwareSetup/stmSetup.txt index d756f25f2e3d0b54aae2569941aa60553e9f6a09..3d1f5401fa3dad894b8096f6dc9aca062246407b 100644 --- a/doc/softwareSetup/stmSetup.txt +++ b/doc/softwareSetup/stmSetup.txt @@ -1,13 +1,21 @@ -Dieses Dokument dient als Anleitung für die Kompilierung des Codes auf dem STM +Dieses Dokument dient als Anleitung für Kompilieren und Flashen von Code aufs STM + +Schritte: +1. Ort der Dateien +2. Voraussetzungen für Kompilation +3. Notwendige Korrekturen für Kompilation +4. Kompilation +5. Mögliche Fehler +6. Installation der Tools fürs Flashen +7. Flashen mit GUI (optional) +8. Flashen mit CLI (mit Skript) + 1. STM-Files - Dateien herunterladen von - https://www.dropbox.com/l/scl/AABtsAyzx1MIZBJeAg0Nz5LGSd3bH9qCfmM + Dateien herunterladen aus der Dropbox von Oliver Kreuzmann Dann speichern und entpacken unter z.B. ~/Documents - Im Repo sind bereits alle Änderungen gemacht - 2. Einrichten der ARM-Toolchain (Zusatzinformationen: https://gnu-mcu-eclipse.github.io/toolchain/arm/install/) @@ -22,7 +30,7 @@ Dieses Dokument dient als Anleitung für die Kompilierung des Codes auf dem STM $ mkdir -p ~/opt $ cd ~/opt $ tar xjf ~/Downloads/gcc-arm-none-eabi-4_8-2014q2-20140609-linux.tar.bz2 - $ chmod -R -w ~/opt/gcc-arm-none-eabi-4_8-2014q2-20140609 + $ chmod -R -w ~/opt/gcc-arm-none-eabi-4_8-2014q2 Testen ob die Toolchain läuft: @@ -31,11 +39,16 @@ Dieses Dokument dient als Anleitung für die Kompilierung des Codes auf dem STM Erwartete Ausgabe: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.8.4 20140526 (release) [ARM/embedded-4_8-branch revision 211358] ... -3. Ändern der STM-Files + +3. Korrigieren der STM-Files + Im Repo sind bereits alle Änderungen gemacht $ cd ~/Documents/Austausch\ Assystem\ -\ HU/02_lieferung/vehicle_ecu_sw/quellcode/ - Ändern der jeweiligen Dateien + Es wird die Datei nano.specs benötigt + $ cp ~/opt/gcc-arm-none-eabi-4_8-2014q2/arm-none-eabi/lib/nano.specs . + + Änderungen sind in den folgenden Dateien notwendig, suchen der entsprechenden Zeile und ersetzen makefile: /home/jenkins/ARM_GCC/2014q2/bin @@ -136,7 +149,7 @@ Dieses Dokument dient als Anleitung für die Kompilierung des Codes auf dem STM Gehe zu http://ecmc.rochester.edu/ecmc/docs/supercollider/scbook/Ch23_Dialects/extensions_c23_dialects/ENIAC/Eniac_Cycling%20Source%20Code/rtwtypes.h - Speichern unter ~/Documents/Austausch\ Assystem\ -\ HU/02_lieferung/vehicle_ecu_sw/quellcode/sys + Speichere Datei in sys, z.B. unter ~/Documents/Austausch\ Assystem\ -\ HU/02_lieferung/vehicle_ecu_sw/quellcode/sys sys/matlab/rtGetNaN.h:34 @@ -157,6 +170,8 @@ Dieses Dokument dient als Anleitung für die Kompilierung des Codes auf dem STM #include "rtwtypes.h" + Die Änderungen in cpx sind nicht notwendig, da im makefile alle Dateien aus cpx entfernt wurden + cpx/foccomplex/foccomplex.h:52 #include "curmon.h" #include "angmon.h" @@ -188,16 +203,60 @@ Dieses Dokument dient als Anleitung für die Kompilierung des Codes auf dem STM #include "brd/startup/stm32f4xx.h" - Umbennen von cpx zu cpx2 +4. Kompilation + $ cd ~/Documents/Austausch\ Assystem\ -\ HU/02_lieferung/vehicle_ecu_sw/quellcode/ + $ make + + Bei Erfolg: + + ~/opt/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-gcc obj/app/rx24fctrl/src/rx24fctrl.o obj/app/main.o ... + ... + ~/opt/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-objcopy -O binary vlx.elf vlx.bin + -e \x1b[32;01mFinished Compiling and Linking\x1b[0m -4. Mögliche Kompilationsfehler: + +5. Mögliche Kompilationsfehler: - /home/opt/gcc-arm-none-eabi-4_8-2014q2/bin/arm-none-eabi-gcc: Command not found - Lösung: Instllation der ARM_Toolchain + Lösung: Installation der ARM_Toolchain - In file included from ... No such file or directory - Lösung: #includes fehlerhaft + Lösung: #includes korrigieren, siehe 3. + + +6. Installation stlink-gui, st-flash + https://startingelectronics.org/tutorials/STM32-microcontrollers/programming-STM32-flash-in-Linux/ + + $ sudo apt-get install libusb-1.0-0-dev git + $ sudo apt-get install libgtk-3-dev + $ cd ~/Git + $ git clone https://github.com/texane/stlink + $ cd stlink + $ make + $ cd build/Release + $ sudo make install + $ sudo ldconfig + + +7. Benutzen von stlink-gui + Verbinde Rechner und STM mit USB-to-miniUSB + + $ stlink-gui + + Schreibe in Goto address den Wert + 0x08000000 + + Klicke connect + ... (Klicke Flash, Disconnect, unklar da nur st-flash von uns benutzt wird) + + +8. Benutzen von st-flash + Erstelle Skript, z.B. run.sh, mit Inhalt: + + #use in quellcode + make && st-flash erase && st-flash write vlx.bin 0x0800000 && st-flash reset + + Folgendermaßen können Änderungen vorgenommen werden: + 1. Ändern des Codes + 2. Ausführen des Skriptes + -5. TODO: - - in cpx/foccomplex/foccomplex.h stehen Dateien, welche nicht vorhanden sind - - in cpx/foccomplex/src/foccomplex stehen Dateien, welche nicht vorhanden sind - - es kompiliert nur bei Umbenennung von cpx zu cpx2 diff --git a/modules/catkin_ws/src/car/include/ultrasonic/USS_SRF02.h b/modules/catkin_ws/src/car/include/ultrasonic/USS_SRF02.h new file mode 100644 index 0000000000000000000000000000000000000000..092d475a8a2655b6557273e0eabe44676bca49b9 --- /dev/null +++ b/modules/catkin_ws/src/car/include/ultrasonic/USS_SRF02.h @@ -0,0 +1,21 @@ +#ifndef USS_SRF02_H_ +#define USS_SRF02_H_ + +class USS_SRF02{ + +public: + USS_SRF02(int devId); + + int getDistance(); + +private: + + void setup(); + + int devId; + + int fd; +}; + + +#endif /* USS_SRF02_H_ */ diff --git a/modules/catkin_ws/src/car/src/ultrasonic/USS_SRF02.cpp b/modules/catkin_ws/src/car/src/ultrasonic/USS_SRF02.cpp new file mode 100644 index 0000000000000000000000000000000000000000..85243aad010d5cc6f31325258c3859016e084018 --- /dev/null +++ b/modules/catkin_ws/src/car/src/ultrasonic/USS_SRF02.cpp @@ -0,0 +1,63 @@ +#include "../include/USS_SRF02.h" +#include "../lib/wiringPi/wiringPi/wiringPiI2C.h" + +#include <iostream> + +#include <unistd.h> + +//gpio pins where the sonar is connected +const int SRF02_SDA = 8; //i2c data pin ; +const int SRF02_SCL = 9; //i2c clock pin ; + +// addresses of the sonars, the number is also as a sticker on the devices themselves +const int DEVICE_ADDRESS1 = 0x74; +const int DEVICE_ADDRESS2 = 0x76; +const int DEVICE_ADDRESS3 = 0x77; + +//path to i2c file +const char *DEVICE = "/dev/i2c-1"; + +const int COMMAND_REGISTER = 0x00; +const int RESULT_HIGH_BYTE = 0x02; +const int RESULT_LOW_BYTE = 0x03; +const int RANGING_MODE_CM = 0x51; + +const int DELAY = 70; //70 ms for ranging to finish + +int main() { + + USS_SRF02 uss(0x74); + + while(1){ + std::cout << uss.getDistance() << std::endl; + } + return 0; +} + +USS_SRF02::USS_SRF02(int devId) { + this->fd = -1; //no file opened yet + this->devId = devId; +} + +int USS_SRF02::getDistance() { + int distance; + + if(fd == -1){ + USS_SRF02::setup(); + } + + wiringPiI2CWriteReg8(fd, COMMAND_REGISTER, RANGING_MODE_CM); + usleep(DELAY * 1000); + distance = wiringPiI2CReadReg16(fd, RESULT_LOW_BYTE); + + return distance; +} + +void USS_SRF02::setup() { + + USS_SRF02::fd = wiringPiI2CSetupInterface(DEVICE, this->devId); + //todo error handling, + //however wiringPiI2CSetupInterface() calls exit() if it fails + + +}