CS 444 - Week 4 Lecture 1 - 2015-02-10 ...another task of the regulator thread in the NXTRegulatedMotor class: ...to control the motor speed; * to go straight, when 2 wheels each attached to a different motor -- the 2 motors need to rotate at the same speed; * standard Lego software: directly synchronize the 2 motors; * NXJ (leJOS) doesn't do this -- it keeps the motor ROTATION synchronized to the system clock; the regulator thread compares the tachometer count (minus its reference count) with the speed (multiplied by) elapsed time; ...and adjusts the power to keep the two quantities closely matched; (and this regulator thread resets its reference count and its elapsed time to zero whenever you call any of the methods we've been using here) * let's see this in action: GoStraight1.java (and please put the names of all on your team in class today in an @author impl'd by name, name, name * SOMETIMES you DON'T want constant speed -- you may want frequent speed adjustments (say, based on sensor readings) -- regulator thread is NOT of benefit here, you'd use an NXTMotor class instance instead of NXTRegulatedMotor; ...no regulator thread is set up by that class (and so you can't call rotate/rotateTo)... you CAN call: setPower(int aPower) ...aPower is a value between 0 and 100 used to control motor power directly; * you can create an NXTMotor instance by calling its constructor with a MotorPort instance: NXTMotor motorB = new NXTMotor(MotorPort.B); * playing with this a LITTLE: NXTMotorTest.java