偵測車輛:探測取料區前方是否有搬運車,並回應給中控主機,同時通知
取料區的卸貨時機和閘門升降時機。
中控主機:接收電腦控制端指令,再將指令透過訊號發送傳達給取料區各
裝置做出相對應的作業。
出貨口:根據接收到訊息,控制出貨裝置送出正確的貨物數量。
閘門系統:閘門能阻止車輛前進,當車輛完成取貨動作,閘門就會開啟,直到車輛通過後再次關閉。
import lejos.nxt.*;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.MotorPort;
import lejos.nxt.NXTMotor;
import lejos.nxt.SensorPort;
import lejos.nxt.addon.NXTLineLeader;
import lejos.util.Delay;
import lejos.nxt.addon.ColorHTSensor;
import lejos.nxt.addon.*;
import java.io.*;
import lejos.nxt.comm.*;
import lejos.util.Delay;
import lejos.nxt.comm.*;
class factories{
static UltrasonicSensor us1 = new UltrasonicSensor(SensorPort.S1);
static UltrasonicSensor us2 = new UltrasonicSensor(SensorPort.S2);
static NXTMotor MotorA = new NXTMotor(MotorPort.A);
static NXTMotor MotorB = new NXTMotor(MotorPort.B);
static NXTMotor MotorC = new NXTMotor(MotorPort.C);
static int red,blue,a;
public static void main(String arg[]){
Button.ESCAPE.addButtonListener(new ButtonListener(){
public void buttonPressed(Button b){System.exit(1);}
public void buttonReleased(Button b) {}
});
factories fa=new factories();
LCD.drawString("Waiting...", 0, 0);
NXTConnection connection = Bluetooth.waitForConnection(); //µ¥«Ý³s½u
DataInputStream dataIn = connection.openDataInputStream();//¨ú±o¿é¤J¦ê¬y
DataOutputStream dataOut =connection.openDataOutputStream();
LCD.drawString("OK...", 0, 0);
try{
while(true){
a = dataIn.read();
red=dataIn.read();
blue=dataIn.read();
if(a==1){
fa.factories(red,blue);
LCD.drawString("ok", 0, 1);
}
}
}catch(IOException e) {System.exit(1);}
}
public void factories(int blue ,int red){
while (!Button.ESCAPE.isDown()){
int sound1;
int sound2;
sound1 = us1.getDistance();
sound2 = us2.getDistance();
if(sound1<=20||sound2<=20){
Delay.msDelay(2000);
for(int i=1;i<=red;i++){
Motor.A.setSpeed(0);
Motor.B.setSpeed(795);
Motor.B.backward();
MotorC.setPower(0);
Delay.msDelay(431);
Motor.A.setSpeed(0);
Motor.B.setSpeed(0);
Motor.C.setSpeed(0);
Delay.msDelay(100);
}
Motor.A.setSpeed(0);
Motor.B.setSpeed(0);
Motor.C.setSpeed(0);
Delay.msDelay(100);
for(int j=1;j<=blue;j++){
Motor.A.setSpeed(0);
Motor.B.setSpeed(0);
Motor.C.setSpeed(795);
Motor.C.backward();
Delay.msDelay(431);
Motor.A.setSpeed(0);
Motor.B.setSpeed(0);
Motor.C.setSpeed(0);
Delay.msDelay(100);
}
Motor.A.setSpeed(390);
Motor.A.forward();
Motor.B.setSpeed(0);
Motor.C.setSpeed(0);
Delay.msDelay(270);
//----------------------------------------------------
Motor.A.setSpeed(0);
Motor.B.setSpeed(0);
Motor.C.setSpeed(0);
Delay.msDelay(4500);
Motor.A.setSpeed(390);
Motor.A.backward();
Motor.B.setSpeed(0);
Motor.C.setSpeed(0);
Delay.msDelay(270);
break;
}
}
}
}