The hebrew University,
The Institute of CS
Basic Robot Project
How to run it?
This is the robot simulate applet:
If it isn't running (now applet above), you can run it by typing: appletviewer RobotSim.htm
How it works?
The program simulate a user program running.
To run a user program, Enter it's name and press run.
You can press on Running Options, to control on the running:
go back to the first step, go back one step (<<<),go forward one step (>>>) or to continune the running.
Here there is three simples user programs: FirstProgram, SecondProgram
and Third Program.
Creating your own program
To create your own program, let's say userProgram, you should do:
- Create file called userProgram of class in the same name.
- The class should extends RobotProgram.
- It should be able to find all java files at ~jarom/www/project ,
by coping them or with soft link (ln -s ~jarom/www/project).
All files placed at Robot.jar file.
- It should have main method: public void main(String[] args)
- To create a BasicRobot object, named joe at (1,2) facing North with 3 beepers,
you should write: BasicRobot joe = new BasicRobot (1,2,3,"North",this);
The robot interface
The BasicRobot interface, means the command you can give to the robot object, are:
- move - moving forward one step.
- turnLeft - turning left.
- pickBeeper - pick up one beeper.
- putBeeper - put down one beeper.
- turnOff - ends the robot running.
- xLoc, yLoc - return the (x,y) location of the robot.
- facing - return the direction that the robot facing.
- facingNorth, facingSouth, facingEast, facingWest -
return true if the robot facing the direction that asked, false otherwise.
- anyBeepersInBag - return true if there is any beepers at bag, false otherwise.
In the user program there is a world object called myWorld.
The user can ask the world those questions:
- frontIsClear(x,y,facing) - return true if the front is clear.
- leftIsClear(x,y,facing) - return true if left is clear.
- rightIsClear(x,y,facing) - return true if right is clear.
- nextToABeeper(x,y,facing) - return true if the robot is next to a beeper.
(The facing parameter add just to create a uniform parameters structure).
How it loads the user program
Let's say we have a user program look like this:
public class UserProgram extends RobotProgram {
public void main(String[] args) {
BasicRobot lisa = new BasicRobot(2,3,4,"East",this);
lisa.turnLeft();
lisa.turnLeft();
lisa.goForward();
BasicRobot joe = new BasicRobot(3,4,1,"West",this);
joe.goForward();
joe.turnLeft();
joe.goForward();
lisa.turnLeft();
lisa.goForward();
lisa.goForward();
}
}
When you run the Robot.class (by running RobotSim.htm), and pressing
the run button, when the the program file is UserProgram, it does the following:
- It send the request to the dynamicLoaderThrad, to load the program.
- The dynamicLoaderThrad takes the fileName string and make it a RobotProgram class.
- makes a RobotProgram object.
- runs it main method.
- When a BasicRobot object has been created, as a process of the RobotProgram running,
it turn the RobotProgram to be an observer of the BasicRobot object.
- For every action that the BasicRobot done, it inform the RobotProgram
who calling the repaint action of the Robot.
The project objects
- Robot - The main program.
Some notes
- When a robot hit a wall, or try to pick up beeper when trere is no beeper,
it ends its running.
- When one of the robots ends its running, the other robots will continue
their running.
last updated at 29.10.98
return to itai's home page.