i'm currently doing the tutorials from this page but the code from "Program 5" doesn't works.
Solution from the tutorial: click here
- Code: Select all
import lejos.nxt.*;
import lejos.util.*;
/**
* Test the accuracy of motor speed regulation.
* @author Roger
*/
public class RegulateTest
{
Stopwatch sw = new Stopwatch();
Motor[] m = {Motor.A, Motor.B, Motor.C}; //build an array of motors
/**
* Display program name, wait for button, then call go/
* @param args
*/
public static void main( String[] args)
{
LCD.drawString(" Reg Test", 0, 0);
Button.waitForPress();
LCD.clear();
new RegulateTest().go();
}
/**
* helper method - does the detailed work; resets tacho count, runs motors,
* displays data
*/
public void go()
{
LCD.clear();
sw.reset();
for( int i = 0; i<3; i++)m[i].resetTachoCount();
for( int i = 0; i<3; i++)m[i].setSpeed(720);
for( int i = 0; i<3; i++)m[i].forward();
for(int r = 0 ; r<8; r++)
{
while(sw.elapsed() < 200* r)Thread.yield();
for( int i = 0; i<3; i++)
LCD.drawInt(m[i].getTachoCount(),5*i,r);
}
for( int i = 0; i<3; i++)m[i].stop();
Button.waitForPress();
}
}
In eclipse i get at line 11
- Code: Select all
Motor[] m = {Motor.A, Motor.B, Motor.C}; //build an array of motors
the following error:
- Code: Select all
Multiple markers at this line
- Type mismatch: cannot convert from NXTRegulatedMotor to Motor
- Type mismatch: cannot convert from NXTRegulatedMotor to Motor
- Type mismatch: cannot convert from NXTRegulatedMotor to Motor
and at lines 32, 33, 34, 39, 41
- Code: Select all
32: for( int i = 0; i<3; i++)m[i].resetTachoCount();
33: for( int i = 0; i<3; i++)m[i].setSpeed(720);
34: for( int i = 0; i<3; i++)m[i].forward();
39: LCD.drawInt(m[i].getTachoCount(),5*i,r);
41: for( int i = 0; i<3; i++)m[i].stop();
the following errors:
- Code: Select all
32: The method resetTachoCount() is undefined for the type Motor
33: The method setSpeed(int) is undefined for the type Motor
34: The method forward() is undefined for the type Motor
39: The method getTachoCount() is undefined for the type Motor
41: The method stop() is undefined for the type Motor
There seems to be an problem by defining the Motor[]-Array.
If I try to run it on my NXT, then i get this error code:
- Code: Select all
Exception: 2
Unresolved compi
at: 6(7)
If i rewrite the code to this, it works:
- Code: Select all
import lejos.nxt.*;
import lejos.util.*;
public class RegTest
{
Stopwatch sw = new Stopwatch();
//Motor[] m = {Motor.A, Motor.B, Motor.C};
MotorPort[] m = {MotorPort.A, MotorPort.B, MotorPort.C};
public static void main (String[] args)
{
LCD.drawString("Reg Test", 0, 0);
Button.waitForPress();
LCD.clear();
new RegTest().go();
}
public void go()
{
LCD.clear();
sw.reset();
for(int i=0; i<3; i++) m[i].resetTachoCount();
//for(int i=0; i<3; i++) m[i].setSpeed(720);
//for(int i=0; i<3; i++) m[i].forward();
for(int i=0; i<3; i++) m[i].controlMotor(100, 1);
for(int r=0; r<8; r++)
{
while(sw.elapsed() < 200* r) Thread.yield();
for(int i=0; i<3; i++)
LCD.drawInt(m[i].getTachoCount(), 5*i, r);
}
//for(int i=0; i<3; i++) m[i].stop();
for(int i=0; i<3; i++) m[i].controlMotor(0, 3);
Button.waitForPress();
}
}
But i want to know, why the solution from the tutorial doens't work. Where is the problem?
Thanks in advance!
