100 likes | 226 Views
Sound, Touch Sensor, and Motors. Wheeled Vehicles. Using the Pilot class: Constructor Pilot(float wheelDiameter, float trackWidth,Motor leftMotor, Motor rightMotor) Pilot(float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse)
E N D
Wheeled Vehicles • Using the Pilot class: • Constructor • Pilot(float wheelDiameter, float trackWidth,Motor leftMotor, Motor rightMotor) • Pilot(float wheelDiameter, float trackWidth, Motor leftMotor, Motor rightMotor, boolean reverse) • The boolean reverse will set forward as backward , and vice versa. • Wheel diameter and track width determine the accuracy of NTX’s motion MMN Lab.
Wheeled Vehicles cont’d • Straight line movement • void setSpeed(int speed) • If not specified, use default value • void forward() • void backward() • void stop() • void travel(float distance) • void travel(float distance, boolean immediateReturn) • By using boolean immediateReturn , thecalling thread can do other work while the travel task in progress. • int getTravelDistance() MMN Lab.
Wheeled Vehicles cont’d • Movement along a curved path • void rotate(int angle) • If angle is positive, the robot turns to the left. • void rotate(int angle, boolean immediateReturn ) • By using boolean immediateReturn , thecalling thread can do other work while the rotation task in progress. • void steer(int turnRate) • ratio = 100 - abs(turnRate) MMN Lab.
Wheeled Vehicles cont’d • Other methods • void resetTachocount() • Reset distance and angle counters • boolean isMoving() • boolean stalled() • Returns true if either motor actual speed is zero MMN Lab.
Sound Static method • void playTone(int aFrequency, int aDuration) • void systemSound (boolean aQueued, int aCode) • code = 0 Short beepcode = 1 Double beepcode = 2 Descending arpeggiocode = 3 Ascending arpeggiocode = 4 Long, low buzz MMN Lab.
Sound cont’d MMN Lab.
Touch Sensor • Constructor • TouchSensor(SensorPort port) • Method • boolean isPressed() MMN Lab.
Lab 3 • Sample Code • Move.java • Take the action after pressing any key • ENTER : move forward • ESCAPE : move backward • RIGHT : turn 90° • LEFT : turn -90° • Press ENTER + RIGHT to exit • Bump.java • Show the value returned by touch sensor • PlayMisic.java • Play the Music MMN Lab.
Lab 3 cont’d • Implement this scenario: • 1: Move forward after pressing “ENTER” • 2: After bumping something, turn around and go back to the original position • 3: Turn around again and play the music at the same time MMN Lab.