Before the upgrade, everything was working fine: I was sending commands from my Android to the NXT (via BT) indicating to it which way it should move.
I tilt the phone and in doing so, send some int's to the NXT which then interprets them and decides which way the MMXRegulatedMotor's should move. I'm using the MMX from Mindsensors.
The reason I upgraded is because when using an ordinary LEGO servo motor (which I'm trying to use as the motor which conrols my "radar") seems to jump all over the place and never rotates to the correct spot... it always seems to "overshoot". That's another problem though.
Anyhow, I decided to try the upgrade because I've been reading through the threads and it seems there have been some problems with the resetTachoCount() and so I thought perhaps there had been a fix to the problems I was encountering.
Since the upgrade, if I send values from Android to NXT - values to change the mode of the application (not values intended for the MMX) - all is fine. However, if I send values intended to make the motors of the MMX move, the MMX seems to stall.
I know it's the MMX because if I simply comment out the bit that uses the MMX, all continues to work fine.
Here is some code to help illustrate:
- Code: Select all
public class FreestyleMode {
private MovementManager mm = new MovementManager();
public FreestyleMode() {
}
// integers come from the android via DataInputStream
public void control(int command, int value) {
// Here I pass the values which moves the motors - commented out all works perfectly
// mm.Move(command, value);
}// End control
}// End Class
Here's the class with the MMX
- Code: Select all
public class MovementManager {
private static final int STOP = 0;
private static final int FORWARD = 1;
private static final int BACKWARD = 2;
private static final int LEFT = 3;
private static final int RIGHT = 4;
private NXTMMX mux = new NXTMMX(SensorPort.S1);
private MMXRegulatedMotor rightTrack = new MMXRegulatedMotor(mux,
NXTMMX.MMX_MOTOR_1);
private MMXRegulatedMotor leftTrack = new MMXRegulatedMotor(mux,
NXTMMX.MMX_MOTOR_2);
public MovementManager() {}
public void rotateRadar(int degree){
Motor.A.setSpeed(50);
Motor.A.rotateTo(degree);
}
public void Move(int direction, int speed) {
switch (direction) {
// stop
case STOP:
leftTrack.stop();
rightTrack.stop();
break;
// forward
case FORWARD:
rightTrack.setPower(100);
leftTrack.setPower(100);
leftTrack.setSpeed(speed);
leftTrack.forward();
rightTrack.setSpeed(speed);
rightTrack.forward();
break;
// backwards
case BACKWARD:
rightTrack.setPower(100);
leftTrack.setPower(100);
rightTrack.setSpeed(speed);
rightTrack.backward();
leftTrack.setSpeed(speed);
leftTrack.backward();
break;
// left
case LEFT:
rightTrack.setPower(100);
leftTrack.setPower(100);
rightTrack.setSpeed(speed);
rightTrack.forward();
leftTrack.setSpeed(speed);
leftTrack.backward();
break;
// right
case RIGHT:
rightTrack.setPower(100);
leftTrack.setPower(100);
rightTrack.setSpeed(speed);
rightTrack.backward();
leftTrack.setSpeed(speed);
leftTrack.forward();
break;
}//end of switch
}//end of move()
}//end of class
I've got no errors or crashes and the only way to stop the motors of the MMX is to physically unplug it from the NXT.
Please let me know if there is anything you want me to do to try fix this.
Thanks,
Rich.
