作者liwon (不懂)
看板java
标题[问题] 请问乐高机器人Lejos语言
时间Wed Aug 9 22:40:17 2006
这是用来控制乐高机器人的java语言 Lejos
请问有人学过嘛
我想用角度感应器 + 马达
控制马达转速
以下是书上找的程式码
import josx.platform.rcx.Motor;
import josx.platform.rcx.Sensor;
import josx.platform.rcx.SensorConstants;
import josx.platform.rcx.Servo;
import josx.platform.rcx.Sound;
public class ServoDemo{
public static void main(String args[]) throws InterruptedException
{
Servo s = new Servo(Sensor.S3, Motor.A,5);
boolean isthere= s.rotateTo (30);
if(! isthere) {
synchronized(s){
s.wait();
}
}
Sound.buzz();
Thread.currentThread().sleep(1000);
}
}
写一项控制转速 可以跑出结果
但写多项时 马达的转速不能受控制 跑不出程式马上的结果
import josx.platform.rcx.*;
public class TestSensor
{
public static void main(String args[]) throws Exception
{
Servo s = new Servo(Sensor.S3, Motor.A,0);
Servo s1 = new Servo(Sensor.S2, Motor.C,0);
s.rotateTo(5);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s.rotateTo(5);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s1.rotateTo(30);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s.rotateTo(-5);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s.rotateTo(-5);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s1.rotateTo(30);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s.rotateTo(5);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
s.rotateTo(5);
try {Thread.sleep (1000);}
catch (InterruptedException e) {}
Thread.currentThread().sleep(2000);
}
}
请问是我程式有错 还是使用角度感应器时有硬体上的限制???
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.117.211.236