ROBOT_연구소/ROBOT_제작

[라인트레이서]F1제작이야기5

SOSABU 2010. 12. 6. 22:41
728x90
반응형

프로그램을 공개 하도록 하죠...

 

워낙 간단하게 짠 프로그램이라 주석문이 없어도 될거 같네요..

 

//*****************소  속 : 한국산업기술대학교 로봇동아리 C.I.R.*******************
//*****************학  과 : 한국산업기술대학교 메카트로닉스공학과******************
//*****************학  번 : 2002132021 성명 : 소병천*******************************
//*****************파일명 : f1lin.c ***날짜 : 2008년 04월 20일*********************

 

#include <mega128.h>
#include <delay.h>

//RC서보모터 각도에 따른 함수
void servo_a()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD.0 = 1;
                delay_us(1355);
                PORTD.0 = 0;
                delay_ms(10);
        }
}
void servo_b()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD.0 = 1;
                delay_us(1405);
                PORTD.0 = 0;
                delay_ms(10);
        }
}
void servoc()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1455);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servod()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1505);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servoe()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1555);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servof()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1605);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servog()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1655);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servoh()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1705);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servoi()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1755);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servoj()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1805);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servok()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1855);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servol()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1905);
                PORTD = 0x00;
                delay_ms(10);
        }
}

void servom()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(1955);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servon()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(2005);
                PORTD = 0x00;
                delay_ms(10);
        }
}
void servoo()
{
        int i;
        for(i = 0; i<30; i++)
        {
                PORTD = 0x01;
                delay_us(2055);
                PORTD = 0x00;
                delay_ms(10);
        }
}
 
void main(void)
{
        int sensor_input;//센서 입력 받을 변수 선언
      
        DDRA=0xFF;//LED포트 출력설정
        DDRB=0xFF;//모터포트 출력설정
        DDRD=0xFF;//서보모터 포트 출력 설정
        DDRE=0x00;//센서포트 입력설정
        DDRF=0xFF;//센서ON/OFF출력설정
       
 //PWM출력 사용 하기 위해 타이머 초기화
 TCCR1A=0x81;
        TCCR1B=0x0B;
        TCNT1H=0x00;
        TCNT1L=0x00;
        ICR1H=0x00;
        ICR1L=0x00;
        OCR1AH=0x00;
        OCR1AL=0x00;
        OCR1BH=0x00;
        OCR1BL=0x00;
        OCR1CH=0x00;
        OCR1CL=0x00;
      
 while (1)
       {
  PORTD = 0xFF;
                PORTF = 0xFF;
                PORTB.6 = 1;//모터 정회전
                PORTE = 0xFF;
                sensor_input = (0xFF & PINE);//센서 입력값 받기
                PORTA = sensor_input;//센서 입력 변수에 받기
              
              
                switch(sensor_input)//라인 인식에 따라 모터속도 및 방향 제어
                {
                     
                       
                        case 0x7F:
                        servo_a();
                        OCR1A = 100;
                        break;
                       
                        case 0x3F:
                        servo_b();
                        OCR1A = 100;
                        break;
                       
                        case 0xBF:
                        servoc();
                        OCR1A = 95;
                        break;
                       
                        case 0x9F:
                        servod();
                        OCR1A = 90;
                        break;
                       
                        case 0xDF:
                        servoe();
                        OCR1A = 80;
                        break;
                       
                        case 0xCF:
                        servof();
                        OCR1A = 80;
                        break;
                       
                        case 0xEF:
                        servog();
                        OCR1A = 50;
                        break;
                       
                        case 0xE7:
                        servoh();
                        OCR1A = 50;
                        break;
                       
                        case 0xF7:
                        servoi();
                        OCR1A = 50;
                        break;
                       
                        case 0xF3:
                        servoj();
                        OCR1A = 80;
                        break;
                       
                        case 0xFB:
                        servok();
                        OCR1A = 80;
                        break;
                       
                        case 0xF9:
                        servol();
                        OCR1A = 90;
                        break;
                       
                        case 0xFD:
                        servom();
                        OCR1A = 95;
                        break;
                       
                        case 0xFC:
                        servon();
                        OCR1A = 100;
                        break;
                       
                        case 0xFE:
                        servoo();
                        OCR1A = 100;
                        break;
                                              
                        default:
                        sensor_input = sensor_input;
                       
                }
                       
               
      };
}

728x90
반응형