diff --git a/.~lock.ideen_mechanik_und_elektronik.odt# b/.~lock.ideen_mechanik_und_elektronik.odt# index affc95a..0e6d32f 100644 --- a/.~lock.ideen_mechanik_und_elektronik.odt# +++ b/.~lock.ideen_mechanik_und_elektronik.odt# @@ -1 +1 @@ -,yves,yves-UB,05.02.2020 13:15,file:///home/yves/.config/libreoffice/4; \ No newline at end of file +,yves,yves-UB,05.02.2020 13:51,file:///home/yves/.config/libreoffice/4; \ No newline at end of file diff --git a/Code/miniRobot/miniRobot.ino b/Code/miniRobot/miniRobot.ino index bcb2398..452f374 100644 --- a/Code/miniRobot/miniRobot.ino +++ b/Code/miniRobot/miniRobot.ino @@ -12,6 +12,9 @@ RF24 radio(A0, 3); // CE, CSN byte commands[32]; //byte 0 = command +unsigned long timer; +int16_t temperature = 0; +uint16_t distance = 50; void inline clearCommands() { for(uint8_t i=0; i<32; i++) { @@ -20,6 +23,7 @@ void inline clearCommands() { } const byte address[6] = "00001"; +const byte address2[6] = "00002"; //Kommandos #define nothing 9 //reset/nichts tun #define speedA 1 // set speed A + speed @@ -30,7 +34,7 @@ const byte address[6] = "00001"; #define stopDrive 6 //stop #define getTemp 7 //get temperature #define timeToDrive 8 //Zeitdauer des fahrens -#define distance 10 //Abstand zu Objekten +#define getDistance 10 //Abstand zu Objekten //Motortreiber //#include @@ -57,9 +61,6 @@ bool forwardA = true; bool forwardB = true; volatile bool driveOn = false; -int temperatur = 0; - - volatile long driveTimeout = 0; volatile long driveTimeDiff = 0; @@ -68,13 +69,39 @@ void setup() { // motorA.setPWM16(2,RESOLUTION); // motorB.setPWM16(2,RESOLUTION); radio.begin(); - radio.openReadingPipe(0, address); + radio.openWritingPipe(address2); + radio.openReadingPipe(1, address); radio.setPALevel(RF24_PA_MAX); radio.startListening(); clearCommands(); + + //Temperatur- und Abstandsmessung + + setEchoPins(16, 6); //16: A2, 6: D6 + tempDistSetup(); + timer = millis(); } void loop() { + //Temperatur- und Abstandsmessung + //Serial.println(temperature); + //Serial.println(distance); + + + unsigned long currentMillis = millis(); + + if((unsigned long)(currentMillis - timer) >= 100){ + temperature = dallas(4, 0); + measureDistance(); + distance = calculateDistance(); + Serial.println(distance); + timer = currentMillis; + + } + + + + if (radio.available()) { radio.read(&commands, sizeof(commands)); commandInterpretation(); @@ -84,8 +111,22 @@ void loop() { pwmA = 0; pwmB = 0; } + + + if(distance < 20){ + //Serial.println("Achtung!"); + if(pwmA < 0 && pwmB < 0){ + pwmA = 0; + pwmB = 0; + } + } + + drive.setPWM_A(pwmA); drive.setPWM_B(pwmB); + + + } void commandInterpretation() { @@ -130,9 +171,12 @@ void commandInterpretation() { driveOn = false; break; } - case getTemp : { - temperatur = (0xFF00 & (commands[i+1] << 8)); - temperatur |= (0x00FF & commands[i+2]); + case getTemp : { + //Serial.println("Senden!"); + radio.stopListening(); + int16_t sendData = temperature; + radio.write(&sendData, sizeof(int16_t)); + radio.startListening(); break; } case timeToDrive : { @@ -149,9 +193,11 @@ void commandInterpretation() { forwardA = true; forwardB = true; driveOn = false; */ + break; } } } + clearCommands(); } diff --git a/Code/miniRobotRC/temperatureDistance.ino b/Code/miniRobot/temperatureDistance.ino similarity index 74% rename from Code/miniRobotRC/temperatureDistance.ino rename to Code/miniRobot/temperatureDistance.ino index 637be31..a3e977c 100644 --- a/Code/miniRobotRC/temperatureDistance.ino +++ b/Code/miniRobot/temperatureDistance.ino @@ -2,17 +2,18 @@ #define maxDistance 400 -int trig = 0; -int echo = 0; +int trig; +int echo; -//int distance = 0; -int distance2 = 0; +uint16_t distance3 = 0; +uint16_t distance2 = 0; //ISR for PCINT20 ISR(PCINT2_vect) { - distance = pulseIn(echo, HIGH); - if(distance > 0){ - distance2 = distance; + distance3 = pulseIn(echo, HIGH); + + if(distance3 > 0){ + distance2 = distance3; } delayMicroseconds(10); @@ -25,25 +26,23 @@ void setEchoPins(int pin1, int pin2){ echo = pin2; } -int calculateDistance(){ - int result = distance2/ 58; - - if(result > maxDistance){ - result = maxDistance; +int16_t calculateDistance(){ + int16_t result2 = distance2/ 58; + if(result2 > maxDistance){ + result2 = maxDistance; } - return result; + return result2; } void measureDistance(){ - PORTD |= (1< #include -long timer; - void inline clearCommands() { for(uint8_t i=0; i<32; i++) { commands[i] = 0xFF; @@ -17,19 +15,17 @@ void setup() { driveTimeout = 10; joystickInit(); //TODO clearCommands(); - //Temperatur- und Abstandsmessung - tempDistSetup(); - setEchoPins(0, 0); //Setze die pins für den Abstandsensor aus denen gelesenw erden soll das erster ist der Trigger-, das zweite der Echopin - timer = millis(); + } void loop() { //lcdMenu(); + while(!tasten.getButtonCycle(buttonStart)) { manualDigitalDrive(); } tasten.clearButton(buttonStart); - while(!tasten.getButtonCycle(buttonStart)){ + while(!tasten.getButtonCycle(buttonStart)){ motorMapping(); } tasten.clearButton(buttonStart); @@ -40,6 +36,7 @@ void loop() { } tasten.clearButton(buttonStart); +<<<<<<< HEAD //Temperatur- und Abstandsmessung /* temperature = dallas(4, 0); @@ -51,6 +48,8 @@ void loop() { distance = calculateDistance(); */ +======= +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 } void lcdMenu() { diff --git a/Code/miniRobotRC/fahrsteuerung_old.ino b/Code/miniRobotRC/fahrsteuerung_old.ino index 3d9dc04..eef130b 100644 --- a/Code/miniRobotRC/fahrsteuerung_old.ino +++ b/Code/miniRobotRC/fahrsteuerung_old.ino @@ -1,37 +1,62 @@ void manualDigitalDrive() { + bool goOn = false; + String temp_str = "T: " + String(temperature) + " Grad C"; + lcdLines[5] = temp_str; // while(!tasten.getButtonCycle(buttonL1)) { clearCommands(); if(!tasten.getAnyPressed()) { +<<<<<<< HEAD //lcd.clear(); lcd.println("Warte..."); +======= + lcdLines[0] = "Warte..."; + + +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 } if(tasten.checkButton(buttonB) || tasten.checkButton(buttonUp)) { pwmA = -215; pwmB = -255; +<<<<<<< HEAD //lcd.clear(); lcd.println("geradeaus fahren"); +======= + lcdLines[0] = "geradeaus fahren"; +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 goOn =true; } if(tasten.checkButton(buttonC) || tasten.checkButton(buttonDown)) { pwmA = 100; pwmB = 255; +<<<<<<< HEAD //lcd.clear(); lcd.println("rueckwaerts fahren"); +======= + lcdLines[0] = "rueckwaerts fahren"; +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 goOn =true; } if(tasten.checkButton(buttonRight)) { pwmA = -100; //rechter Motor pwmB = 100; +<<<<<<< HEAD //lcd.clear(); lcd.println("rechts lenken"); +======= + lcdLines[0] = "rechts lenken"; +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 goOn =true; } if(tasten.checkButton(buttonLeft)) { pwmB = -100; pwmA = 100; +<<<<<<< HEAD //lcd.clear(); lcd.println("links lenken"); +======= + lcdLines[0] = "links lenken"; +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 goOn =true; } if(goOn) { @@ -45,9 +70,39 @@ void manualDigitalDrive() { commands[7] = highByte(driveTimeout); commands[8] = lowByte(driveTimeout); commands[9] = goDrive; + radio.write(&commands, sizeof(commands)); goOn = false; } + + //Temperatur <3 + unsigned long currentMillis = millis(); + if((unsigned long)(currentMillis - temp_time) >= 1000){ // jede Sekunden + temp_time = millis(); + bool err = false; + clearCommands(); + + commands[0] = getTemp; + radio.write(&commands, sizeof(commands) && !err); + unsigned long start = micros(); + radio.startListening(); + while(!radio.available()){ + //Serial.println("nix"); + unsigned long currentMicros = micros(); + if((unsigned long)(currentMicros - start) >= 1){ + + err = true; + } + } + if(!err){ + int16_t readData; + radio.read(&readData, sizeof(int16_t)); + temperature = readData; + } + radio.stopListening(); + clearCommands(); + } + // } // tasten.clearAllButtons(); } diff --git a/Code/miniRobotRC/funkInit.ino b/Code/miniRobotRC/funkInit.ino index 308995f..fa40d29 100644 --- a/Code/miniRobotRC/funkInit.ino +++ b/Code/miniRobotRC/funkInit.ino @@ -1,6 +1,8 @@ void funkInit() { radio.begin(); + radio.openWritingPipe(address); + radio.openReadingPipe(1, address2); radio.setPALevel(RF24_PA_MAX); radio.stopListening(); } diff --git a/Code/miniRobotRC/interruptRoutinen.ino b/Code/miniRobotRC/interruptRoutinen.ino index cce5cf5..09ca807 100644 --- a/Code/miniRobotRC/interruptRoutinen.ino +++ b/Code/miniRobotRC/interruptRoutinen.ino @@ -3,6 +3,11 @@ ISR(TIMER2_COMPA_vect) { tasten.checkButtons(); renderTime++; if(renderTime >= renderTimeout) { + lcd.clear(); + for(uint8_t i = 0; i < sizeof(lcdLines); i++) { + lcd.gotoXY(0, i); + lcd.print(lcdLines[i]); + } lcd.renderAll(); renderTime = 0; } diff --git a/Code/miniRobotRC/joystick.ino b/Code/miniRobotRC/joystick.ino index be1ead8..1abf753 100644 --- a/Code/miniRobotRC/joystick.ino +++ b/Code/miniRobotRC/joystick.ino @@ -10,28 +10,8 @@ volatile int16_t yValue = 0; volatile int16_t leftPWM = 0; volatile int16_t rightPWM = 0; -const int16_t deadZone = 10; -/* -void setup() { - Serial.begin(115200); -} - -void loop() { - koordinaten(analogRead(xPin), analogRead(yPin)); - motorPWM(); - Serial.print("X: "); - Serial.println(xValue); - Serial.print("Y: "); - Serial.println(yValue); - Serial.print("links: "); - Serial.println(leftPWM); - Serial.print("rechts: "); - Serial.println(rightPWM); - - delay(200); +const int16_t deadZone = 40; -} -*/ void motorMapping() { static long temp = millis(); koordinaten(analogRead(xPin), analogRead(yPin)); @@ -40,12 +20,23 @@ void motorMapping() { pwmB = map(leftPWM, -255,255,leftMin,leftMax); pwmA = map(rightPWM, -255,255,rightMin,rightMax); if((millis() - temp) > 100) { +<<<<<<< HEAD //lcd.clear(); lcd.println("Links: "); lcd.println(pwmB); lcd.gotoXY(0,2); lcd.println("Rechts: "); lcd.println(pwmA); +======= + // lcd.clear(); + // lcd.println("Links: "); + lcdLines[0] = "Links: " + String(pwmB, DEC); + // lcd.println(pwmB); + // lcd.gotoXY(0,2); + // lcd.println("Rechts: "); + lcdLines[0] = "Rechts: " + String(pwmA, DEC); + // lcd.println(pwmA); +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 } senden(); diff --git a/Code/miniRobotRC/miniRobotRC.ino b/Code/miniRobotRC/miniRobotRC.ino index 898b88b..f93a12c 100644 --- a/Code/miniRobotRC/miniRobotRC.ino +++ b/Code/miniRobotRC/miniRobotRC.ino @@ -4,7 +4,7 @@ #define CLR_BIT(p,n) ((p) &= ~((1) << (n))) #define SET_BIT(p,n) ((p) |= (1 << (n))) - +//Pinzuordnungen #define BL 10 //backlight, Hintergrundbeleuchtung LCD #define SD_CARD_CS 2 //D2 ist Chip Enable #define BAT_VOLTAGE A7 //Akkuspannung an A7 @@ -17,7 +17,8 @@ volatile myInterrupts pwmBL; volatile shiftRegButton tasten; //LCD uint8_t renderTime = 0; -#define renderTimeout 100 +#define renderTimeout 100 //es wird alle 100ms gerendert +String lcdLines[6]; //Strings welche alle 100ms ausgegeben werden //Kommandos #define nothing 9 //reset/nichts tun @@ -31,15 +32,17 @@ uint8_t renderTime = 0; #define timeToDrive 8 //Zeitdauer des fahrens #define getDistance 10 //Abstand zu Objekten -int pwmA = 0; -int pwmB = 0; +int16_t pwmA = 0; +int16_t pwmB = 0; bool forwardA = true; bool forwardB = true; bool driveOn = false; uint16_t driveTimeout = 0; -int distance; -int temperature; +uint8_t distance; +uint8_t temperature = 0; + +unsigned long temp_time = millis(); //Funk #include @@ -49,25 +52,6 @@ int temperature; RF24 radio(A2, A3); // CE, CSN const byte address[6] = "00001"; +const byte address2[6] = "00002"; uint8_t commands[32]; -/* -const String mainMenu[] = { - "fahren", //0 - "stoppen", //1 - "manuell fahren", //2 - "", //3 - "", //4 - "", //5 - "", //6 - "", //7 - "", //8 - "" //9 -}; - -const String subMenuEntry0[] = { - "Zeitdauer", - "Speed A", - "Speed B", - "Starten" -}; */ diff --git a/Latex/main.tex b/Latex/main.tex index dbf07ff..ef33a9c 100644 --- a/Latex/main.tex +++ b/Latex/main.tex @@ -229,12 +229,16 @@ const byte address[6] = "00001"; \end{file} Damit sind bereits Sämtliche Konfigurationen für die Hardware-SPI Kommunikation zwischen Arduino nano und dem nRF24L01 erledigt. +<<<<<<< HEAD Kommunizieren zwischen zwei dieser Setups wird dann durch die Funktionen read und wirite, jedoch muss vor dem Start einer Kommunikation die Methoden begin(), openWritingPipe(address) mit address als Kommunikationsleitung und stopListening() bei Sender bzw startListening() beim Empfänger aufgerufen werden. Die Methode setPALevel() setzt den Power Amplifiyer Level umso höher dieser Wert umso Stärker das Signal, wodurch der Stromverbrauch Steigt. Der Anstieg des Stromverbrauchs kann auch bei einer nicht ganz konstanten Stromversorgung dazu führen das das Modul nicht korrekt funktioniert. +======= + Kommunizieren zwischen zwei dieser Setups wird dann durch die Funktionen read und write, jedoch muss vor dem Start einer Kommunikation die Methode begin() aufgerufen werden. +>>>>>>> 48327ec5c42c4d70afa8e9c00bbf52ab2db2ca05 \begin{file}[RF24 initialisieren] \begin{lstlisting}[language=C++] //An der Sender Seite @@ -273,7 +277,9 @@ if (radio.available()) { %Folgende beiden ließen sich auch durch subsections mittels sensoric als section realisieren, kommt aber auf die menge des textes an subsections sollten nicht über eine halbe seite lang sein. \newpage \section{Thermosensor} %Nick - + Wie bereits erwähnt benutzen wir einen Dallas DS1820 1-Wire Digital Thermometer, um die Motortemperatur zu messen. Der DS1820 speichert die Temperatur als einen 9bit Wert und kann Temperaturen im Bereich von -55°C bis 125°C messen. Für unsere Bedürfnisse reicht es wenn wir in 1-er Schritten messen. Der Sensor kommt aber auch mit halben Graden zu recht. + + Eine Messung wird durchgeführt indem der Sensor Takte, innerhalb eines Zeitfensters zählt. Der Zähler startet bei einem Wert, der -55°C darstellt. Erreicht der Zähler 0 schneller als das vorgegebene Zeitfenster wird das Temperaturregister inkrementiert. Der Zähler wird auf einen vom Slope Accumulator Circuitry abhängigen wert gestellt und wieder runtergezählt. Dies wiederholt sich solange bis das festgelegte Zeitfenster abgelaufen ist. \newpage \section{Ultraschallsensor} %Nick diff --git a/ideen_mechanik_und_elektronik.odt b/ideen_mechanik_und_elektronik.odt index dd56f82..7690502 100644 Binary files a/ideen_mechanik_und_elektronik.odt and b/ideen_mechanik_und_elektronik.odt differ