[問題] 請問樂高機器人Lejos語言
這是用來控制樂高機器人的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