[問題] 請問樂高機器人Lejos語言

看板java作者 (不懂)時間19年前 (2006/08/09 22:37), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
這是用來控制樂高機器人的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
文章代碼(AID): #14sVCqNm (java)