Difference between revisions of "Mighty Chihuahua"

From LVL1
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
Mighty Chihuahua AKA Darth Sidious is a 'bot Brian Wagner built for the Spring 2011 Sumobot competition hosted by Hive13.  He is named so because of his yip-yip nature.  He looks like a rabid Chihuahua with ADD.  Watch out Mighty Chihuahua is coming after you!
 
Mighty Chihuahua AKA Darth Sidious is a 'bot Brian Wagner built for the Spring 2011 Sumobot competition hosted by Hive13.  He is named so because of his yip-yip nature.  He looks like a rabid Chihuahua with ADD.  Watch out Mighty Chihuahua is coming after you!
  
[[File:File.png|200px|thumb|left|alt text]]
+
[[File:IMG 7535.JPG|400px|thumb|right]]
  
 
== Components ==
 
== Components ==
Line 9: Line 9:
 
I will get pictures up soon, but until then here are the components I used...
 
I will get pictures up soon, but until then here are the components I used...
  
digital line sensor http://www.pololu.com/catalog/product/959
+
*digital line sensor http://www.pololu.com/catalog/product/959
 +
*Motors are from Solarbotics
 +
*Wheels are from Solarbotics
 +
*Battery is a NiMH 7.2V RC battery
 +
*Controller (computer) is a Orangutan from Pololu.  I cannot say enough good stuff about this controller.  AWESOME!
 +
*Orangutan programmed with AdaFruit's USBTinyISP.  Used WinAVR and programmers notepad.
 +
*Misc wire and other stuff
 +
*All held together with hot melt glue.  Great stuff for building robots
 +
*Some birch plywood and acrylic plastic
  
Misc switches and other stuff
+
== Code ==
 +
Here is the "meat" of the code I am running on Mighty Chihuahua.  I cannot say enough good stuff about the orangutan controllers!
 +
 
 +
<pre>
  
 +
//The main sumo run program.  Press a button to stop the run and return
 +
unsigned char SumoRun()
 +
{
 +
unsigned char button;
 +
 +
int lspeed = -100; //right motor is slightly faster
 +
int rspeed = -95;
 +
int turnspeed = 150;
 +
int turndelay = 400; //read_trimpot(); adjust turn delay with pot???
 +
int lungespeed = read_trimpot();
 +
int DistanceSensorL;
 +
int DistanceSensorR;
 +
int DistanceSensorB;
 +
// int Adjustment;
 +
int LTurn;
 +
int RTurn;
 +
// int ReallyClose = 400;
 +
int Close = 100;
 +
int Far = 40;
 +
int lungecount = 0;
 +
 +
unsigned int LineSensors[2];
 +
 +
if (lungespeed > 150) {
 +
lungespeed = 150;
 +
}
  
== Code ==
+
clear();
This is the code I used. It worked OK, but not great. I need to tweak it more.
+
print("T Minus");
 +
lcd_goto_xy(0, 1);
 +
print("  5      ");
 +
play_from_program_space(beep_button_b);
 +
delay(1000);
 +
lcd_goto_xy(0, 1);
 +
print("  4      ");
 +
play_from_program_space(beep_button_b);
 +
delay(1000);
 +
lcd_goto_xy(0, 1);
 +
print("  3    ");
 +
play_from_program_space(beep_button_b);
 +
delay(1000);
 +
lcd_goto_xy(0, 1);
 +
print("  2    ");
 +
play_from_program_space(beep_button_b);
 +
delay(1000);
 +
lcd_goto_xy(0, 1);
 +
print("  1  ");
 +
play_from_program_space(beep_button_b);
 +
delay(1000);
 +
lcd_goto_xy(0, 1);
 +
print(" FIGHT! ");
 +
play_from_program_space(beep_button_a);
 +
clear();
 +
 
 +
while (1)
 +
{
 +
 
 +
      qtr_read(LineSensors, QTR_EMITTERS_ON);
 +
   
 +
      lcd_goto_xy(0, 0);
 +
  print_long(LineSensors[0]);
 +
  lcd_goto_xy(0, 1);
 +
  print_long(LineSensors[1]);
 +
 
 +
 
 +
  if (LineSensors[0] <750 && LineSensors[1] <750 ) {
 +
//about face
 +
//lcd_goto_xy(0, 0);
 +
//print("About  ");
 +
//lcd_goto_xy(0, 1);
 +
//print("Face  ");
 +
set_motors( 0,  0);
 +
delay(20);
 +
set_motors( lspeed*-1,  rspeed *-1);
 +
delay(400);
 +
set_motors( turnspeed,  turnspeed *-1);
 +
delay(turndelay);
 +
  }
 +
 
 +
  else if (LineSensors[0] <750) {
 +
    //turn left
 +
//lcd_goto_xy(0, 0);
 +
//print("Turn  ");
 +
//lcd_goto_xy(0, 1);
 +
//print("Left  ");
 +
set_motors( 0,  0);
 +
delay(20);
 +
set_motors( lspeed*-1,  rspeed *-1);
 +
delay(100);
 +
set_motors( turnspeed* -1,  turnspeed );
 +
delay(turndelay);
 +
  }
 +
 
 +
  else if (LineSensors[1] <750) {
 +
    //turn right
 +
//lcd_goto_xy(0, 0);
 +
//print("Turn  ");
 +
//lcd_goto_xy(0, 1);
 +
//print("Right  ");
 +
set_motors( 0,  0);
 +
delay(20);
 +
set_motors( lspeed*-1,  rspeed *-1);
 +
delay(100);
 +
set_motors( turnspeed,  turnspeed *-1);
 +
delay(turndelay);
 +
  }
 +
 
 +
 
 +
  //Check the back sensor to see if someone has snuck up on you
 +
  DistanceSensorB = analog_read(2);  // get result
 +
  if ((DistanceSensorB < 500) || (lungecount > 1000)) {
 +
  set_motors( 0,  0);
 +
delay(20);
 +
set_motors( lspeed*-1,  rspeed *-1);
 +
delay(100);
 +
set_motors( turnspeed* -1,  turnspeed );
 +
delay(turndelay);
 +
set_motors( lspeed*-1,  rspeed *-1);
 +
delay(100);
 +
lungecount=0;
 +
  }
 +
 
 +
  //check the eyes
 +
  DistanceSensorL = analog_read(1);  // get result
 +
DistanceSensorR = analog_read(0);  // get result
 +
 +
 
 +
  //locked in close
 +
  if ((DistanceSensorL > Close) && (DistanceSensorR > Close)) {
 +
    LTurn = 150; //full power
 +
    RTurn = 150; //full power
 +
lungecount++;
 +
  }
 +
  else if ((DistanceSensorL > Close) && (DistanceSensorR > Far)) {
 +
LTurn = 0;
 +
    RTurn = 100;
 +
lungecount=0;
 +
  }
 +
  else if ((DistanceSensorL > Close) && (DistanceSensorR > 0)) {
 +
    LTurn = 0;
 +
    RTurn = 100;
 +
lungecount=0;
 +
  }
 +
 
 +
 
 +
  else if ((DistanceSensorL > Far) && (DistanceSensorR > Close)) {
 +
LTurn = 100;
 +
    RTurn = 0;
 +
lungecount=0;
 +
  }
 +
  else if ((DistanceSensorL > Far) && (DistanceSensorR > Far)) {
 +
    LTurn = 100;
 +
    RTurn = 100;
 +
lungecount=0;
 +
  }
 +
  else if ((DistanceSensorL > Far) && (DistanceSensorR > 0)) {
 +
LTurn = 0;
 +
    RTurn = 100;
 +
lungecount=0;
 +
  }
 +
 
 +
 
 +
  else if ((DistanceSensorL > 0) && (DistanceSensorR > Close)) {
 +
    LTurn = 100;
 +
    RTurn = 0;
 +
lungecount=0;
 +
  }
 +
  else if ((DistanceSensorL > 0) && (DistanceSensorR > Far)) {
 +
LTurn = 100;
 +
    RTurn = 0;
 +
lungecount=0;
 +
  }
 +
  else if ((DistanceSensorL > 0) && (DistanceSensorR > 0)) {
 +
    LTurn = 0;
 +
    RTurn = 0;
 +
lungecount=0;
 +
  }
 +
  else {
 +
  LTurn = 0;
 +
    RTurn = 0;
 +
lungecount=0;
 +
  }
 +
 
 +
  lcd_goto_xy(5, 0);
 +
    print_long(DistanceSensorL);
 +
print(" ");
 +
    lcd_goto_xy(5, 1);
 +
    print_long(DistanceSensorR);
 +
print(" ");
  
<pre>
+
  set_motors(lspeed - LTurn, rspeed - RTurn);
 +
 +
  //check for a button press
 +
  button = button_is_pressed(ANY_BUTTON);
 +
  if (button != 0) {
 +
set_motors(0, 0);
 +
return button;
 +
  }
 +
 
 +
 +
}
 +
}
  
  
 
</pre>
 
</pre>

Latest revision as of 10:24, 2 October 2011


Mighty Chihuahua AKA Darth Sidious is a 'bot Brian Wagner built for the Spring 2011 Sumobot competition hosted by Hive13. He is named so because of his yip-yip nature. He looks like a rabid Chihuahua with ADD. Watch out Mighty Chihuahua is coming after you!

IMG 7535.JPG

Components

I will get pictures up soon, but until then here are the components I used...

  • digital line sensor http://www.pololu.com/catalog/product/959
  • Motors are from Solarbotics
  • Wheels are from Solarbotics
  • Battery is a NiMH 7.2V RC battery
  • Controller (computer) is a Orangutan from Pololu. I cannot say enough good stuff about this controller. AWESOME!
  • Orangutan programmed with AdaFruit's USBTinyISP. Used WinAVR and programmers notepad.
  • Misc wire and other stuff
  • All held together with hot melt glue. Great stuff for building robots
  • Some birch plywood and acrylic plastic

Code

Here is the "meat" of the code I am running on Mighty Chihuahua. I cannot say enough good stuff about the orangutan controllers!


//The main sumo run program.  Press a button to stop the run and return
unsigned char SumoRun()
{
	unsigned char button;
	
	int lspeed = -100; //right motor is slightly faster
	int rspeed = -95;
	int turnspeed = 150;
	int turndelay = 400; //read_trimpot(); adjust turn delay with pot???
	int lungespeed = read_trimpot();
	int DistanceSensorL;
	int DistanceSensorR;
	int DistanceSensorB;
//	int Adjustment;
	int LTurn;
	int RTurn;
//	int ReallyClose = 400;
	int Close = 100;
	int Far = 40;
	int lungecount = 0;
	
	unsigned int LineSensors[2];
	
	if (lungespeed > 150) {
		lungespeed = 150;
	}

	clear();			
	print("T Minus");	
	lcd_goto_xy(0, 1);	
	print("  5       ");	
	play_from_program_space(beep_button_b);
	delay(1000);
	lcd_goto_xy(0, 1);	
	print("  4      ");	
	play_from_program_space(beep_button_b);
	delay(1000);
	lcd_goto_xy(0, 1);	
	print("  3     ");	
	play_from_program_space(beep_button_b);
	delay(1000);
	lcd_goto_xy(0, 1);	
	print("  2    ");
	play_from_program_space(beep_button_b);
	delay(1000);	
	lcd_goto_xy(0, 1);	
	print("  1   ");	
	play_from_program_space(beep_button_b);
	delay(1000);
	lcd_goto_xy(0, 1);	
	print(" FIGHT! ");	
	play_from_program_space(beep_button_a);
	clear();

	while (1)
	{
	  
      qtr_read(LineSensors, QTR_EMITTERS_ON);
 	  	  
      lcd_goto_xy(0, 0);
	  print_long(LineSensors[0]);
	  lcd_goto_xy(0, 1);
	  print_long(LineSensors[1]);
	  
	  
	  if (LineSensors[0] <750 && LineSensors[1] <750 ) {
		//about face
		//lcd_goto_xy(0, 0);
		//print("About  ");
		//lcd_goto_xy(0, 1);
		//print("Face  ");
		set_motors( 0,  0);
		delay(20);
		set_motors( lspeed*-1,  rspeed *-1);
		delay(400);
		set_motors( turnspeed,  turnspeed *-1);
		delay(turndelay);
	  }
	  
	  else if (LineSensors[0] <750) {
	    //turn left
		//lcd_goto_xy(0, 0);
		//print("Turn  ");
		//lcd_goto_xy(0, 1);
		//print("Left  ");
		set_motors( 0,  0);
		delay(20);
		set_motors( lspeed*-1,  rspeed *-1);
		delay(100);
		set_motors( turnspeed* -1,  turnspeed );
		delay(turndelay);
	  }
	  
	   else if (LineSensors[1] <750) {
	    //turn right
		//lcd_goto_xy(0, 0);
		//print("Turn  ");
		//lcd_goto_xy(0, 1);
		//print("Right  ");
		set_motors( 0,  0);
		delay(20);
		set_motors( lspeed*-1,  rspeed *-1);
		delay(100);
		set_motors( turnspeed,  turnspeed *-1);
		delay(turndelay);
	  }
	  
	  
	  //Check the back sensor to see if someone has snuck up on you
	  DistanceSensorB = analog_read(2);  // get result
	  if ((DistanceSensorB < 500) || (lungecount > 1000)) {
	  	set_motors( 0,  0);
		delay(20);
		set_motors( lspeed*-1,  rspeed *-1);
		delay(100);
		set_motors( turnspeed* -1,  turnspeed );
		delay(turndelay);
		set_motors( lspeed*-1,  rspeed *-1);
		delay(100);
		lungecount=0;
	  }
	  
	  //check the eyes
	  	DistanceSensorL = analog_read(1);  // get result	
		DistanceSensorR = analog_read(0);  // get result
		

	  //locked in close	
	  if ((DistanceSensorL > Close) && (DistanceSensorR > Close)) {
	     LTurn = 150; //full power 
	     RTurn = 150; //full power
		 lungecount++;
	  }
	  else if ((DistanceSensorL > Close) && (DistanceSensorR > Far)) {
		 LTurn = 0;
	     RTurn = 100;
		 lungecount=0;
	  }
	  else if ((DistanceSensorL > Close) && (DistanceSensorR > 0)) {
	     LTurn = 0;
	     RTurn = 100;
		 lungecount=0;
	  }
	  
	  
	  else if ((DistanceSensorL > Far) && (DistanceSensorR > Close)) {
		 LTurn = 100;
	     RTurn = 0;
		 lungecount=0;
	  }
	  else if ((DistanceSensorL > Far) && (DistanceSensorR > Far)) {
	     LTurn = 100;
	     RTurn = 100;
		 lungecount=0;
	  }
	  else if ((DistanceSensorL > Far) && (DistanceSensorR > 0)) {
		 LTurn = 0;
	     RTurn = 100;
		 lungecount=0;
	  }
	  
	  
	  else if ((DistanceSensorL > 0) && (DistanceSensorR > Close)) {
	     LTurn = 100;
	     RTurn = 0;
		 lungecount=0;
	  }
	  else if ((DistanceSensorL > 0) && (DistanceSensorR > Far)) {
		 LTurn = 100;
	     RTurn = 0;
		 lungecount=0;
	  }
	  else if ((DistanceSensorL > 0) && (DistanceSensorR > 0)) {
	     LTurn = 0;
	     RTurn = 0;
		 lungecount=0;
	  }
	  else {
	  	 LTurn = 0;
	     RTurn = 0;
		 lungecount=0;
	  }
	  
	  	lcd_goto_xy(5, 0);
	    print_long(DistanceSensorL);
		print("  ");
	    lcd_goto_xy(5, 1);
	    print_long(DistanceSensorR);
		 print("  ");

	  set_motors(lspeed - LTurn, rspeed - RTurn); 
		
	  //check for a button press		
	  button = button_is_pressed(ANY_BUTTON);	
	  if (button != 0) {					
		set_motors(0, 0);
		return button;
	  }
	  
	
	}
}