Download presentation
Presentation is loading. Please wait.
Published byBruce Ford Modified over 9 years ago
1
Sound, Touch Sensor, and Motors
2
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.
3
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, the calling thread can do other work while the travel task in progress. –int getTravelDistance() MMN Lab.
4
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, the calling thread can do other work while the rotation task in progress. –void steer(int turnRate) ratio = 100 - abs(turnRate) MMN Lab.
5
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.
6
Sound Static method –void playTone(int aFrequency, int aDuration) –void systemSound (boolean aQueued, int aCode) code = 0 Short beep code = 1 Double beep code = 2 Descending arpeggio code = 3 Ascending arpeggio code = 4 Long, low buzz MMN Lab.
7
Sound cont’d MMN Lab.
8
Touch Sensor Constructor –TouchSensor(SensorPort port) Method –boolean isPressed() MMN Lab.
9
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.
10
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.