Hi,
My Mindstorms NXT arrived today. I have no experience programming
the Mindstorms (with or without NXT) or programming Lejos. Since I
am a Java programmer, I am very interested (besides RobotC and NBC)
in the Lejos NXT activities of this project.
To answer your question:
- I assume the Motor methods are final to prevent that they are
overwritten. The Mindstorms motor is just a piece of hardware
that does what it does. There are no different motors, with
different or extra features. So there is no point to overwrite
its methods. I think it even would be better to also declare the
class as final, to prevent subclasses.
Your message inspired me to write a "simplified" proxy. I hope
my interpretation of the API is correct. I do not have a Brick
to test it. So I hope it works. Excuses for this lengthy mail.
Greetings,
Peter Joosten.
====================================================================
package org.pejo.robotics;
import josx.platform.rcx.LCD;
import josx.platform.rcx.Segment;
public class Motor {
public static final Motor A = new Motor('A');
public static final Motor B = new Motor('B');
public static final Motor C = new Motor('C');
private josx.platform.rcx.Motor motor;
private Motor(char aId) {
switch (aId) {
case 'A':
motor = josx.platform.rcx.Motor.A;
break;
case 'B':
motor = josx.platform.rcx.Motor.B;
break;
case 'C':
motor = josx.platform.rcx.Motor.C;
break;
}
}
public void backward() {
motor.backward();
setMotorDirectionOnLCD();
}
public void flt() {
motor.flt();
setMotorDirectionOnLCD();
}
public void forward() {
motor.forward();
setMotorDirectionOnLCD();
}
public char getId() {
return motor.getId();
}
public int getPower() {
return motor.getPower();
}
public boolean isBackward() {
return motor.isBackward();
}
public boolean isFloating() {
return isFloating();
}
public boolean isForward() {
return motor.isFloating();
}
public boolean isMoving() {
return motor.isMoving();
}
public boolean isStopped() {
return motor.isStopped();
}
public void reverseDirection() {
motor.reverseDirection();
setMotorDirectionOnLCD();
}
public void setPower(int aPower) {
motor.setPower(aPower);
}
public void stop() {
motor.stop();
setMotorDirectionOnLCD();
}
private void setMotorDirectionOnLCD() {
char theId = motor.getId();
switch (theId) {
case 'A':
setMotorADirectionOnLCD();
break;
case 'B':
setMotorBDirectionOnLCD();
break;
case 'C':
setMotorCDirectionOnLCD();
break;
}
}
private void setMotorADirectionOnLCD() {
LCD.clearSegment(Segment.MOTOR_A_FWD);
LCD.clearSegment(Segment.MOTOR_A_REV);
if (motor.isForward()) {
LCD.setSegment(Segment.MOTOR_A_FWD);
}
if (motor.isBackward()) {
LCD.setSegment(Segment.MOTOR_A_REV);
}
}
private void setMotorBDirectionOnLCD() {
LCD.clearSegment(Segment.MOTOR_B_FWD);
LCD.clearSegment(Segment.MOTOR_B_REV);
if (motor.isForward()) {
LCD.setSegment(Segment.MOTOR_B_FWD);
}
if (motor.isBackward()) {
LCD.setSegment(Segment.MOTOR_B_REV);
}
}
private void setMotorCDirectionOnLCD() {
LCD.clearSegment(Segment.MOTOR_C_FWD);
LCD.clearSegment(Segment.MOTOR_C_REV);
if (motor.isForward()) {
LCD.setSegment(Segment.MOTOR_C_FWD);
}
if (motor.isBackward()) {
LCD.setSegment(Segment.MOTOR_C_REV);
}
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of
William J. Rust
Sent: Friday, September 22, 2006 11:20 PM
To: [email protected]
Subject: [Lejos-discussion] Motor methods final question
I know I should know this but why are the methods in Motor final? As a
exercise in extending classes, I want to extend Motor and add the LCD
displays for forward and backward. Unfortunately, because everything is
final, I can't do it. I assume it's because it takes more runtime memory
for the methods not to be final but is it enough memory to make a
difference?
Thanks,
wjr
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Lejos-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lejos-discussion