本文整理汇总了Java中lejos.hardware.port.SensorPort类的典型用法代码示例。如果您正苦于以下问题:Java SensorPort类的具体用法?Java SensorPort怎么用?Java SensorPort使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SensorPort类属于lejos.hardware.port包,在下文中一共展示了SensorPort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DeviceManager
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public DeviceManager(){
mm = new MotorManager(BrickType.EV3);
sm = new SensorManager(BrickType.EV3);
sensPorts.put("S1", SensorPort.S1);
sensPorts.put("S2", SensorPort.S2);
sensPorts.put("S3", SensorPort.S3);
sensPorts.put("S4", SensorPort.S4);
motorPorts.put("A", MotorPort.A);
motorPorts.put("B", MotorPort.B);
motorPorts.put("C", MotorPort.C);
motorPorts.put("D", MotorPort.D);
checkForCreationThread();
}
示例2: main
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public static void main(String[] args) {
EV3 ev3 = (EV3) BrickFinder.getLocal();
TextLCD lcd = ev3.getTextLCD();
Keys keys = ev3.getKeys();
EV3TouchSensor touchSensor = new EV3TouchSensor(SensorPort.S1);
SensorMode touch = touchSensor.getTouchMode();
float[] sample = new float[touch.sampleSize()];
RegulatedMotor m = new EV3LargeRegulatedMotor(MotorPort.A);
m.resetTachoCount();
m.rotateTo(320, true);
// int angle = m.getTachoCount(); // should be -360
// lcd.drawInt(angle, 0, 0);
// keys.waitForAnyPress();
// m.rotateTo(-100, true);
// do{
// touch.fetchSample(sample, 0);
// } while (sample[0] == 0);
while (m.isMoving())
Thread.yield();
m.stop();
int angle = m.getTachoCount(); // should be < -100
lcd.drawInt(angle, 0, 1);
// keys.waitForAnyPress();
}
示例3: EV3Helper
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
/**
* Instantiates a new helper class and optionally calibrates the cannon.
* Robot is ready for operation after completion.
* @param skipMotorCannonCalibration Set to true if you don't want to calibrate the cannon
*/
public EV3Helper(boolean skipMotorCannonCalibration) {
motorRight = new EV3LargeRegulatedMotor(MotorPort.A);
motorLeft = new EV3LargeRegulatedMotor(MotorPort.B);
//Sets default motor speed for driving motors
motorRight.setSpeed(DEFAULT_MOTOR_SPEED);
motorLeft.setSpeed(DEFAULT_MOTOR_SPEED);
motorCannon = instantiateMotorCannon(skipMotorCannonCalibration);
irSensor = new EV3IRSensor(SensorPort.S1);
colorSensor = new EV3ColorSensor(SensorPort.S4);
rangeSampler = irSensor.getDistanceMode();
lastRange = new float[rangeSampler.sampleSize()];
colors = getColors();
}
示例4: testEV3DevPlatformOnEV3BrickTest
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public void testEV3DevPlatformOnEV3BrickTest() throws IOException {
//Inject a MockBattery object
BatteryMock batteryMock = new BatteryMock(this.tempFolder);
batteryMock.createEV3DevMocksEV3BrickPlatformPath();
EV3DevSensorDeviceChild device = new EV3DevSensorDeviceChild();
LOGGER.debug(device.getROOT_PATH());
LOGGER.debug(device.getSensorPort(SensorPort.S1));
device.detect("demo","ui");
device.getIntegerAttribute("demo");
device.getPlatform();
device.getStringAttribute("demo");
device.setIntegerAttribute("", 0);
device.setStringAttribute("","");
}
示例5: init
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public void init(boolean isClockwiseMove) {
this.robotRunning = true;
//Init Motor
motorA = new EV3MediumRegulatedMotor(MotorPort.A);
motorB = new EV3LargeRegulatedMotor(MotorPort.B);
motorC = new EV3LargeRegulatedMotor(MotorPort.C);
// init sensors
this.colorSensor = new EV3ColorSensor(SensorPort.S3);
//For reading color only
try {
this.colorSensorRGB = new EV3ColorSensor(SensorPort.S2);
} catch(Exception e) {
this.colorSensorRGB = null;
}
new Thread(new ColorIdentifyTask()).start();
new Thread(new LightIdentifyTask()).start();
}
示例6: main
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public static void main(String[] args) {
sensor = new EV3ColorSensor(SensorPort.S1);
sensor.setFloodlight(false);
LCD.drawString("Init", 2, 2);
LCD.setAutoRefresh(false);
brightnessSensorMode = sensor.getRGBMode();
float[] sample = new float[brightnessSensorMode.sampleSize()];
while(true) {
brightnessSensorMode.fetchSample(sample, 0);
LCD.refresh();
LCD.clear();
System.out.println("R: " + sample[0] + " G: " + sample[1] + " B: " + sample[2]);
LCD.drawString("R: " + sample[0], 1, 1);
LCD.drawString("G: " + sample[1], 1, 2);
LCD.drawString("B: " + sample[2], 1, 3);
}
}
示例7: getSensorPort
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
private static Port getSensorPort(String p) throws EV3ScriptException {
switch (p) {
case "1":
case EV3Constants.S1:
return SensorPort.S1;
case "2":
case EV3Constants.S2:
return SensorPort.S2;
case "3":
case EV3Constants.S3:
return SensorPort.S3;
case "4":
case EV3Constants.S4:
return SensorPort.S4;
}
throw new EV3ScriptException(EV3ScriptException.INVALID_SENSOR_PORT, MapBuilder.buildHashMap("port", p).build());
}
示例8: EventGrab
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
private EventGrab(){
//left = new EV3LargeRegulatedMotor(MotorPort.A);
//right = new EV3LargeRegulatedMotor(MotorPort.B);
//touchSensor = new TouchSensor(SensorPort.S1);
//touchSensor.start();
infraredSensor = new InfraredSensor(SensorPort.S1);
}
示例9: GrabBot
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
private GrabBot(){
left = new EV3LargeRegulatedMotor(MotorPort.A);
right = new EV3LargeRegulatedMotor(MotorPort.B);
touch = new EV3TouchSensor(SensorPort.S1);
arbitrator = new Arbitrator(new Behavior[]{forward, hit});
}
示例10: GrabBot
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
private GrabBot(){
left = new EV3LargeRegulatedMotor(MotorPort.A);
right = new EV3LargeRegulatedMotor(MotorPort.B);
touch = new EV3TouchSensor(SensorPort.S1);
Behavior forward = new ForwardBehavior(this);
Behavior hit = new ObstacleBehavior(this);
arbitrator = new Arbitrator(new Behavior[]{forward, hit});
}
示例11: main
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public static void main(String[] args) {
final EV3 ev3 = (EV3) BrickFinder.getLocal();
TextLCD lcd = ev3.getTextLCD();
Keys keys = ev3.getKeys();
// Color sensor
EV3ColorSensor colorSensor = new EV3ColorSensor(SensorPort.S3);
SensorMode color = colorSensor.getRGBMode();
float[] colorSample = new float[color.sampleSize()];
lcd.drawInt(colorSample.length, 0, 2);
int key;
long startTime = System.currentTimeMillis();
long duration;
do {
duration = System.currentTimeMillis() - startTime;
color.fetchSample(colorSample, 0);
lcd.drawString("" + colorSample[0], 0, 3);
lcd.drawString("" + colorSample[1], 0, 4);
lcd.drawString("" + colorSample[2], 0, 5);
lcd.drawString("" + isReflecting(colorSample), 0, 6);
// key = keys.waitForAnyPress();
} while (duration < 60000);
}
示例12: setupSensors
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
void setupSensors() {
logger.trace("setupSensors");
leftTouch = new EV3TouchSensor(SensorPort.S1);
rightTouch = new EV3TouchSensor(SensorPort.S4);
distance = new EV3UltrasonicSensor(SensorPort.S2);
distance.enable();
distanceSampler = distance.getDistanceMode();
}
示例13: main
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public static void main(String[] args) {
EV3 ev3 = (EV3) BrickFinder.getLocal();
TextLCD lcd = ev3.getTextLCD();
Keys keys = ev3.getKeys();
EV3TouchSensor touchSensor = new EV3TouchSensor(SensorPort.S1);
SensorMode touch = touchSensor.getTouchMode();
float[] sample = new float[touch.sampleSize()];
RegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A);
RegulatedMotor mB = new EV3LargeRegulatedMotor(MotorPort.B);
RegulatedMotor mC = new EV3LargeRegulatedMotor(MotorPort.C);
mA.resetTachoCount();
mB.resetTachoCount();
mC.resetTachoCount();
mA.rotateTo(760);
int angle = mA.getTachoCount(); // should be -360
lcd.drawInt(angle, 0, 0);
keys.waitForAnyPress();
mB.setSpeed(720);// 2 RPM
mC.setSpeed(720);
mB.forward();
mC.forward();
Delay.msDelay(1000);
mB.stop();
mC.stop();
mB.rotateTo(360);
mB.rotate(-720, true);
while (mB.isMoving())
Thread.yield();
angle = mB.getTachoCount();
lcd.drawInt(angle, 0, 1);
mA.rotateTo(-100, true);
do{
touch.fetchSample(sample, 0);
} while (mA.isMoving() && sample[0] == 0);
mA.stop();
angle = mA.getTachoCount(); // should be -360
lcd.drawInt(angle, 0, 2);
keys.waitForAnyPress();
}
示例14: main
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
public static void main(String[] args) {
EV3 ev3 = (EV3) BrickFinder.getLocal();
TextLCD lcd = ev3.getTextLCD();
Keys keys = ev3.getKeys();
EV3ColorSensor colorSensor = new EV3ColorSensor(SensorPort.S3);
SensorMode color = colorSensor.getColorIDMode();
float[] sample = new float[color.sampleSize()];
color.fetchSample(sample, 0);
int colorId = (int)sample[0];
String colorName = "";
switch(colorId){
case Color.NONE: colorName = "NONE"; break;
case Color.BLACK: colorName = "BLACK"; break;
case Color.BLUE: colorName = "BLUE"; break;
case Color.GREEN: colorName = "GREEN"; break;
case Color.YELLOW: colorName = "YELLOW"; break;
case Color.RED: colorName = "RED"; break;
case Color.WHITE: colorName = "WHITE"; break;
case Color.BROWN: colorName = "BROWN"; break;
}
lcd.drawString(colorId + " - " + colorName, 0, 0);
keys.waitForAnyPress();
// EV3TouchSensor touchSensor = new EV3TouchSensor(SensorPort.S1);
// SensorMode touch = touchSensor.getTouchMode();
// float[] sample = new float[touch.sampleSize()];
//
// RegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A);
// RegulatedMotor mB = new EV3LargeRegulatedMotor(MotorPort.B);
// RegulatedMotor mC = new EV3LargeRegulatedMotor(MotorPort.C);
// mA.resetTachoCount();
// mB.resetTachoCount();
// mC.resetTachoCount();
//
// mA.rotateTo(760);
// int angle = mA.getTachoCount(); // should be -360
// lcd.drawInt(angle, 0, 0);
// keys.waitForAnyPress();
//
// mB.setSpeed(720);// 2 RPM
// mC.setSpeed(720);
// mB.forward();
// mC.forward();
// Delay.msDelay(1000);
// mB.stop();
// mC.stop();
// mB.rotateTo(360);
// mB.rotate(-720, true);
// while (mB.isMoving())
// Thread.yield();
// angle = mB.getTachoCount();
// lcd.drawInt(angle, 0, 1);
//
// mA.rotateTo(-100, true);
// do{
// touch.fetchSample(sample, 0);
// } while (mA.isMoving() && sample[0] == 0);
// mA.stop();
//
// angle = mA.getTachoCount(); // should be -360
// lcd.drawInt(angle, 0, 2);
// keys.waitForAnyPress();
}
示例15: getSensorPort
import lejos.hardware.port.SensorPort; //导入依赖的package包/类
protected String getSensorPort(final Port port) {
if(this.getPlatform().equals(EV3DevPlatform.EV3BRICK)){
if(port.equals(SensorPort.S1)){
return "in1";
}else if(port.equals(SensorPort.S2)){
return "in2";
}else if(port.equals(SensorPort.S3)){
return "in3";
}else if(port.equals(SensorPort.S4)){
return "in4";
}
} else if(this.getPlatform().equals(EV3DevPlatform.BRICKPI)) {
if (port.equals(SensorPort.S1)) {
return "ttyAMA0:S1";
} else if (port.equals(SensorPort.S2)) {
return "ttyAMA0:S2";
} else if (port.equals(SensorPort.S3)) {
return "ttyAMA0:S3";
} else if (port.equals(SensorPort.S4)) {
return "ttyAMA0:S4";
}
} else if(this.getPlatform().equals(EV3DevPlatform.BRICKPI3)) {
if (port.equals(SensorPort.S1)) {
return "spi0.1:S1";
} else if (port.equals(SensorPort.S2)) {
return "spi0.1:S2";
} else if (port.equals(SensorPort.S3)) {
return "spi0.1:S3";
} else if (port.equals(SensorPort.S4)) {
return "spi0.1:S4";
}
} else {
if (port.equals(SensorPort.S1)) {
return "pistorms:BBS2";
} else if (port.equals(SensorPort.S2)) {
return "pistorms:BBS1";
} else if (port.equals(SensorPort.S3)) {
return "pistorms:BAS1";
} else if (port.equals(SensorPort.S4)) {
return "pistorms:BAS2";
}
}
//TODO Improve
return null;
}