Our Robosapian project has our Robosapien playing golie on a robot soccer field. Our Robosapien has three primitives to block an oncomming shot. It decides which permative to use based on wheather the ball is comming down the middle, from the left, or from the right. A USB camera is used to determine the location of the ball, as well as the timeing of when to start the permatives.
Since we were unable to get OpenCV working, we let the Robosapien know what permative to use, and when to begin the excutation of the permative.
A image of our setup.
The simpliest permative is when the ball is comming right down the center. In order to block the ball, the Robosapien simply walks forward.
The code for this without using video feedback is quite simple since its the easiest permative.
Note use in our code location 1 is the left, location 2 is the middle, and location 3 is the right. All locations are from the point of view of the picture shown above, (as if you are shooting the ball). We used this orientation since it is the same one used in the Robosapien code.
Middle Block Code
if(location==2) // center
{
myRobosapien.sendCode(Robosapien.Walk_Forward);
Thread.sleep(300); // wait 3 seconds
myRobosapien.sendCode(Robosapien.Stop_Code);
}
The location int is initially initialized to 0, this code assumes that the OpenCV will change the location accordingly and tell the program when to begin the permative.
When the ball is coming from the left the Robosapien leans left to block the ball, then uses the pick up command to knock it out of the way, then procedes to walk forward in case the ball is still infront.
When blocking to the right the permative is the same, except it's to the left instead of the right. On the left block video the Robosapien never walks forward because the bluetooth failed to send the command. Since the Robosapien blocked the ball, we didn't feel the need to run the test again.
Left Block Video
Right Block Video
Left Block Code
if(location==1) //left
{
for(int i=0; i<300; i++)
{
myRobosapien.sendCode(Robosapien.Tilt_Body_Left);
Thread.sleep(1);
}
myRobosapien.sendCode(Robosapien.Left_Hand_Pickup);
Thread.sleep(100); //wait one second
myRobosapien.sendCode(Robosapien.Walk_Forward);
Thread.sleep(100); //wait one second
myRobosapien.sendCode(Robosapien.Stop_Code);
}
Right Block Code
if(location==3) //right
{
for(int i=0; i<300; i++)
{
myRobosapien.sendCode(Robosapien.Tilt_Body_Right);
Thread.sleep(1);
}
myRobosapien.sendCode(Robosapien.Right_Hand_Pickup);
Thread.sleep(100); //wait one second
myRobosapien.sendCode(Robosapien.Walk_Forward);
Thread.sleep(100); //wait one second
myRobosapien.sendCode(Robosapien.Stop_Code);
}