I have my robot fully controllable via Android and decided to get the NXTMMX so that I could use an external battery.
I think it might be the battery pack I am using. It's only 6v @ 700mA and I know the unit requires 7.2v or 9v, but I wanted to check and make sure it is not my code before I run out and buy a new battery pack.
Also, I tested it with:
- Code: Select all
public static void main(String[] args) {
NXTMMX mux = new NXTMMX(SensorPort.S1);
MMXRegulatedMotor cat = new MMXRegulatedMotor(mux, NXTMMX.MMX_MOTOR_1);
MMXRegulatedMotor dog = new MMXRegulatedMotor(mux, NXTMMX.MMX_MOTOR_2);
while (!Button.ESCAPE.isPressed()) {
if (Button.LEFT.isPressed()) {
dog.backward();
}
if (Button.RIGHT.isPressed()) {
cat.forward();
}
if (Button.ENTER.isPressed())
mux.stopMotors();
}
}
And it works perfectly(with my current battery pack), but not on my robot.
This is how the code looked prior to installing the NXTMMX:
- Code: Select all
public void takeControl(DataInputStream input, DataOutputStream output) throws IOException {
int command = input.readInt();
int speed = input.readInt();
LCD.clear();
LCD.drawString("command: " + command, 0, 1);
LCD.drawString("speed : " + speed , 0, 2);
LCD.refresh();
switch (command) {
case MOTOR_A_LEFT:
Motor.A.setSpeed(speed );
Motor.A.forward();
break;
case MOTOR_A_RIGHT:
Motor.A.setSpeed(speed );
Motor.A.backward();
break;
case MOTOR_B_FORWARD:
Motor.B.setSpeed(speed );
Motor.B.backward();
break;
case MOTOR_B_BACKWARD:
Motor.B.setSpeed(speed );
Motor.B.backward();
break;
case DISCONNECT:
input.close();
output.close();
break;
case MOTOR_A_STOP:
Motor.A.stop();
break;
case MOTOR_B_STOP:
Motor.B.stop();
break;
}
}
Everything there worked 100% and was very responsive. Then I added the NXTMMX and adjusted the code. replaced the motor commands with:
- Code: Select all
private NXTMMX mux = new NXTMMX(SensorPort.S1);
private MMXRegulatedMotor forwardOrBackward = new MMXRegulatedMotor(mux, NXTMMX.MMX_MOTOR_1);
private MMXRegulatedMotor leftOrRight = new MMXRegulatedMotor(mux, NXTMMX.MMX_MOTOR_2);
And added these to the switch method(I did this for backward() and the other motor on MMX_MOTOR_1)
- Code: Select all
leftOrRight.setSpeed(value);
leftOrRight.forward();
Now, when I run my code and try control the robot via Android, the motors behave erratically. They start and stop and there seems to be a delay somewhere in the connection, although I'm not entirely sure. Eventually it crashes and prints out some error messages on the NXT LCD.
Where might I find a list to all the error meanings?
Any idea's what the problem might be or a clue for me so that I might find it on my own?
I have 2 NXTMMX units and have tested on both of them(seperately) and it's the same problem.
I am using a 6v battery pack. (might be too low)
I am currently testing using normal NXT motors.
Firmware 0.9.0
IDE: Eclipse
Any other info needed, just ask.
Thanks,
Rich.
