Wayne Liu

Justin Kufro

This prototype machine allows you to play fetch with your dog hands-free under a sort-of fixed-ratio reinforcement schedule. The machine will most dominantly fake throw a ping pong ball. It will then actually catapult the ball after a fixed number of times of fake throws. A distance sensor is used as part of determining machine states. Being close means that the machine will act playful and ready to throw without actually giving up possession of the ball. Once at a desirable distance away, the machine will decide to either throw or fake-out the user.

Disclaimer: repeated use this machine may cause your dog to become highly skeptical when trying to play fetch.

Video

Files

solidworks files

Code

</pre>
#include <Servo.h>
Servo hit;
Servo throw_b;
const int big_angle1=0;
const int big_angle2=80;
const int small_angle1=170;
const int small_angle2=100;
const int echoPin=11;
const int trigPin=12;
const int SMALL_FAKE=0;
const int BIG_FAKE=1;
const int THRESHOLD=70;
float total_dis,avg_dis;
int mode=0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
hit.attach(9);
throw_b.attach(10);
hit.write(small_angle1);
throw_b.write(big_angle1);
}

void loop() {
int count=0;
total_dis=0;
//averaging multiple readings to filter out errors
while(count<100)
{
total_dis+=detect_distance();
count+=1;
}
avg_dis=total_dis/(count+1);
if(avg_dis<=THRESHOLD)
{
mode=SMALL_FAKE;
}
else mode=BIG_FAKE;
if(mode==BIG_FAKE)
{
// put your main code here, to run repeatedly:
hit.write(small_angle2);
delay(200);
hit.write(small_angle1);
delay(500);
throw_b.write(big_angle2);
delay(500);
throw_b.write(big_angle1);
delay(5000);
Serial.println(mode);
}
else if(mode==SMALL_FAKE)
{
throw_b.write(20);
delay(10);
throw_b.write(0);
delay(10);
throw_b.write(20);
delay(10);
throw_b.write(0);
delay(100);
}
}

float detect_distance()

{
float duration, inches, cm;

pinMode(trigPin, OUTPUT);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

cm = microsecondsToCentimeters(duration);

return cm;
}

float microsecondsToCentimeters(long microseconds)

{
return microseconds / 29 / 2;
}