Dependencies:   mbed

main.cpp

Committer:
JST2011
Date:
2012-02-16
Revision:
0:4c4bcf3cc019

File content as of revision 0:4c4bcf3cc019:

/*cutting system by timer*/
/*
#include "mbed.h"

Ticker timer;                                

unsigned int globaltime; // msec               

void timer_func()  
{                    
    globaltime +=1;                        
}                                            

DigitalOut nicrom(p21);

     
int main()
{
    timer.attach(&timer_func,0.001);                   
      
    while(1)
    {  
        if(globaltime < 20000)
        {
            nicrom = 0;
            wait(0.025);
        }
    
        else if(globaltime > 20000)
        {
            nicrom = 1;
            wait(0.025);
        }
    
     }
}
*/


/*cutting system by accel  part1*/
/*#include "mbed.h"

#define delta 0.2

AnalogIn xin(p20);
AnalogIn yin(p19);
AnalogIn zin(p18);

DigitalOut nicrom(p21);

Serial pc(USBTX, USBRX);

int d;

float xx ;
float yy ;    
float zz ;

float xg[2];
float zg[2];
float yg[2];

int accelerometer();

int main()
{
     

      while(1)
      {
         d = accelerometer();  
            if(d == 0)
            {
                 nicrom = 0;
                 wait(0.025);
            }
    
            else if(d == 1)
            {
                  nicrom = 1;
                 wait(0.025);
            }
       pc.printf("%d\n",d);
                 wait(1);
     }
}

int accelerometer()
{
    xg[0] = xg[1];
    yg[0] = yg[1];
    zg[0] = zg[1];
   
    xg[1] = (xin.read() - 0.5 ) * 1.5/0.5 ;
    yg[1] = (yin.read() - 0.5 ) * 1.5/0.5 ;
    zg[1] = (zin.read() - 0.5 ) * 1.0/0.18 ;
    
    xx = fabs(xg[1] - xg[0]);
    yy = fabs(yg[1] - yg[0]);
    zz = fabs(zg[1] - zg[0]);
    
    if(xx >= delta  || yy >= delta  || zz >= delta)
    {
        d = 0;
    }
    else
    {
        d = 1;
    }
    return d;
}
*/

/*cutting system by accel  part2*/
/*#include "mbed.h"

#define delta 0.2

AnalogIn xin(p20);
AnalogIn yin(p19);
AnalogIn zin(p18);

DigitalOut nicrom(p21);

Serial pc(USBTX, USBRX);

int d;
int t, s;

float xx ;
float yy ;    
float zz ;

float xg[2];
float zg[2];
float yg[2];

int accelerometer();

int main()
{
     

      while(1)
      {
         d = accelerometer();  
            if(d == 0)
            {
                t = 0;
            }
    
            else if(d == 1)
            {
                t = t + 1;
            }
        pc.printf("%d\n",d);
                 wait(1);
       
        if( t > 10)break; 
     }
//heat the nicrom for 10sec     
     while(1)
     {
        nicrom = 1;
        s = s + 1;
        if( s > 10)break; 
     }
        
        wait(0.25);
}

int accelerometer()
{
    xg[0] = xg[1];
    yg[0] = yg[1];
    zg[0] = zg[1];
   
    xg[1] = (xin.read() - 0.5 ) * 1.5/0.5 ;
    yg[1] = (yin.read() - 0.5 ) * 1.5/0.5 ;
    zg[1] = (zin.read() - 0.5 ) * 1.0/0.18 ;
    
    xx = fabs(xg[1] - xg[0]);
    yy = fabs(yg[1] - yg[0]);
    zz = fabs(zg[1] - zg[0]);
    
    if(xx >= delta  || yy >= delta  || zz >= delta)
    {
        d = 0;
    }
    else
    {
        d = 1;
    }
    return d;
}
*/


/*cutting system by gps and accel*/
#include "mbed.h"
#include "GPS.h"

Serial pc(USBTX, USBRX);
GPS gps(p9, p10);


#define delta 0.2

AnalogIn xin(p20);
AnalogIn yin(p19);
AnalogIn zin(p18);

DigitalOut nicrom(p21);

int d, e;
int t, s;

float xx ;
float yy ;    
float zz ;

float xg[2];
float zg[2];
float yg[2];

float gpxx ;
float gpyy ;    
float gpzz ;

float gpxg[2];
float gpzg[2];
float gpyg[2];


int accelerometer();
int latandlon();

int main()
{
      while(1)
      {
         d = accelerometer(); 
         e = latandlon();  
         
            if(d == 0 || e == 0)
            {
                t = 0;
            }
    
            else if(d == 1 && e ==1 )
            {
                t = t + 1;
            }
        pc.printf("%d,%d\n",d,e);
                 wait(1);
       
        if( t > 10)break;  
     }
//heat the nicrom for 10sec     
     while(1)
     {
        nicrom = 1;
        s = s + 1;
        if( s > 10)break; 
     }   
        wait(0.25);
}


int latandlon()
{
    while(1)
    {
        if(gps.sample())
        {
            pc.printf("I'm at %f, %f, %f\n", gps.longitude, gps.latitude, gps.altitude);
            
            gpxg[0] = gpxg[1];
            gpyg[0] = gpyg[1];
            gpzg[0] = gpzg[1];
   
            gpxg[1] = gps.longitude;
            gpyg[1] = gps.latitude;
            gpzg[1] = gps.altitude;
    
            xx = fabs(gpxg[1] - gpxg[0]);
            yy = fabs(gpyg[1] - gpyg[0]);
            zz = fabs(gpzg[1] - gpzg[0]);

            if(gpxx >= delta  || gpyy >= delta  || gpzz >= delta)
            {
                e = 0;
            }
            else
            {
                e = 1;
            }
            return e;
        } 
    }
}


int accelerometer()
{
    xg[0] = xg[1];
    yg[0] = yg[1];
    zg[0] = zg[1];
   
    xg[1] = (xin.read() - 0.5 ) * 1.5/0.5 ;
    yg[1] = (yin.read() - 0.5 ) * 1.5/0.5 ;
    zg[1] = (zin.read() - 0.5 ) * 1.0/0.18 ;
    
    xx = fabs(xg[1] - xg[0]);
    yy = fabs(yg[1] - yg[0]);
    zz = fabs(zg[1] - zg[0]);
    
    if(xx >= delta  || yy >= delta  || zz >= delta)
    {
        d = 0;
    }
    else
    {
        d = 1;
    }
    return d;
}









/*
#include "mbed.h"

DigitalOut nicrom(p21);

int main() {
      while(1)
      {
        nicrom = 1;   
        wait(1);
        nicrom = 0;    
        wait(1);
     }
}

*/



/*

#include "mbed.h"

Ticker timer;                                //please copy me

unsigned int globaltime; // msec                //please copy me

void timer_func()                        //please copy me
{                                         //please copy me
    globaltime +=1;                         //please copy me
}                                             //please copy me 

Serial pc(USBTX,USBRX);

int main() {
    timer.attach(&timer_func,0.001);                //please copy me
        pc.printf("hello");
    while(1) {
        wait(0.100);
        pc.printf("%d\r\n",globaltime);
    }
}

*/


/*
#include "mbed.h"
//#include "GPS.h"

//Serial pc(USBTX, USBRX);

//GPS gps(p9, p10);

DigitalOut nicrom(p21);


//float lon = 1.2 ;   //keido
//float lat = 3.5;   //ido
     
int main() {
      while(1){
       
/*         if(gps.longitude>lon - 5  && gps.longitude>lon )
         {
             nicrom = 1;   
         }
         else
         {
             nicrom = 0;
         }*/
/*        nicrom = 1;
         
        wait(3.0);
        nicrom = 0;    
        wait(0.025);
     }
}

*/













/*
#include "mbed.h"
#include "GPS.h"

Serial pc(USBTX, USBRX);

GPS gps(p9, p10);

DigitalOut nicrom(p21);


float lon = 1.2 ;   //keido
float lat = 3.5;   //ido
     
int main() {
      while(1){
       
       if(gps.longitude>lon - 5  && gps.longitude>lon  && gps.latitude > lat - 5 && gps.latgitude < lat + 5 )
         {
             nicrom = 1;   
         }
         else
         {
             nicrom = 0;
         }
         wait(0.25);
     }
}
*/




/*
// 信号の値をマジックナンバーではなく文字列で表している
// そのまま0と1でも意味はわかるので、あまりこだわらなくてもよい
typedef enum { OFF, ON } state;


// ちょっと難しいけど関数のポインタを使う
// 詳しくは後述
typedef void (*FUNCPTR)();
FUNCPTR pFuncBand;

// onの信号を出力するための関数
// onの信号は赤外線LEDの出力波形で観測すると最初の500[uS]はLoで続く1000[uS]がHi
// Hiのときは38[kHz]のパルス信号を出力する
void on_func(){
    int begin;
    Timer ton;
    // タイマ開始と同時に時間を取得する
    ton.start();
    begin = ton.read_us();
    // タイマの時間が、500[us]経過するまでの間出力は0(Lo)
    while ( 500 > ton.read_us() - begin )
        out.write(0.0f) ;
        
    // 再び時間を取得        
    begin = ton.read_us();
    // タイマの時間が、1000[us]経過するまでの間38[kHz]の方形波を出力する  
    while ( 1000 > ton.read_us() - begin )
        out.write(0.5f) ;
    // タイマの停止    
    ton.stop();
}

// offの信号を出力するための関数
// offの信号は赤外線LEDの出力波形で観測すると最初の500[us]はLoで続く500[uS]がHi
// Hiのときは38[kHz]のパルス信号を出力する
void off_func(){
    int begin;
    Timer toff;
    // タイマ開始と同時に時間を取得する
    toff.start();
    begin = toff.read_us();
    // タイマの時間が、500[uS]経過するまでの間出力は0(Lo)
    while( 500 > toff.read_us() - begin )
        out.write(0.0f) ;
   
   // 再び時間を取得    
    begin = toff.read_us();
    // タイマの時間が、500[uS]経過するまでの間38[kHz]の方形波を出力する  
    while ( 500 > toff.read_us() - begin )
        out.write(0.5f) ;
    // タイマの停止    
    toff.stop() ;    
}


*/








/*
 
#include "mbed.h"
#include "GPS.h"

DigitalIn enable(p5);
PwmOut heat_pwm[] = {p22};

int main() {
    while(1) {
        if(enable) {
            heat_pwm[0].period_ms(10); // set pwm period 10ms=100Hz
        }
        wait(0.25);
    }
}


*/











/*
#include "mbed.h"
#include "GPS.h"

Serial pc(USBTX, USBRX);
GPS gps(p28, p27);

PwmOut heat_pwm[] = {p22};


int main(){
    int heater_num;
    int i;
    float pwidth;
    float modified_cycle = heat_pwm[heater_num].read();
    float lon = 1.2... ;   //keido
    float lat = 3.5...;   //ido
     

    while(1)
     {
      if(gps.sample()) 
      {
         if(gps.longitude>lon - 5  &&   ) 
         {
           for(pwidth=1000;pwidth<=2500;pwidth+=10)
           
  
  
                 wait(0.1);
         }
            pc.printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
         }
      }
         if(gps.sample()) 
         {
            for(pwidth=2300;pwidth>=1500;pwidth-=10){
                
                
                 wait(0.1);
         }
            pc.printf("I'm at %f, %f\n", gps.longitude, gps.latitude);
         }
    }

  heat_pwm[].period_ms(10); // set pwm period 10ms=100Hz
}


*/



/*

#include "mbed.h" 
Serial pc(USBTX, USBRX);

PwmOut heat_pwm[] = {p22};

// change pwm duty cycle
void change_pwm_cycle(int heater_num, int recieve_direction) {
  float modified_cycle = heat_pwm[heater_num].read();
  float temp_difference = Tav[heater_num] - target_temp;
  
  if(temp_difference < 0) {
    temp_difference *= -1;
  }
  
  switch(recieve_direction) {
    case 0:
      if(current_direction[heater_num] == 0) {
        if(temp_difference > 5) {
          modified_cycle -= 0.2;
        } else if(temp_difference < 2) {
          modified_cycle += 0.05;
        }
      } else {
        modified_cycle -= 0.2;
      }
      break;
      
      default:
      break;
  }
  
  if(modified_cycle < 0) {
    modified_cycle = 0;
  } else if(modified_cycle > 1) {
    modified_cycle = 1;
  }
  
  heat_pwm[heater_num].write(modified_cycle);
}



    case 1:
      if(current_direction[heater_num] == 1) {
   

(modified_cycle < 0) {






void control_heater() {
          modified_cycle += 0.2;
        } else if(temp_difference < 2) {
          modified_cycle -= 0.05;
        }
      } else {
        modified_cycle += 0.2;
  }
       }
  if(modified_cycle < 0) {
// control heater
void control_heater() {
  for(int i = 0; i < 2; i++) {
    } 
    if(Tav[i] > target_temp) {
      change_pwm_cycle(i ,0);
    } else if(Tav[i] < target_temp) {
      change_pwm_cycle(i, 1);
      
  heat_pwm[0].period_ms(10); // set pwm period 10ms=100Hz
  

*/