![]() |
User Control Code |
---|
The minimum requirements for the Robot class can be found
here. This template file should be used as the
starting point when creating your own controllers. You can simply add your
own methods and fields to this class definition to define your behaviors.
You should try to put as many of your repetitive routines as possible into
the run()
method. Calling methods that may loop indefinitely
from within the run()
method, may cause this thread to continue
executing after the thread was halted from the interface. To avoid these
potential problems, you should insert statements within potentially endless
loops that test the termination variable boolean active
. When
(active == false)
, a termination "request" has been
sent to the Robot thread via its killControl()
method. By testing
this condition within pieces of code that may take control away from the main
while(active)
loop (in run()
) for long periods of
time, and breaking or returning when (active == false)
, you will
insure the timely termination of this thread.
Almost all of the controllers you develop will involve some form of sensor
polling coupled with setting motor speeds. A recommended "first
controller" to get you started programming, is one that defines a simple
reactive behavior: move the robot around the world and avoid obstacles. The
first step in developing this control, is to create a "dummy"
Robot.java file that either does nothing at all (e.g. the template file) or
one that just sets both motor speeds to 1 and loops indefinitely. Compile
and then execute this code in the simulator, making note of the distance sensor
readings at various distances as it runs. If your code does nothing at all, you
will need to place the robot at different distances from a wall, run the code,
note the sensor readings, halt the run, re-set the robot at a different
distance, etc. - repeating these steps until you understand how sensor readings
generally correspond to distance. The data collected from this phase helps you
determine the safe sensor value thresholds you will need when polling the
sensors in the reactive controller. During polling you will need to compare
these threshold value(s) to the current sensor values to determine when the
robot may be "too close" to an obstacle. When this occurs, set the
motor speeds accordingly so that the robot turns or backs away from the
obstacle. To allow the robot a greater range of exploration, you will want to
set your motor speeds based on the specific sensor or set of sensors that
returned value(s) above the threshold. See the Robot_Example.java file in the
controller subdirectory for code specific examples of polling, etc.
Back | Home |
---|