User Tools

Site Tools


Motor Thread Project


  1. Create a program that spins the robot in place until the user tells it to stop.
  2. Implement a listeners that listens for to the user's input and stops the program.
  3. Use concurrency to execute motor commands in order to avoid busy waiting.


  1. Create a sequential program that can make the robot spin in one place and terminate when the user presses the touch sensor.
  2. Create a class that implements the SensorPortListener interface and overrides the stateChanged method. This class should be used to tell the program when the user wishes to stop the program.
  3. Create a Thread subclass that controls motor movement and is managed by the listener. This means that the listener should tell the Thread when to start and stop the motors.
  4. End the program once all of the Threads report that they have finished their assigned tasks.

Final Remarks

  1. This projects uses threading and synchronization; make sure to keep track of which object holds a particular lock at any given time.
  2. Organize the calls to wait and notifyAll carefully; a thread that is waiting on a certain monitor should not miss a notifyAll.
  3. It may be a surprise that the code within the leJOS API currently does not have an implementation for the join method. In other words, the join method that is provided in the leJOS NXJ library is useless. Make sure to take this into account when developing the functionality of the main program/thread.
  4. A listener is used to make sure that input from the user is not missed. In other words, this is to ensure that if the user presses the touch sensor, that it does not go unrecorded. Use this advantage and make sure to synchronize safely so to avoid any potentials for deadlock.
  5. Create a non-threaded version first then implement threading. This approach will help in debugging.
reu/motor_thread_test_project.txt · Last modified: 2009/02/03 08:53 by jtk