Download Final Year Dissertation 2006
Transcript
Faculty of
Information
Technology
public void turnS(){
if (Math.abs(targetHead-heading)>0.2) {
if ((targetHead-heading)<0) {
if ((targetHead+Math.PI)>heading)
//{heading=(float)((heading-0.08f)%(2*Math.PI));}
{heading=(heading-0.08)%(2*Math.PI);}
else
// {heading=(float)((heading+0.08f)%(2*Math.PI));}
{heading=(heading+0.08)%(2*Math.PI);}
} else if ((targetHead-heading)>0) {
if ((heading+Math.PI)>targetHead)
// {heading=(float)((heading+0.08f)%(2*Math.PI));}
{heading=(heading+0.08)%(2*Math.PI);}
else
//{heading=(float)((2*Math.PI+heading0.08f)%(2*Math.PI));}
{heading=(2*Math.PI+heading-0.08)%(2*Math.PI);}
}
// this.heading=(this.heading+change)%(2*Math.PI);
// System.out.println("the first if head...change:
"+change);
}
else {heading=targetHead;}
}
public boolean hasStopped(){
//return this.speed==0;
return (this.loc_x==this.dest_x && this.loc_y==this.dest_y);
}
public boolean finishedTurn(){
return (heading==targetHead);}
}
The ‘behaviour interface’
public interface Behavior {
public void behavior(robot rob, Arbitrator arbi);
/**
* Returns a boolean to indicate if this behavior should take
control of the robot.
*/
public boolean takeControl();
/**
* The code in action() represents the action the robot should
*take when this behavior becomes active.
60