当前位置: 首页>>代码示例>>Java>>正文


Java SensorPort类代码示例

本文整理汇总了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();
}
 
开发者ID:Echtzeitsysteme,项目名称:mindroid,代码行数:17,代码来源:DeviceManager.java

示例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();
	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:32,代码来源:MotorDemo03.java

示例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();
}
 
开发者ID:magnusbae,项目名称:HelloBrick,代码行数:23,代码来源:EV3Helper.java

示例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("","");

    }
 
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:18,代码来源:EV3DevSensorDeviceTest.java

示例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();
}
 
开发者ID:eSDK,项目名称:esdk_ide_ev3,代码行数:20,代码来源:HDCIDERobot.java

示例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);

    }

}
 
开发者ID:phllipo,项目名称:RoboRace,代码行数:21,代码来源:LightTestMain.java

示例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());
}
 
开发者ID:jbenech,项目名称:gnikrap,代码行数:18,代码来源:SimpleEV3Brick.java

示例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);
}
 
开发者ID:jweijers,项目名称:EV3-robots,代码行数:8,代码来源:EventGrab.java

示例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});
}
 
开发者ID:jweijers,项目名称:EV3-robots,代码行数:8,代码来源:GrabBot.java

示例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});
}
 
开发者ID:jweijers,项目名称:EV3-robots,代码行数:10,代码来源:GrabBot.java

示例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);

	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:28,代码来源:ColorSensorTest.java

示例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();
}
 
开发者ID:RadicalZephyr,项目名称:ev3java,代码行数:10,代码来源:Main.java

示例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();
}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:46,代码来源:MotorDemo06.java

示例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();
	}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:65,代码来源:MotorDemo04.java

示例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;
    }
 
开发者ID:ev3dev-lang-java,项目名称:ev3dev-lang-java,代码行数:56,代码来源:EV3DevPlatforms.java


注:本文中的lejos.hardware.port.SensorPort类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。