예제 #1
0
int main(void) {

    initialize();

    print_string("BotShop");
    next_line();
    print_string("Wall Following");

    /*****************************************************************
     * set timer 0 to trigger the interrupt 100 times per second.
     * the OCR register sets how many counts between interrupts.
     * the prescaler set how many clock cycles for every count.
     * 16MHz / prescaler / OCR = interrupts per second.
    /*****************************************************************/
    TCCR0 |= _BV(CS02) | _BV(CS00);   // set prescaler to 1024
    OCR0 = 156;

    while( !get_sw1() );   // wait for button to be pressed
    while( get_sw1() );    // wait for button to be released

    set_point = analog(RANGE_SENSOR);

    // enable timer 0 interrupt
    TIMSK |= _BV(OCIE0);             // enable timer0 interrupt

    // start moving
    move( BASESPEED, BASESPEED );

    // the while loop will spin forever so the program never ends
    // the interrupt handler interrupts this loop to execute its code at regular intervals
    while( 1 );

    return 0;
}
예제 #2
0
int main(void) {
   u16 i;
   u08 data[2];
   int j=0;

   init();
   test_motor();
   clear_screen();

   _delay_ms(100);

   data[0] = 0x1; //change to WAKE mode
   send_address(0x2A,0);
   write_register(&data[0], 1);
   _delay_ms(100);
   unlock_bus();
   //send_address(0x2);
   //read_register(&data[1], 1);
   print_num(data[0]);
   //while(1) {}
   while(1) {
      //X
      send_address(0x1,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ",1);

      //Y
      send_address(0x3,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ", 1);

      //Z
      lcd_cursor(0,1);
      send_address(0x5,1);
      read_register(&(data[0]), 1);
      print_num(data[0]);
      print_string(" ",1);
      print_num(count);
      _delay_ms(50);
      clear_screen();
      OCR2A = 28;

   }





/*



   USI_TWI_Master_Initialize();
   i2cMessageBuf[0] = 0x1c << 1; // Odd numbers for read
   i2cMessageBuf[1] = 0x0d; // Register 0 contains version number
   i2cMessageBuf[2] = (0x1c << 1) + 1; // Odd numbers for read
   i2cMessageBuf[3] = 0x00; // Register 0 contains version number
   USI_TWI_Start_Read_Write( i2cMessageBuf, 1 );

   */
   while(get_sw1() == 0) {}

   DDRD |= _BV(IR_PIN);

   led_on(1);
   led_on(0);

   clear_screen();

   while(1) {
      _delay_ms(1500);

      if (j) {
         clear_screen();
         print_string("test",4);
         led_on(1);
         led_off(0);
         //sbi(PORTC,LCD_E_PIN);
         //sbi(PORTC,LCD_RS_PIN);
         //PORTA = 0xff;

         sbi(PORTD,IR_PIN); //turn on IR pin

         sbi(PORTC,SERVO0_PIN); //set servo pins
         sbi(PORTC,SERVO1_PIN);
         sbi(PORTC,SERVO2_PIN);
         sbi(PORTF,SERVO3_PIN);

         //test i2c pins
         //sbi(PORTE,4);
         //sbi(PORTE,5);
         
         //motor test
         sbi(PORTB,MOTOR0_EN_PIN);
         sbi(PORTB,MOTOR1_EN_PIN);
         sbi(PORTD,MOTOR0_DIR0_PIN); 
         sbi(PORTD,MOTOR0_DIR1_PIN);
         sbi(PORTD,MOTOR1_DIR0_PIN);
         sbi(PORTD,MOTOR1_DIR1_PIN);
         j=0;
      } else {
         led_off(1);
         led_on(0);
         clear_screen();
         print_string("program",7);
         j=1;
         //cbi(PORTC,LCD_E_PIN);
         //cbi(PORTC,LCD_RS_PIN);
         //PORTA = 0;

         cbi(PORTD,IR_PIN); //turn off IR pin

         cbi(PORTC,SERVO0_PIN); //clear servo pins
         cbi(PORTC,SERVO1_PIN);
         cbi(PORTC,SERVO2_PIN);
         cbi(PORTF,SERVO3_PIN);
         
         //test i2c pins
         //cbi(PORTE,4);
         //cbi(PORTE,5);
         
         //motor test
         cbi(PORTB,MOTOR0_EN_PIN);
         cbi(PORTB,MOTOR1_EN_PIN);
         cbi(PORTD,MOTOR0_DIR0_PIN); 
         cbi(PORTD,MOTOR0_DIR1_PIN);
         cbi(PORTD,MOTOR1_DIR0_PIN);
         cbi(PORTD,MOTOR1_DIR1_PIN);
      }

   }

   return 0;
}
예제 #3
0
void calCompass()
{
	int xmin, xmax;
	int ymin, ymax;
	struct heading temp;
	u08 i=0;

	temp = compass();

	xmin = temp.x;
	xmax = temp.x;
	ymin = temp.y;
	ymax = temp.y;

	clear_screen();
	print_string("Calibrating");
	next_line();
	print_string("Compass");

	set_motor_power(0,25);
	set_motor_power(1,-25);


	for(i=0; i<255; i++)
	{
		clear_screen();
		print_string("Calibrating");
		next_line();
		print_string("Compass");

		temp = compass();
		if(xmin > temp.x)
			xmin = temp.x;
		else if(xmax < temp.x)
			xmax = temp.x;

		if(ymin > temp.y)
			ymin = temp.y;
		else if(ymax < temp.y)
			ymax = temp.y;
		delay_ms(10);
	}
	set_motor_power(0,0);
	set_motor_power(1,0);

	compZero.x = (xmin+xmax)>>1;
	compZero.y = (ymin+ymax)>>1;
	clear_screen();
	print_string("x: ");
	print_int( (xmin+xmax)>>1 );
	next_line();
	print_string("y: ");
	print_int( (ymin+ymax)>>1 );
	while(!get_sw1());
	/* test calibration results
	 * x: -3, y: 5
	 * x: -4, y: 7
	 * x: -4, y: 6
	 * x: -5, y: 6
	 * x: -8, y: 8
	 */
	/* i = sine[i];
	i = sine[i];*/
}
예제 #4
0
int main(void)
{
	initialize();
	servo_init();
	motor_init();
	sonar_init();
	set_servo_position(0, 120); //center the servo
	
	print_string("Rodentia Demo");
	next_line();
	print_string("by Austin");
	
	led_on();
	delay_ms(100);
	led_off();
	delay_ms(100);
	led_on();
	delay_ms(100);
	led_off();
	
	//wait for a start signal
	while(!get_sw1())
	{
		/*u08 temp;
		clear_screen();
		temp = analog(0);
		print_int(temp);*/
		delay_ms(50);
	}
	led_on();
	
	while(1)
	{ //find and point toward heading with minimum sonar reading
		u08 heading = 0;
		/*u16 minHeading = 0;
		u16 left = 0;
		u08 aLeft = 1;
		
		u16 right = 0;
		u08 aRight = 1;*/
		u16 sonar = 0x0;
		u16 temp = 0;
		set_servo_position(0, 120); //center the servo
		set_motor_power(0, MIN_POWER);
		set_motor_power(1, -MIN_POWER);
		while(heading < 170) //what's the magic number?
		{
			/*u08 tempL = analog(1);
			u08 tempR = analog(2);
			if(tempL < 25 && aLeft)
			{
				set_motor_power(0, 0);
				left++;
				aLeft = 0;
			}
			if(tempL > 180 && !aLeft)
			{
				set_motor_power(0, 0);
				left++;
				aLeft =  1;
			}
			if(tempR < 25 && aRight)
			{
				set_motor_power(1, 0);
				right++;
				aRight = 0;
			}
			if(tempR > 180 && !aRight)
			{
				set_motor_power(1, 0);
				right++;
				aRight =  1;
			}
			if(left > heading && right > heading)*/
			{
				heading++;
				temp = getSonar(0);
				if(IR(0) > 70)
				{
					temp = 0;
				}
				if(temp > sonar)
				{
					sonar = temp;
					//minHeading = heading;
				}
				clear_screen();
				print_string("here=");
				print_int(temp);
				print_string(" max=");
				print_int(sonar);
				/*next_line();
				print_string("Hdng=");
				print_int(heading);
				print_string(" minH=");
				print_int(minHeading);
				if(left < right)
				{ //left motor on
					set_motor_power(0, MIN_POWER);
				}
				else if (right < left)
				{ //right motor on
					set_motor_power(1, -MIN_POWER);
				}
				else
				{
					set_motor_power(0, MIN_POWER);
					set_motor_power(1, -MIN_POWER);
				}*/
			}
		}
		
		if(sonar > 140)
		{ //set a reasonable maximum value for sonar
			sonar = 140;
		}
		
		//turn back to minumum heading
		temp = 0;
		while( temp < sonar )
		{
			temp = getSonar(0) + 3;
			if(IR(0) > 70)
			{
				temp = 0;
			}
			clear_screen();
			print_string("here=");
			print_int(temp);
			print_string(" max=");
			print_int(sonar);
		}
		/*set_motor_power(0, -MIN_POWER);
		set_motor_power(1, MIN_POWER);
		while(heading > minHeading)
		{
			u08 tempL = analog(1);
			u08 tempR = analog(2);
			if(tempL < 25 && aLeft)
			{
				set_motor_power(0, 0);
				left--;
				aLeft = 0;
			}
			if(tempL > 180 && !aLeft)
			{
				set_motor_power(0, 0);
				left--;
				aLeft =  1;
			}
			if(tempR < 25 && aRight)
			{
				set_motor_power(1, 0);
				right--;
				aRight = 0;
			}
			if(tempR > 180 && !aRight)
			{
				set_motor_power(1, 0);
				right--;
				aRight =  1;
			}
			if(left < heading && right < heading)
			{
				heading--;
				clear_screen();
				print_string("L=");
				print_int(left);
				print_string(" R=");
				print_int(right);
				next_line();
				print_string("Hdng=");
				print_int(heading);
				print_string(" minH=");
				print_int(minHeading);
				if(left > right)
				{ //left motor on
					set_motor_power(0, -MIN_POWER);
				}
				else if (right > left)
				{ //right motor on
					set_motor_power(1, MIN_POWER);
				}
				else
				{
					set_motor_power(0, -MIN_POWER);
					set_motor_power(1, MIN_POWER);
				}
			}
		}*/
		set_motor_power(0, 0);
		set_motor_power(1, 0);
		
		//scan with IR for obstacles
		delay_ms(500);
		u08 dir=120;
		s08 dDir = 1;
		u08 dist = IR(0);
		set_motor_power(0, 100);
		set_motor_power(1, 100);
		while(dist < 100)
		{
			dir += dDir;
			set_servo_position(0, dir);
			if(dir >= 200)
			{
				dDir = -1;
			}
			if(dir <= 40)
			{
				dDir = 1;
			}
			dist = IR(0);
			clear_screen();
			print_string("Distance=");
			print_int(dist);
		}
	}
	/*u08 temp;
	
	while(1)
	{
		clear_screen();
		temp = analog(0);
		print_int(temp);
		set_servo_position(0,temp);
		delay_ms(50);
	}*/
}
예제 #5
0
int main(void) {
  initialize();
int prog=0, bool_=1;
  led_on();
  delay_ms(200);
  led_off();
  delay_ms(200);
  led_on();
  delay_ms(200);
  led_off();
  delay_ms(200);
  print_string("Start Up");
  next_line();
  print_string("Select a Prog");
  delay_ms(1500);
  clear_screen();
  while(bool_){
	print_string("prog " );
	print_int(prog);
	delay_ms(500);
	if(get_sw1()==257)
	{
	    prog++;
		//if(prog>10);
		  // prog=0;
	}
	else
	   bool_=0;
	clear_screen();
  }
  clear_screen();
  print_string("Ready" );
  next_line();  
  print_string("Prog " );
  print_int(prog);
  print_string(" Selected");
  delay_ms(2000);
  clear_screen();
  if(prog==1)
  {
   
       orientate();
	
    /* print_string("Collection");
     one_row();
     deposite();
     clear_screen();
	 print_string("DONE");
	 forward(0);*/
	 
  }
  else if(prog==0)
  {
     print_string("sensor test");
     delay_ms(500);
     clear_screen();
     while(1)
     {
	    forward(100);
        if(digital(0)==1)
	    {  
		   break;
	    }  
	 }
	
     clear_screen();
     
	 print_string("DONE");
     reverse(0, 1000);
	 //stop();
	
  }
  else if(prog==2)
  {
     print_string("ATTACK");
	 forward(100);
	 //swing_left(100,250);
	 clear_screen();
	 print_string("DONE");
	 return 0;
	 //return code?
  }
  return 0;
}