|
楼主 |
发表于 2013-5-7 17:09:59
|
显示全部楼层
额,错了,是这个
package org.lejos.example;
import lejos.nxt.*;
import lejos.util.Delay;
import lejos.nxt.Button;
import java.lang.Math;
public class HelloWorld
{
public static void main(String args[])
{
int a[]=new int[6];
int b[]=new int[6];
int c[]=new int[6];
int phase=30;
float step=(float) 0.56;
float range=50;
float flag = 0;
a[0]=(int)(range*Math.sin(flag/2*step));
b[0]=(int)(range*Math.sin((flag/2*step)+phase));
c[0]=(int)(range*Math.sin((flag/2*step)+phase+phase));
a[1]=0;
b[1]=0;
c[1]=0;
LCD.drawString("Setting speed=500", 0, 0);//display program name before running
Motor.A.setSpeed(800);
Motor.B.setSpeed(800);
Motor.C.setSpeed(800);
Motor.A.rotateTo(0);
Motor.B.rotateTo(0);
Motor.C.rotateTo(0);
LCD.drawString("Press a button to start!", 0, 1);
Button.waitForPress();
for(flag=0;flag<=500;flag++)
{
if(Button.ENTER.isPressed()==false)
{
a[1]=(int)(range*Math.sin(flag/2*step));
if(Math.abs(a[1]-a[0])>40)
{
Motor.A.setPower(15);
a[0]=a[1];
Motor.A.rotateTo(a[0],true);
}
else
{
Motor.A.setPower(30);
a[0]=a[1];
Motor.A.rotateTo(a[0],true);
}
Delay.msDelay(4);
b[1]=(int)(range*Math.sin((flag/2*step)+phase));
if(Math.abs(b[1]-b[0])>40)
{
Motor.B.setPower(15);
b[0]=b[1];
Motor.B.rotateTo(b[0],true);
}
else
{
Motor.B.setPower(30);
b[0]=b[1];
Motor.B.rotateTo(b[0],true);
}
Delay.msDelay(4);
c[1]=(int)(range*Math.sin((flag/2*step)+phase+phase));
if(Math.abs(c[1]-c[0])>40)
{
Motor.C.setPower(15);
c[0]=c[1];
Motor.C.rotateTo(c[0],true);
}
else
{
Motor.C.setPower(30);
c[0]=c[1];
Motor.C.rotateTo(c[0],true);
}
Delay.msDelay(4);
/* a[0]=(int)(range*Math.sin(flag/2*step));
b[0]=(int)(range*Math.sin((flag/2*step)+phase));
c[0]=(int)(range*Math.sin((flag/2*step)+phase+phase));
a[1]=a[0]/6;
b[1]=b[0]/6;
c[1]=c[0]/6;
a[2]=a[0]*2/6;
b[2]=b[0]*2/6;
c[2]=c[0]*2/6;
a[3]=a[0]*3/6;
b[3]=b[0]*3/6;
c[3]=c[0]*3/6;
a[4]=a[0]*4/6;
b[4]=b[0]*4/6;
c[4]=c[0]*4/6;
a[5]=a[0]*5/6;
b[5]=b[0]*5/6;
c[5]=c[0]*5/6;
Motor.A.rotateTo(a[1],true);
Delay.usDelay(100);
Motor.B.rotateTo(b[1],true);
Delay.usDelay(100);
Motor.C.rotateTo(c[1],true);
Delay.usDelay(100);
Motor.A.rotateTo(a[2],true);
Delay.usDelay(100);
Motor.B.rotateTo(b[2],true);
Delay.usDelay(100);
Motor.C.rotateTo(c[2],true);
Delay.usDelay(100);
Motor.A.rotateTo(a[3],true);
Delay.usDelay(100);
Motor.B.rotateTo(b[3],true);
Delay.usDelay(100);
Motor.C.rotateTo(c[3],true);
Delay.usDelay(100);
Motor.A.rotateTo(a[4],true);
Delay.usDelay(100);
Motor.B.rotateTo(b[4],true);
Delay.usDelay(100);
Motor.C.rotateTo(c[4],true);
Delay.usDelay(100);
Motor.A.rotateTo(a[5],true);
Delay.usDelay(100);
Motor.B.rotateTo(b[5],true);
Delay.usDelay(100);
Motor.C.rotateTo(c[5],true);
Delay.usDelay(100);
Motor.A.rotateTo(a[0],true);
Delay.usDelay(100);
Motor.B.rotateTo(b[0],true);
Delay.usDelay(100);
Motor.C.rotateTo(c[0],true);
Delay.usDelay(100);
*/
}
else
{
Motor.A.rotateTo(0);
Motor.B.rotateTo(0);
Motor.C.rotateTo(0);
break;
}
}
}
}
}
else
{
Motor.A.rotateTo(0);
Motor.B.rotateTo(0);
Motor.C.rotateTo(0);
break;
}
}
}
} |
|