Mindsensors Multiplexer v2: problem with NXT brick!

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc

Moderators: roger, 99jonathan, imaqine

Mindsensors Multiplexer v2: problem with NXT brick!

Postby bent » Sat Mar 24, 2012 8:27 am

I am now designing a robot for my project, but the NXT is not enough motor for my robot. So, I have bought a NXTMMX to control two more motors, but I got some troubles with the NXTMMX. When I run motors from the NXTMMX, I can't not come back to the NXT brick.
Here is my code:
Code: Select all
   public static void main(String[] args) {
      
      NXTMMX mux = new NXTMMX(SensorPort.S2);
      
      MMXRegulatedMotor motor1 = new MMXRegulatedMotor(mux, NXTMMX.MMX_MOTOR_1);
      MMXRegulatedMotor motor2 = new MMXRegulatedMotor(mux, NXTMMX.MMX_MOTOR_2);
      
      
      UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S3);
      TouchSensor touch_fwd = new TouchSensor(SensorPort.S1);
      sonic.continuous();
      while(sonic.getDistance()<10){
         LCD.drawInt(sonic.getDistance(), 0, 0);
         motor1.setSpeed(speed);
         motor1.forward();         
         }      
      motor1.stop();
      
      Motor.A.setSpeed(speed);
      Motor.A.forward();
      Delay.msDelay(DELAY);
      Motor.A.stop();      
   }

When my code reached the line "motor1.stop()", it was hang. I guested this is because the signal could not come back the NXT brick.
Anyone has ever got the same situation like me before? Or if anyone has any idea to fix this problem, pls help me.
Thanks a lot.
bent
New User
 
Posts: 1
Joined: Sat Mar 24, 2012 7:42 am

Re: Mindsensors Multiplexer v2: problem with NXT brick!

Postby Rickz2020 » Sat Mar 24, 2012 10:20 pm

Hi,

In this code:
Code: Select all
 Delay.msDelay(DELAY);

Where is "DELAY" and what is it's value?

Maybe you have set the DELAY value to some high number and so it just looks like it's hung?

Also, you could surround your code with:

Code: Select all
while(!Button.ESCAPE.isPressed()){

... put your code here
}

Doing so will make your code loop/repeat until you press the escape button.
Rickz2020
Active User
 
Posts: 121
Joined: Thu Feb 10, 2011 5:47 pm
Location: London, Earth.

Re: Mindsensors Multiplexer v2: problem with NXT brick!

Postby gloomyandy » Sat Mar 24, 2012 10:30 pm

Hi,
It is probably not a good idea to be constantly calling setSpeed and forward in a loop with no delays in it. Nor in the case of your code is there any good reason to do so. Simply moving these calls to before the while loop and then adding a delay as the body of the loop (say 50mS or so, the Ultrasonic sensor does not return new readings much faster than this), will do pretty much the same thing and will not be constantly issuing commands to the motor controller...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3004
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff