Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: RoboChan on June 24, 2009, 11:27:50 AM

Title: I want to build stampy
Post by: RoboChan on June 24, 2009, 11:27:50 AM
Ok i want to build a Stampy like robot. I have 2 DC motors that are very powerful and very Small (from those powerwheels toys). I just want to know is the Duemilanove and the motor shield good for 2 DC motors, a servo, a Sharp IR, and maybe 2 photoresistors. I want is to do what stampy dose but also stay in side a black ring. Can it be programed using arduino or should i use AVR and buy a programmer?
Title: Re: I want to build stampy
Post by: SmAsH on June 24, 2009, 02:30:25 PM
yep, an arduino can do it...
you could have the sharp ir run admins stampy code while the photoresistors watch for the line,
if line detected, back up for a second and turn or the like.
Title: Re: I want to build stampy
Post by: RoboChan on June 24, 2009, 02:50:22 PM
Cool. How can i convert the stampy code to arduino code and how do i implement the photoresistors to the code??
Title: Re: I want to build stampy
Post by: Admin on June 24, 2009, 03:01:07 PM
The $50 Robot has my Stampy code (Sharp IR upgrade), which uses the same exact microcontroller as the Arduino.
Title: Re: I want to build stampy
Post by: RoboChan on June 24, 2009, 03:12:46 PM
Do i have to download the AVR porgrams to veiw the code or is there any stampy code in arduino?
Title: Re: I want to build stampy
Post by: SmAsH on June 24, 2009, 03:59:55 PM
find the $50 robot sharp ir tutorial, the code is in there.
you may have to get avrstudio...
Title: Re: I want to build stampy
Post by: RoboChan on June 25, 2009, 09:42:37 AM
i cant open the code. How do i look at the code with AVR? Theres a note pad doc. MAIN.
Code: [Select]
//www.societyofrobots.com December, 2006

#include "cereb104.h"
#include "Utilities.h"


signed long int scan_angle=0; //angle of IR servo
unsigned int target_distance=0; //distance away of target
unsigned int distance_thresh=30; //acceptable target detection


//sense
void scan()
{
//swap scan directions

/*psuedocode
while object is detected
scan left while object detected
while object not detected
scan right until object detected*/

target_distance = analog(A3);//check sensor

if (target_distance > distance_thresh)//object detected
{
if (scan_angle>-20) //overflow protection
scan_angle-=1;//scan left
}
else //object not detected
{
if (scan_angle<130) //overflow protection
scan_angle+=1; //scan right
else //if scanned all the way, this forces it to start over
scan_angle=-20;
}

//servo scan code
output_bit(PIN_D2, 1);//139 center
long_delay_us(130+scan_angle);
output_bit(PIN_D2, 0);

//printf("angle: %ld distance: %u\r\n", scan_angle, target_distance);//debug code
}


void main() {

//initializing all Cerebellum routines
cereb_init(0);
pwm_init();

//allow short capacitor charge up time
delay_us(5000);

ScanLeft(); //reset IR scanner to straight

//system ready indicator, and start button
set_led(YELLOW, 1);
while(analog(A3) < 100) {printf("%u\r\n", analog(A3));}; //hand swipe to activate robot
set_led(YELLOW, 0);

servoReverse();

while(1)
{
delay_us(2500);//so it doesnt change states too fast //2500 works

scan();//locate target


//movement actions
if (scan_angle > 85)//if target is too far on right
{
servoRight();//turn towards target
set_led(YELLOW, 0);
set_led(GREEN, 1);
scan_angle-=1;//scanner turns left while robot turns right
}
else if (scan_angle < 50)//if target is too far on left
{
servoLeft();//turn towards target
set_led(YELLOW, 1);
set_led(GREEN, 0);
scan_angle+=1;//scanner turns right while robot turns left
}
else //centered on target
{
servoForward();//drive straight
set_led(YELLOW, 1);
set_led(GREEN, 1);
}
}

while(1);
}

//thoughts, try reducing the 5000 delay, maybe doubling negative scan_angle, and reducing turning speed
I tryed looking for arduino sumo robot code but i can't find any. Has anyone ever build a sumo robot with arduino??
Title: Re: I want to build stampy
Post by: Admin on June 25, 2009, 11:32:15 AM
http://www.societyofrobots.com/robot_50_robot_sharpIR.shtml (http://www.societyofrobots.com/robot_50_robot_sharpIR.shtml)