problem with Motor.A.rotate();

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

problem with Motor.A.rotate();

Postby treeface99 » Tue Jan 10, 2012 1:23 pm

Hi,

I am having trouble rotating the motors 80 degrees.. I am making a blackjack playing nxt robot and am having trouble with my card reading class. This class uses the Lego RGB colour sensor to read two coloured strips on the playing cards. Here is my code for the early stages of my ReadCard class :

import lejos.nxt.*;
import lejos.robotics.Color;

public class ReadCard {



public int CardRead(){

int counter = 0;

String colorNames[] = {"Red", "Green", "Blue", "Yellow",
"Megenta", "Orange", "White", "Black", "Pink",
"Grey", "Light Grey", "Dark Grey", "Cyan"};


while (!Button.ESCAPE.isPressed() && counter == 0)
{


ColorSensor colours = new ColorSensor(SensorPort.S1);
ColorSensor.Color colourVal = colours.getColor();


Motor.A.setSpeed(540);
Motor.B.setSpeed(540);
Motor.C.setSpeed(540);

Motor.A.forward();
Motor.B.forward();
Motor.C.forward();



if (colourVal.getColor()<7){

counter = 1;
Motor.A.rotate(80);
Motor.B.rotate(80);
Motor.C.rotate(80);

}

}


return card;

}

}



The aim of this is to turn the motors to draw in the card and when the sensor senses the beginning of the card, I want all 3 the motors to rotate 80 degrees to position the card in the correct position for the first coloured strip to be read. Everything works until the 'rotate motor' code runs. All that happens is one motor turns slowly for a few seconds then shuts off. If I remove the B and C line and just have Motor.A.rotate(80), it works and motor A rotates 80 degrees. I cant seem to get all 3 motors to rotate 80 degrees.

Any Suggestions?

Many Thanks
treeface99
Novice
 
Posts: 30
Joined: Thu Nov 24, 2011 10:07 am

Re: problem with Motor.A.rotate();

Postby kirkpthompson » Tue Jan 10, 2012 2:05 pm

Try using a Motor.[A/B/C].stop() or .flt() between the.forward() and .rotate() transition and report back what the behavior is.

i.e.
Code: Select all
if (colourVal.getColor()<7){
    Motor.A.stop(true);
    Motor.B.stop(true);
    Motor.C.stop(false);
    counter = 1;
    Motor.A.rotate(80);
    Motor.B.rotate(80);
    Motor.C.rotate(80);
}

Best,
-K
Leg Godt!
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Re: problem with Motor.A.rotate();

Postby gloomyandy » Tue Jan 10, 2012 3:13 pm

Do you really intend to let motors B and C continue moving forward while motor A rotates by 80 degrees. The rotate method waits for the rotation to complete, if you want to just start the operation use the non blocking version. You should probably also move the creation of the color sensor object, and the calls to setSpeed and to forward outside of the loop. Constantly calling these methods is not a good idea...

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

Re: problem with Motor.A.rotate();

Postby treeface99 » Tue Jan 10, 2012 3:23 pm

thanks a lot for your input. I tried :

Code: Select all
if (colourVal.getColor()<7){


            Motor.A.stop(true);
            Motor.B.stop(true);
            Motor.C.stop(false);

         
                        
            Motor.A.rotate(80);
            Motor.B.rotate(80);
            Motor.C.rotate(80);

            counter = 1;
}


This was a little closer to what i am aiming for. Now they perform a 80 degree turn, one at a time. What i need is for all 3 motors to turn 80 degrees at the same time.

I will play around with the creation of the colour sensor object and the setting of speed.

Many Thanks
treeface99
Novice
 
Posts: 30
Joined: Thu Nov 24, 2011 10:07 am

Re: problem with Motor.A.rotate();

Postby gloomyandy » Tue Jan 10, 2012 3:47 pm

As I said above, you need this version of rotate:
http://lejos.sourceforge.net/nxt/nxj/api/lejos/nxt/NXTRegulatedMotor.html#rotate(int,%20boolean)
The one you are using will wait for the rotate to complete. Note that you may need to add code after the loop to wait for all three motors to reach the end point (see the waitComplete method)...

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

Re: problem with Motor.A.rotate();

Postby treeface99 » Tue Jan 10, 2012 3:50 pm

thats great, working now. Thanks very much
treeface99
Novice
 
Posts: 30
Joined: Thu Nov 24, 2011 10:07 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff