Write a source code in Java NXT legos for this Lawn Mower Robot. The robot has 3
ID: 3840923 • Letter: W
Question
Write a source code in Java NXT legos for this Lawn Mower Robot. The robot has 3 motors A,B,C.
Motor A is the blade which is constantly spinning. Motor B and C are the whelels. The robot has 2 sensors. Touch sensor and light sensor. Light sensor is connected to sensorPort 1and the touch sensor is connected to sensorPort 4. The robot should work when the touch sensor is pressed. Then it use the light sensor to follow the black tape. The robot should able to make small turn. The robot should stop until it reaches the end of black tape.
o:Explanation / Answer
TouchSensor.java
//If the touch sensor is been moved from the position than inform the PC of what has happened.
public void run(){
TouchSensor touchA=new TouchSensor(SensorPort.S1);
TouchSensor touchB=new TouchSensor(SensorPort.S2);
while (true) {
synchronized (mutex) {
try {
bumped=true;
if (touchA.isPressed() || touchB.isPressed()) {
try {
os.write(OpCodes.BUMP_ON.ordinal());
os.flush();
}
catch ( Exception ex) {
}
pilot.stop();
Delay.msDelay(100);
pilot.travel(-20);
LCD.clear();
LCD.drawString("End travel -20",0,0);
pilot.stop();
LCD.drawString("End stop",0,1);
LCD.drawString("Restored travelSpeed",0,2);
try {
os.write(OpCodes.BUMP_OFF.ordinal());
os.flush();
}
catch ( Exception ex) {
LCD.drawString("bump off has been failed",0,2);
}
LCD.drawString("Sent BUMP_OFF",0,3);
}
}
finally {
bumped=false;
mutex.notifyAll();
}
}
}
}
RobotCondition.java
private RobotCondition()
{
ultra=new UltrasonicSensor(Config.ULTRASONIC_PORT);
ls=new ls(Config.LIGHTSENSOR_PORT);
bSensor=new TouchSensor(Config.BUMPSENSOR_PORT);
bSensor2=new TouchSensor(Config.BUMPSENSOR2_PORT);
lastuSmp=new SensorSample(ultra.getDistance());
lstlsSmp=new SensorSample(ls.getLightValue());
newEng=new newEng();
Armsen=new SensorArm();
Button.ESCAPE.addButtonListener(new ButtonListener()
{
public void buttonReleased Button arg0)
{
}
public void buttonPressed( Button arg0)
{
System.exit(0);
}
}
);
}
Hope this would help.... All the best with your robot
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.