Datenlogger

{autotoc}

1. Arbeitsplan

Ich plane im Rahmen meiner Ingeniuerspraxis auf Basis des Datenloggers OpenLog und einem Mikrocontrollerboard vom Typ Arduino Pro Mini eine Messwerteerfassungseinheit für den Zeppelin aufzubauen.
Hierfür will ich zunächst die Sensoren zusammen mit dem Datenlogger auf einem Steckbrett aufbauen und ihn zusammen mit verschiedenen Sensoren testen. Anschließend - wenn Aufbau und Software ausgereift sind - wird die Schaltung auf eine Platine übertragen und sauber aufgebaut.
Dieser Datenlogger wird anschließend in den Zeppelin montiert und auf einigen Probeflügen getestet. Die dabei gesammelten Daten sollen zum Test des im Rahmen einer anderen Ingenieurspraxis entwickelten computergestützten Zeppelin-Simulators dienen.

Der komplette Arbeitsplan kann im PDF anhang nachgelesen werden.

2. Praktikumsbericht

Die Ergebnisse meines Praktikums können im PDF nachgelesen werden.

3. OpenLog

Aufbau mit XBee



gesamter Stromverbrauch(Arduino, OpenLog, Sensoren und XBee ca. 340mA.

 

4. Arduino Pro Mini

Als Mikrocontroller wird ein Arduino Pro Mini verwendet(5V, 16MHz,ATmega328).

5. Sensoren

  • Beschleunigungssensor (ADXL345)
  • Gyroskop (SD740)
  • Kompass (HMC5883L)
  • Lichtsensor (TEMT6000)
  • Luftdrucksensor (BMP085)
  • Luftfeuchtigkeitssensor (DHT11)
  • Real Time Clock (DS1307)
  • TILT Sensor (RPI-1031)
  • Ultraschallsensor (MB1240)


Davon dürfen die folgenden Sensoren ausschließlich mit 3,3V betrieben werden: ADXL345, BMP085, HMC5883L, RPI-1031 und SD740

6. Spannungsversorgung


Für die Spannungsversorgung steht ein 3.7V Akku zur Verfügung. Diese 3.7V werden mit einem Step-Up auf 5V erhöht. Da aber einige Sensoren nur mit 3.3V zu betreiben sind werden die 5V anschließend mit einem Spannungsregler wieder auf 3.3V verringert.

7. Programmcode für alle Sensoren

/* 
 *  Beschleunigungssensor(ADXL345)
 *  Drucksensor (BMP085)
 *  Feuchtigkeits Sensor (DHT11)
 *  Gyroskop (SD740)
 *  Kompass (HMC5883L)
 *  Lichtsensor(TEMT6000)
 *  Real Time Clock (DS1307)
 *  Ultraschallsensor(MB1240)
 *  Tilt-a-Whirl (RPI-1031)
 *
 *  zuletzt geändert am:
 *  21.03.2012
 *
 *  Autoren:
 *  http://www.dfrobot.com/index.php?route=product/product&path=36_64&product_id=174                                (DHT11)
 *  http://www.ladyada.net/learn/breakoutplus/ds1307rtc.html                                                        (DS1307)
 *  http://www.ladyada.net/learn/sensors/bmp085.html                                                                (BMP085)
 *  http://www.dfrobot.com/wiki/index.php?title=Triple_Axis_Accelerometer_Breakout_-_ADXL345_%28SKU:SEN0032%29      (ADXL345)
 *  http://www.dfrobot.com/wiki/index.php?title=Tri-Axis_Gyro_Breakout-SD740_%28SKU:_SEN0095%29                     (SD740)
 *  Klaus Wackerbarth                                                                                               (MB1240)
 *  Stefan Hinterleuthner
 *
 *  Code für DHT11, DS1307, BMP085, ADXL345, SD740 und MB1240 wurde verändert
 *    
 *
 *  Pinbelegung:
 *  - A0(Arduino Pro Mini)  und S(DHT11)
 *  - A1(Arduino Pro Mini)  und 2(MB1240)
 *  - SDA(Arduino Pro Mini) und SDA(RTC)
 *  - SCL(Arduino Pro Mini) und SCL(RTC)
 *  - SDA(Arduino Pro Mini) und SDA(BMP08)
 *  - SCL(Arduino Pro Mini) und SCL(BMP08)
 *  - 2(Arduino Pro Mini)   und Taster
 *  - 10(Arduino Pro Mini)  und CSN(SD740)
 *  - 11(Arduino Pro Mini)  und MOSI/SDA(SD740)
 *  - 12(Arduino Pro Mini)  und MISO/ADDR(SD740)
 *  - 13(Arduino Pro Mini)  und SCL(SD740)
 *  - SDA(Arduino Pro Mini) und SDA(ADXL345)
 *  - SCL(Arduino Pro Mini) und SCL(ADXL345)
 *  - GND(Arduino Pro Mini) und SDO(ADXL345)
 *  - 3.3V                  und CS(ADXL345)
 *  - A3(Arduino Pro Mini)  und SIG(TEMT6000)
 *  - SCL(Arduino Pro Mini) und SCL(HMC5883L)
 *  - SDA(Arduino Pro Mini) und SDA(HMC5883L)
 *  - 3(Arduino Pro Mini)   und S2(RPI-1031)
 *  - 4(Arduino Pro Mini)   und S1(RPI-1031)
 *
 *  ACHTUNG:
 *  ADXL345 NUR MIT 3,3V BETREIBEN!!!
 *  BMP085 NUR MIT 3,3V BETREIBEN!!!
 *  HMC5883L NUR MIT 3,3V BETREIBEN!!!
 *  RPI-1031 NUR MIT 3,3V BETREIBEN!!!
 *  SD740 NUR MIT 3,3V BETREIBEN!!!
 *  NICHT MIT 5,0!!!
 *
 *
 */

/********************************************************************************************************/
/*                                       Einstellungen                                                  */
/********************************************************************************************************/

int del = 1000;                                                    //  Zeit zwischen zwei Messungen in ms, >200 wählen

int ADXL345=1;                                                               // Beschleunigungssensor(ADXL345)
int BMP085=1;                                                                // Drucksensor (BMP085)
                                                               // Feuchtigkeits Sensor (DHT11)
                                                               // Gyroskop (SD740)
                                                               // Kompass (HMC5883L)
                                                               // Lichtsensor(TEMT6000)
                                                               // Real Time Clock (DS1307)
                                                               // Ultraschallsensor(MB1240)
                                                               // Tilt-a-Whirl (RPI-1031)


/********************************************************************************************************/
/*                                  DHT11 Luftfeuchtigkeit                                              */
/********************************************************************************************************/

#define DHT11_PIN 0      // ADC0

byte read_dht11_dat()
{
  byte i = 0;                                                                      
  byte result=0;
  for(i=0; i< 8; i++)
  {
    while(!(PINC & _BV(DHT11_PIN)));  // wait for 50us
    delayMicroseconds(30);
    if(PINC & _BV(DHT11_PIN)) 
      result |=(1<<(7-i));
    while((PINC & _BV(DHT11_PIN)));  // wait '1' finish
   }
    return result;
}

/********************************************************************************************************/
/*                                Bibliotheken und defines                                              */
/********************************************************************************************************/
#include <SPI.h>                                                               // für ADXL345
#include <Wire.h>                                                              // für RTC und BMP085
#include "RTClib.h"                                                            // für RTC
#include <Adafruit_BMP085.h>                                                   // für BMP085
#include <math.h>;                                                             // für BMP085

#define DEVICE (0x53)                                                          // für ADXL345     //ADXL345 device address
#define TO_READ (6)                                                            // für ADXL345     //num of bytes we are going to read each time (two bytes for each axis)
#define DataRegister 0x00                                                      // für SD740
#define CS_Pin 10                                                              // für SD740       //chip selection pin


/********************************************************************************************************/

RTC_DS1307 RTC;                                                                // für RTC
Adafruit_BMP085 bmp;                                                           // für BMP085

long value = 0;                                                                // Variable für die Zeit vom US-Sensor zum objeckt
long high = 0;                                                                 // Variable für die Entfernung vom US-Sensor zum objekt
const int us    = A1;                                                          // US  is on Pin A1
const int pwm_a = 10;                                                          // PWM control for motor outputs 1 and 2 is on digital pin 10
const int pwm_b = 11;                                                          // PWM control for motor outputs 3 and 4 is on digital pin 11

int licht = 0;                                                                 // TEMT6000
int Entfernung = 0;
int button = 2;                                                                // switch is connected to pin 2
int val;                                                                       // variable for reading the pin status
int buttonState;                                                               // variable to hold the last button state
double altitude = 518.0;
double pressureAtSealevel = 0;
double relativ = 0;


byte buff[TO_READ] ;                                                           // ADXL345         //6 bytes buffer for saving data read from the device
char str[512];                                                                 // ADXL345         //string buffer to transform data before sending it to the serial port
char receiveData[128];                                                         // SD740           //data array
int x,y,z;                                                                     // SD740
float xg,yg,zg;                                                                // SD740
float absHeading = 0;                                                          // SD740           // calculate the absolute heading
unsigned long iTime = 0;                                                       // SD740

int8_t data[6];                                                                // HMC5883L
int j=0;                                                                       // HMC5883L
int16_t X;                                                                     // HMC5883L
int16_t Z;                                                                     // HMC5883L
int16_t Y;                                                                     // HMC5883L
uint16_t phi;                                                                  // HMC5883L

int tilt_s1 = 3;                                                               // RPI-1031
int tilt_s2 = 4;                                                               // RPI-1031


/********************************************************************************************************/
/*                                        void setup()                                                  */
/********************************************************************************************************/

void setup()
{
  DDRC |= _BV(DHT11_PIN);
  PORTC |= _BV(DHT11_PIN);
  Serial.begin(9600);                                                                     // BAUD RATE!!!!
  buttonState = digitalRead(button);
  Serial.println("Ready;");
  bmp.begin(BMP085_HIGHRES);
  Wire.begin();
  RTC.begin();
  SPI.begin();                                                                            // SD740
  SPI.setDataMode(SPI_MODE0);                                                             // SD740
  
  pinMode(tilt_s1, INPUT);                                                                // RPI-1031
  pinMode(tilt_s2, INPUT);                                                                // RPI-1031
  pinMode(us, INPUT);                                                                     // MB1240       // Set US pin to be input
  pinMode(button, INPUT);
  pinMode(CS_Pin, OUTPUT);                                                                // SD740        // init the chip selection pin
  digitalWrite(CS_Pin, HIGH);                                                             // SD740
    
  checkGyroStatus();                                                                      // SD740
                                                                                          // Turning on the ADXL345
  writeTo(DEVICE, 0x2D, 0);                                                               // ADXL345
  writeTo(DEVICE, 0x2D, 16);                                                              // ADXL345
  writeTo(DEVICE, 0x2D, 8);                                                               // ADXL345
  
  startKompass();                                                                         // HMC5883L
    
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!;");
    RTC.adjust(DateTime(__DATE__, __TIME__));                                             // line sets the RTC to the date & time this sketch was compiled
  }
  
  pressureAtSealevel = setPressureAtSealevel(altitude, (double)bmp.readPressure() );
  Serial.print("pressureAtSealevel: ");
  Serial.print(pressureAtSealevel);
  Serial.println(";");
  Serial.println();
  
  
  
  Serial.println("TIMESTAMP,DATE,,,TIME,,,HUMIDITY,TEMPERATURE,PRESSURE,REAL ALTITUDE,RELATIVE ALTITUDE,DISTANCE,GYROSKOP,,,HEADING,ACCELEROMETER_X,ACCELEROMETER_Y,ACCELEROMETER_Z,LIGHT,COMPASS,TILT");
  Serial.println("seconds (not counting leapseconds) since midnight 1.1.1970,dd,mm,yyyy,hh,mm,ss,%,°C,Pa,m,m,cm,°/s,°/s,°/s,,mg,mg,mg,lx,°,");
  
//  delay(50);
  
}



/********************************************************************************************************/
/*                                        void loop()                                                   */
/********************************************************************************************************/
	
void loop()
{
  byte dht11_dat[5];                                                                      // DHT11
  byte dht11_in;                                                                          // DHT11
  byte i;                                                                                 // DHT11                 // start condition
	                                                                                  // DHT11                 // 1. pull-down i/o pin from 18ms
  PORTC &= ~_BV(DHT11_PIN);                                                               // DHT11
  delay(18);                                                                              // DHT11
  PORTC |= _BV(DHT11_PIN);                                                                // DHT11
  delayMicroseconds(40);                                                                  // DHT11
  DDRC &= ~_BV(DHT11_PIN);                                                                // DHT11
  delayMicroseconds(40);                                                                  // DHT11
                                                                                          // DHT11
  dht11_in = PINC & _BV(DHT11_PIN);                                                       // DHT11
  if(dht11_in)                                                                            // DHT11
  {                                                                                       // DHT11
    Serial.println("dht11 start condition 1 not met;");                                   // DHT11
    return;                                                                               // DHT11
  }                                                                                       // DHT11
  delayMicroseconds(80);                                                                  // DHT11
  dht11_in = PINC & _BV(DHT11_PIN);                                                       // DHT11
  if(!dht11_in)                                                                           // DHT11
  {                                                                                       // DHT11
    Serial.println("dht11 start condition 2 not met;");                                   // DHT11
    return;                                                                               // DHT11
  }                                                                                       // DHT11
                                                                                          // DHT11
  delayMicroseconds(80);                                                                  // DHT11                 // now ready for data reception
  for (i=0; i<5; i++)                                                                     // DHT11
    dht11_dat[i] = read_dht11_dat();                                                      // DHT11
  DDRC |= _BV(DHT11_PIN);                                                                 // DHT11
  PORTC |= _BV(DHT11_PIN);                                                                // DHT11
  byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];             // DHT11                 // check check_sum
                                                                                          // DHT11
  if(dht11_dat[4]!= dht11_check_sum)                                                      // DHT11
  {                                                                                       // DHT11
    Serial.println("DHT11 checksum error;");                                              // DHT11
  }                                                                                       // DHT11
  
  val = digitalRead(button);                                                              // button & sealevel
  if (val != buttonState) {                                                               // button & sealevel
     Serial.println("****************************************;");                         // button & sealevel
     Serial.println("Button just pressed;");                                              // button & sealevel
     pressureAtSealevel = setPressureAtSealevel(altitude, (double)bmp.readPressure() );   // button & sealevel
     Serial.print("pressureAtSealevel changed to: ");                                     // button & sealevel
     Serial.println(pressureAtSealevel);                                                  // button & sealevel
     Serial.println("****************************************;");                         // button & sealevel
    }                                                                                     // button & sealevel
       
  readRegister(DataRegister, 6, receiveData);                                             // SD740
                                                                                          // SD740
  x = ((int)receiveData[0]<<8)|(int)receiveData[1];                                       // SD740
  y = ((int)receiveData[2]<<8)|(int)receiveData[3];                                       // SD740
  z = ((int)receiveData[4]<<8)|(int)receiveData[5];                                       // SD740
                                                                                          // SD740
  float scale = 0.03125;                                                                  // SD740                 // scale: 1024 / 2^15
                                                                                          // SD740
  xg = x * scale;                                                                         // SD740
  yg = y * scale;                                                                         // SD740
  zg = z * scale;                                                                         // SD740
  float pastTime = float(micros() - iTime) / float(1000000);                              // SD740
  absHeading += zg * pastTime;                                                            // SD740
  iTime = micros();                                                                       // SD740    
  
  int regAddress = 0x32;                                                                  // ADXL345               //first axis-acceleration-data register on the ADXL345
  int x, y, z;                                                                            // ADXL345
                                                                                          // ADXL345
  readFrom(DEVICE, regAddress, TO_READ, buff);                                            // ADXL345               //read the acceleration data from the ADXL345
                                                                                          // ADXL345
                                                                                          // ADXL345               //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
                                                                                          // ADXL345               //thus we are converting both bytes in to one int
  x = (((int)buff[1]) << 8) | buff[0];                                                    // ADXL345  
  y = (((int)buff[3])<< 8) | buff[2];                                                     // ADXL345
  z = (((int)buff[5]) << 8) | buff[4];                                                    // ADXL345
  
  licht = analogRead(3);                                                                  // TEMT6000
  
  int position = getTiltPosition();                                                       // RPI-1031
  
/********************************************************************************************************/
// Berechnungen 

  value = pulseIn(us, HIGH);                                                              // MB1240 
  high = value*(1000/58);                                                                 // MB1240 
  Entfernung = high/1000;                                                                 // MB1240 
  relativ = bmp.readAltitude(pressureAtSealevel) - altitude;                              // BMP085
  
/********************************************************************************************************/
/*                                      Ausgaben                                                        */
/********************************************************************************************************/
  DateTime now = RTC.now();

    Serial.print(now.unixtime());                                                         // Ausgabe TIMESTAMP DATUM und UHRZEIT (RTC)
    Serial.print(",");        
    Serial.print(now.day(), DEC);
    Serial.print(',');
    Serial.print(now.month(), DEC);
    Serial.print(',');
    Serial.print(now.year(), DEC);
    Serial.print(",");
   
    if(now.hour()<10){ 
      Serial.print("0");
      Serial.print(now.hour(), DEC);
      }
    else
      Serial.print(now.hour(), DEC);
      
    Serial.print(',');
    
    if(now.minute()<10){
      Serial.print("0");
      Serial.print(now.minute(), DEC);
    }
    else
      Serial.print(now.minute(), DEC);
    
    Serial.print(',');
    
    if(now.second()<10){
      Serial.print("0");
      Serial.print(now.second(), DEC);
    }
    else
      Serial.print(now.second(), DEC);
    Serial.print(",");
    
          
/********************************************************************************************************/

  Serial.print(dht11_dat[0], DEC);                                                        // Ausgabe HUMIDITY(DHT11) und TEMPERATURE(BMP085)
  Serial.print(".");
  Serial.print(dht11_dat[1], DEC);
  Serial.print(",");
  Serial.print(bmp.readTemperature());
  Serial.print(",");
  
/********************************************************************************************************/

    Serial.print(bmp.readPressure());                                                     // Ausgabe PRESSURE, REAL ALTITUDE und RELATIVE ALTITUDE(BMP08)
    Serial.print(",");
    Serial.print(bmp.readAltitude(pressureAtSealevel));
    Serial.print(",");
    Serial.print(relativ);
    Serial.print(",");
    
/********************************************************************************************************/

  if(Entfernung<100){                                                                     // Ausgabe Ultraschallsensor
    Serial.print(Entfernung);
  }
  else{
    Serial.print(Entfernung);
  }
  Serial.print(",");
  
/********************************************************************************************************/  

  /*Serial.print(x, DEC);                                                                 // Ausgabe GYRO
  Serial.print(',');
  Serial.print(y, DEC);
  Serial.print(',');
  Serial.print(z, DEC); 
  Serial.print(",");*/
  Serial.print((float)xg,2);
  Serial.print(",");
  Serial.print((float)yg,2);
  Serial.print(",");
  Serial.print((float)zg,2);
  
  Serial.print(",");
  Serial.print(absHeading);                                                               //Axis Z absolute heading 
  Serial.print(",");
  
/********************************************************************************************************/  

  sprintf(str, "%d,%d,%d", x, y, z);                                                      // Ausgabe ADXL345
  Serial.print(str);
  Serial.print(",");
  
/********************************************************************************************************/ 

  Serial.print(licht, DEC);                                                               // Ausgabe TEMT6000

/********************************************************************************************************/ 

  Serial.print(",");
  printKompass();                                                                         // Ausgabe Kompass       
  Serial.print(",");

/********************************************************************************************************/

 Serial.print(position);                                                                  // Ausgabe TILT RPI-1031
 Serial.println();

/********************************************************************************************************/

  delay(del);                                                                             // Zeit bis zur nächsten Messung in ms
  
}



/********************************************************************************************************/
/********************************************************************************************************/
/********************************************************************************************************/

/********************************************************************************************************/
/*         void readRegister(char registerAddress, int numBytes, char * values) GYROSKOP                */
/********************************************************************************************************/

  void readRegister(char registerAddress, int numBytes, char * values){

    char address = 0x80 | registerAddress;
    digitalWrite(CS_Pin, LOW);
    SPI.transfer(address);
    for(int i=0; i<numBytes; i++){
      values[i] = SPI.transfer(0x00);
    }
    digitalWrite(CS_Pin, HIGH);

  }

/********************************************************************************************************/
/*                  void writeTo(int device, byte address, byte val) Beschleunigungssensor              */
/********************************************************************************************************/

                                                                          //Writes val to address register on device
  void writeTo(int device, byte address, byte val) {
    Wire.beginTransmission(device);                                       // start transmission to device 
    Wire.write(address);                                                  // send register address
    Wire.write(val);                                                      // send value to write
    Wire.endTransmission();                                               // end transmission
  }

/********************************************************************************************************/
/*        void readFrom(int device, byte address, int num, byte buff[]) Beschleunigungssensor           */
/********************************************************************************************************/


                                                                        //reads num bytes starting from address register on device in to buff array
  void readFrom(int device, byte address, int num, byte buff[]) {
    Wire.beginTransmission(device);                                     // start transmission to device 
    Wire.write(address);                                                // sends address to read from
    Wire.endTransmission();                                             // end transmission

    Wire.beginTransmission(device);                                     // start transmission to device
    Wire.requestFrom(device, num);                                      // request 6 bytes from device

    int i = 0;
    while(Wire.available())                                             // device may send less than requested (abnormal)
    { 
      buff[i] = Wire.read();                                            // receive a byte
      i++;
    }
    Wire.endTransmission();                                             // end transmission
  }


/********************************************************************************************************/
/*                                    void checkGyroStatus()                                            */
/********************************************************************************************************/

  void checkGyroStatus(){

    readRegister(20,1,receiveData);
    Serial.print("check lock state:\t");
    Serial.println(receiveData[0],BIN);                                                  // bin; 110 means works well
  
    if(bitRead(receiveData[0],1) == 0 || bitRead(receiveData[0],2) == 0){
      Serial.println("Chip start error! You could reset the arduino board");
      while(1){
      }
    }

    readRegister(70,1,receiveData);
    Serial.print("check standby bit:\t");
    Serial.println(receiveData[0],BIN);                                                  // check bit0 0->normal 1->standby
  
  }


/********************************************************************************************************/
/*                                   Funktion für pressureAtSealevel                                    */
/********************************************************************************************************/

  double setPressureAtSealevel(double high, double pressure) {
    return (double)(pressure/pow(((double)1.0-((double)high/(double)44330.0)), (double)5.255));
  }


/*****************************************************************************************************************/
/*                                         Funktion zum Starten des Kompass                                      */
/*****************************************************************************************************************/

  uint8_t startKompass(){
    uint8_t rueckgabe;
    
    delay(70);
    
    Wire.begin();
    Wire.beginTransmission(30);
    Wire.write((uint8_t)0);
    Wire.write(112);
    
    Wire.beginTransmission((uint8_t)30);
    Wire.write((uint8_t)1);
    Wire.write((uint8_t)160);
    Wire.endTransmission();
    
    return rueckgabe;
  }

/*****************************************************************************************************************/
/*                               Funktion zum Ausgeben und Berechnen des Kompasswertes                           */
/*****************************************************************************************************************/

  int8_t printKompass(){
    int8_t rueckgabe;
 
    Wire.beginTransmission(30);
    Wire.write(2);
    Wire.write(1);
    Wire.endTransmission();
  
    Wire.requestFrom(30,6);
  
    int j=0;
    while(Wire.available()){
     data[j] = Wire.read();
     j++;
    }
 
    X=((((int16_t)data[0])<<8)|(int16_t)data[1]);
    Z=((((int16_t)data[2])<<8)|(int16_t)data[3]);
    Y=((((int16_t)data[4])<<8)|(int16_t)data[5]);
  
    phi=((atan2(X,Y)+3.1416)/(2.0*3.1416))*360.0;
    Serial.print(phi);
  
    Wire.beginTransmission(30);
    Wire.write(3);
    Wire.endTransmission();
  
  
    return rueckgabe; 
  }

/*****************************************************************************************************************/
/*                                            Funktion getTiltPosition                                           */
/*****************************************************************************************************************/

  int getTiltPosition(){
     int s1 = digitalRead(tilt_s1);
     int s2 = digitalRead(tilt_s2);
     return (s1 << 1) | s2;                                                       
  }

8.Matlab

Um die gemessenen Werte auswerten zu können, muss die vom OpenLog gespeicherte txt-Datei als csv-Datei gespeichert werden. Anschließend kann die Datei über "Select" ausgewählt werden und mit "Plot" können die verschiedenen Sensordaten graphisch dargestellt werden.

function varargout = Logger2(varargin)
% LOGGER2 MATLAB code for Logger2.fig
%      LOGGER2, by itself, creates a new LOGGER2 or raises the existing
%      singleton*.
%
%      H = LOGGER2 returns the handle to a new LOGGER2 or the handle to
%      the existing singleton*.
%
%      LOGGER2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LOGGER2.M with the given input arguments.
%
%      LOGGER2('Property','Value',...) creates a new LOGGER2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Logger2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Logger2_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Logger2

% Last Modified by GUIDE v2.5 23-Mar-2012 13:44:52

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Logger2_OpeningFcn, ...
                   'gui_OutputFcn',  @Logger2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Logger2 is made visible.
function Logger2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Logger2 (see VARARGIN)

% Choose default command line output for Logger2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Logger2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Logger2_OutputFcn(hObject, eventdata, handles) 

varargout{1} = handles.output;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


axes(handles.grafik1);
 G1=imread('logo.png','png');
 image (G1);
 axis image;
axis off;

axes(handles.grafik2);
 G2=imread('TUM-Logo-102.png','png');
 image (G2);
 axis image;
axis off;

axes(handles.grafik3);
 G3=imread('LDVLogo.png','png');
 image (G3);
 axis image;
axis off;

% sensor1.
function sensor1_Callback(hObject, eventdata, handles)
    global sensor1Value;
    sensor1Value = get(hObject,'Value');

function sensor1_CreateFcn(hObject, eventdata, handles)

    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
       set(hObject,'BackgroundColor','white');
    end
    global sensor1Value;
    sensor1Value = get(hObject,'Value');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in color1.
function color1_Callback(hObject, eventdata, handles)
    global color1;
    color1 = get(hObject,'Value');

function color1_CreateFcn(hObject, eventdata, handles)

    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end
    global color1;
    color1 = get(hObject,'Value');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in line1.
function line1_Callback(hObject, eventdata, handles)
    global line1;
    line1 = get(hObject,'Value');
    
function line1_CreateFcn(hObject, eventdata, handles)

    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end
    global line1;
    line1 = get(hObject,'Value');
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% plot1.
function plot1_Callback(hObject, eventdata, handles)

global sensor1Value;
global color1;
global color1color;
global line1;
global line1line
global rawdata1;

if isempty(rawdata1)
    warndlg({'Select a file first!','For more info => Help'},'Warning');
end

switch line1
    case 1
        line1line='.';
    case 2
        line1line='o';
    case 3
        line1line='x';
    case 4
        line1line='+';
    case 5
        line1line='*';
    case 6
        line1line='s';
    case 7
        line1line='d';
    case 8
        line1line='v';
    case 9
        line1line='^';
    case 10
        line1line='<';
    case 11
        line1line='>';
    case 12
        line1line='p';
    case 13
        line1line='h';
    case 14
        line1line='-';
    case 15
        line1line=':';
    case 16
        line1line='--';
    case 17
        line1line='-.';
end

switch color1
    case 1
        color1color = 'black';
    case 2
        color1color = 'blue';
    case 3
        color1color = 'cyan';
    case 4
        color1color = 'green';
    case 5
        color1color = 'magenta';
    case 6
        color1color = 'red';
    case 7
        color1color = 'yellow';
end



switch sensor1Value
    case 1      % Accel
        Y=[rawdata1(:,19),rawdata1(:,20),rawdata1(:,21)];
        plot(handles.Diagramm1, Y,line1line);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,{'Acceleration in mg';'X=red';'Y=blue';'Z=green'},'fontsize',15);
    case 2      % Compass
        plot(handles.Diagramm1, rawdata1(:,22),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Direction in °','fontsize',15);
    case 3      % Distance
        plot(handles.Diagramm1, rawdata1(:,13),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Distance in cm','fontsize',15);
    case 4      % Gyro
        Y=[rawdata1(:,14),rawdata1(:,15),rawdata1(:,16)];
        plot(handles.Diagramm1, Y,line1line);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,{'Gyro in °/s';'X=red';'Y=blue';'Z=green'},'fontsize',15);
    case 5      % Humidity
        plot(handles.Diagramm1, rawdata1(:,8),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Humidity in %','fontsize',15);
    case 6      % Light
        plot(handles.Diagramm1, rawdata1(:,21),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Illuminance in lx','fontsize',15);
    case 7      % Pressure
        plot(handles.Diagramm1, rawdata1(:,10),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
       ylabel(handles.Diagramm1,'Pressure in hPa','fontsize',15);
    case 8      % Real Altitdue
        plot(handles.Diagramm1, rawdata1(:,11),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Real Altitude in m','fontsize',15);

    case 9      % Relative Altitudde
        plot(handles.Diagramm1, rawdata1(:,12),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Relative Altitude in m','fontsize',15);

    case 10     % Temperatur
        plot(handles.Diagramm1, rawdata1(:,9),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Temperatur in °C','fontsize',15);
    case 11     % Tilt
        plot(handles.Diagramm1, rawdata1(:,23),line1line,'color', color1color);
        xlabel(handles.Diagramm1,'samples','fontsize',15);
        ylabel(handles.Diagramm1,'Tilt Direction','fontsize',15);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% holdon1.
function holdon1_Callback(hObject, eventdata, handles)
    hold(handles.Diagramm1, 'on');
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% holdoff1.
function holdoff1_Callback(hObject, eventdata, handles)
    hold(handles.Diagramm1, 'off');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% clear1.
function clear1_Callback(hObject, eventdata, handles)
    cla(handles.Diagramm1);
    xlabel(handles.Diagramm1,'','fontsize',15);
    ylabel(handles.Diagramm1,'','fontsize',15);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% select1.
function select1_Callback(hObject, eventdata, handles)
    
    global rawdata1;
    
    [file,path] = uigetfile('*.csv','OpenLog file');
    rawdata1 = csvread([path file]);
    
%     if  isnan(rawdata1)==1
%         errordlg('File not found','File Error');
%     end
    
    % Start1
    set(handles.tag1,'String',rawdata1(1,2));
    set(handles.monat1,'String',rawdata1(1,3));
    set(handles.jahr1,'String',rawdata1(1,4));
    set(handles.stunden1,'String',rawdata1(1,5));
    set(handles.minuten1,'String',rawdata1(1,6));
    set(handles.sekunden1,'String',rawdata1(1,7));
    
    % Ende1
    set(handles.tag2,'String',rawdata1(end-1,2));
    set(handles.monat2,'String',rawdata1(end-1,3));
    set(handles.jahr2,'String',rawdata1(end-1,4));
    set(handles.stunden2,'String',rawdata1(end-1,5));
    set(handles.minuten2,'String',rawdata1(end-1,6));
    set(handles.sekunden2,'String',rawdata1(end-1,7));
    


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in sensor2.
function sensor2_Callback(hObject, eventdata, handles)
    global sensor2Value;
    sensor2Value = get(hObject,'Value');
function sensor2_CreateFcn(hObject, eventdata, handles)

    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
      set(hObject,'BackgroundColor','white');
    end
    global sensor2Value;
    sensor2Value = get(hObject,'Value');
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in color2.
function color2_Callback(hObject, eventdata, handles)
    global color2;
    color2 = get(hObject,'Value');
    
function color2_CreateFcn(hObject, eventdata, handles)

    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
       set(hObject,'BackgroundColor','white');
    end
    global color2;
    color2 = get(hObject,'Value');
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in line2.
function line2_Callback(hObject, eventdata, handles)
    global line2;
    line2 = get(hObject,'Value');
    
function line2_CreateFcn(hObject, eventdata, handles)

    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
     set(hObject,'BackgroundColor','white');
    end
    global line2;
    line2 = get(hObject,'Value');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% plot2.
function plot2_Callback(hObject, eventdata, handles)

global sensor2Value;
global color2;
global color2color;
global line2;
global line2line
global rawdata2;


if isempty(rawdata2)
    warndlg({'Select a file first!','For more info => Help'},'Warning');
end

switch line2
    case 1
        line2line='.';
    case 2
        line2line='o';
    case 3
        line2line='x';
    case 4
        line2line='+';
    case 5
        line2line='*';
    case 6
        line2line='s';
    case 7
        line2line='d';
    case 8
        line2line='v';
    case 9
        line2line='^';
    case 10
        line2line='<';
    case 11
        line2line='>';
    case 12
        line2line='p';
    case 13
        line2line='h';
    case 14
        line2line='-';
    case 15
        line2line=':';
    case 16
        line2line='--';
    case 17
        line2line='-.';
end

switch color2
    case 1
        color2color = 'black';
    case 2
        color2color = 'blue';
    case 3
        color2color = 'cyan';
    case 4
        color2color = 'green';
    case 5
        color2color = 'magenta';
    case 6
        color2color = 'red';
    case 7
        color2color = 'yellow';
end



switch sensor2Value
    case 1      % Accel
        Y=[rawdata2(:,19),rawdata2(:,20),rawdata2(:,21)];
        plot(handles.Diagramm2, Y,line2line);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,{'Acceleration in mg';'X=red';'Y=blue';'Z=green'},'fontsize',15);
    case 2      % Compass
        plot(handles.Diagramm2, rawdata2(:,22),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Direction in °','fontsize',15);
        legend('Compass');
    case 3      % Distance
        plot(handles.Diagramm2, rawdata2(:,13),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Distance in cm','fontsize',15);
    case 4      % Gyro
        Y=[rawdata2(:,14),rawdata2(:,15),rawdata2(:,16)];
        plot(handles.Diagramm2, Y,line2line);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,{'Gyro in °/s';'X=red';'Y=blue';'Z=green'},'fontsize',15);
    case 5      % Humidity
        plot(handles.Diagramm2, rawdata2(:,8),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Humidity in %','fontsize',15);
    case 6      % Light
        plot(handles.Diagramm2, rawdata2(:,21),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Illuminance in lx','fontsize',15);
    case 7      % Pressure
        plot(handles.Diagramm2, rawdata2(:,10),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Pressure in hPa','fontsize',15);
    case 8      % Real Altitdue
        plot(handles.Diagramm2, rawdata2(:,11),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Real Altitude in m','fontsize',15);
    case 9      % Relative Altitudde
        plot(handles.Diagramm2, rawdata2(:,12),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Relative Altitude in m','fontsize',15);
    case 10     % Temperatur
        plot(handles.Diagramm2, rawdata2(:,9),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Temperatur in °C','fontsize',15);
    case 11     % Tilt
        plot(handles.Diagramm2, rawdata2(:,23),line2line,'color', color2color);
        xlabel(handles.Diagramm2,'samples','fontsize',15);
        ylabel(handles.Diagramm2,'Tilt Direction','fontsize',15);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% holdon2.
function holdon2_Callback(hObject, eventdata, handles)
    hold(handles.Diagramm2, 'on');
    
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% holdoff2.
function holdoff2_Callback(hObject, eventdata, handles)
    hold(handles.Diagramm2, 'off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% clear2.
function clear2_Callback(hObject, eventdata, handles)
    cla(handles.Diagramm2);
    xlabel(handles.Diagramm1,'','fontsize',15);
    ylabel(handles.Diagramm1,'','fontsize',15);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% select2.
function select2_Callback(hObject, eventdata, handles)
    global rawdata2;
    
    [file,path] = uigetfile('*.csv','OpenLog file');
    rawdata2 = csvread([path file]);
    
    % Start1
    set(handles.tag3,'String',rawdata2(1,2));
    set(handles.monat3,'String',rawdata2(1,3));
    set(handles.jahr3,'String',rawdata2(1,4));
    set(handles.stunden3,'String',rawdata2(1,5));
    set(handles.minuten3,'String',rawdata2(1,6));
    set(handles.sekunden3,'String',rawdata2(1,7));
    
    % Ende1
    set(handles.tag4,'String',rawdata2(end-1,2));
    set(handles.monat4,'String',rawdata2(end-1,3));
    set(handles.jahr4,'String',rawdata2(end-1,4));
    set(handles.stunden4,'String',rawdata2(end-1,5));
    set(handles.minuten4,'String',rawdata2(end-1,6));
    set(handles.sekunden4,'String',rawdata2(end-1,7));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% help.
function help_Callback(hObject, eventdata, handles)
    
    msgbox({'Select: Here you can choose a csv-file to work with. You have to select a file to be able to plot. You are able to plot a second csv-file in the lower coordinate system','Popupmenu 1: Choose a sensor','Popupmenu 2: Choose a color','Popupmenue 3: Choose a line-style','Plot: Pushing the "Plot"-Button will plot the data you had choosen','Hold On/Hold Off: The "Hold On"-button will hold all the graphs you plot until the "Hold Off"-button is clicked','Clear: Will delete all the plotted graphs','Start/End: Shows date and time the measurement started/ended (dd.mm.yyyy hh:mm:ss)'},'Help');

9. Links

 

Anhänge:
Diese Datei herunterladen (Arbeitsplan_Hinterleuthner2.pdf)Arbeitsplan_Hinterleuthner2.pdf[ ]%2012-%10-%08 %1:%Okt%+02:00
Diese Datei herunterladen (Praktikumsbericht_Datenlogger.pdf)Praktikumsbericht_Datenlogger.pdf[ ]%2012-%10-%08 %1:%Okt%+02:00