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


Java EV3ColorSensor类代码示例

本文整理汇总了Java中lejos.hardware.sensor.EV3ColorSensor的典型用法代码示例。如果您正苦于以下问题:Java EV3ColorSensor类的具体用法?Java EV3ColorSensor怎么用?Java EV3ColorSensor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EV3ColorSensor类属于lejos.hardware.sensor包,在下文中一共展示了EV3ColorSensor类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: EV3Helper

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的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

示例2: init

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的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

示例3: main

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的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

示例4: SimpleEV3ColorSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
public SimpleEV3ColorSensor(Port port) {
  delegate = new EV3ColorSensor(port);
  logger = SensorMonitorFactory.getLogger(port);
  // Reflected light mode
  reflectedLightMode = delegate.getRedMode();
  reflectedLightSample = new float[reflectedLightMode.sampleSize()];
  // Ambient light mode
  ambientLightMode = delegate.getAmbientMode();
  ambientLightSample = new float[ambientLightMode.sampleSize()];
  // Color mode
  colorMode = delegate.getColorIDMode();
  colorModeSample = new float[colorMode.sampleSize()];
}
 
开发者ID:jbenech,项目名称:gnikrap,代码行数:14,代码来源:SimpleEV3ColorSensor.java

示例5: init

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
public static void init() {
 GlobalDefinitions.LEFT_MOTOR         = new EV3LargeRegulatedMotor(LocalEV3.get().getPort(GlobalDefinitions.leftMotorPort));
 GlobalDefinitions.RIGHT_MOTOR        = new EV3LargeRegulatedMotor(LocalEV3.get().getPort(GlobalDefinitions.rightMotorPort));
 GlobalDefinitions.RELOADMOTOR        = new EV3LargeRegulatedMotor(LocalEV3.get().getPort(GlobalDefinitions.reloadMotorPort));
 GlobalDefinitions.SHOOTMOTOR        = new EV3LargeRegulatedMotor(LocalEV3.get().getPort(GlobalDefinitions.shooterMotorPort));
 GlobalDefinitions.LEFT_COLOR_SENSOR  = new EV3ColorSensor(LocalEV3.get().getPort(GlobalDefinitions.leftColorSensorPort));
 GlobalDefinitions.RIGHT_COLOR_SENSOR = new EV3ColorSensor(LocalEV3.get().getPort(GlobalDefinitions.rightColorSensorPort));
 GlobalDefinitions.US_SENSOR          = new EV3UltrasonicSensor(LocalEV3.get().getPort(GlobalDefinitions.usSensorPort));
 //GlobalDefinitions.REAR_COLOR_SENSOR  = new EV3ColorSensor(LocalEV3.get().getPort(GlobalDefinitions.rearColorSensorPort)); 
}
 
开发者ID:alisharif2,项目名称:dpm-project,代码行数:11,代码来源:GlobalDefinitions.java

示例6: initSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
private void initSensor(SensorPort sensorPort, Sensor sensorType, Port hardwarePort) {
    if ( sensorType != null && isUsed(sensorType) ) {
        this.lcd.clear();
        // Hal.formatInfoMessage("Initializing " + sensorType.getComponentType().getShortName() + " on port " + sensorPort + " ...", this.lcd);
        switch ( sensorType.getType() ) {
            case COLOR:
                this.lejosSensors.put(sensorPort, sensorSampleProviders(new EV3ColorSensor(hardwarePort)));
                break;
            case INFRARED:
                this.lejosSensors.put(sensorPort, sensorSampleProviders(new EV3IRSensor(hardwarePort)));
                break;
            case GYRO:
                this.gyroSensor = new EV3GyroSensor(hardwarePort);
                this.lejosSensors.put(sensorPort, sensorSampleProviders(this.gyroSensor));
                break;
            case TOUCH:
                this.lejosSensors.put(sensorPort, sensorSampleProviders(new EV3TouchSensor(hardwarePort)));
                break;
            case ULTRASONIC:
                this.lejosSensors.put(sensorPort, sensorSampleProviders(new EV3UltrasonicSensor(hardwarePort)));
                break;
            case COMPASS_HI_TEC:
                this.hiTechnicCompass = new HiTechnicCompass(hardwarePort);
                this.lejosSensors.put(sensorPort, sensorSampleProviders(this.hiTechnicCompass));
                break;
            case SOUND:
                this.lejosSensors.put(sensorPort, sensorSampleProviders(new NXTSoundSensor(hardwarePort)));
                break;
            default:
                throw new DbcException("Sensor type " + sensorType.getType() + " does not exists!");
        }
    }
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:34,代码来源:DeviceHandler.java

示例7: main

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的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

示例8: FilteredColorSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
public FilteredColorSensor(EV3ColorSensor colorSensor) {
	// TODO Auto-generated constructor stub
	this.colorSensorSampleProvider = colorSensor.getMode("RGB");
	this.colorData = new float[colorSensorSampleProvider.sampleSize()];
}
 
开发者ID:alisharif2,项目名称:dpm-project,代码行数:6,代码来源:FilteredColorSensor.java

示例9: setupColorSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
private void setupColorSensor() {
    cSensor = new EV3ColorSensor(ev3.getPort("S2"));
    colourSP = cSensor.getRGBMode();
    colourSample = new float[colourSP.sampleSize()];
}
 
开发者ID:JINKEHE,项目名称:Rescue-Victims,代码行数:6,代码来源:Megatron.java

示例10: createSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
private EV3ColorSensor createSensor(Port port) {
    System.out.println("Create LeJOS color sensor");
    return new EV3ColorSensor(port.getPort());
}
 
开发者ID:bdeneuter,项目名称:rx-mindstorms,代码行数:5,代码来源:ColorSensor.java

示例11: closeSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
private void closeSensor(EV3ColorSensor sensor) {
    System.out.println("Close LeJOS color sensor");
    sensor.close();
}
 
开发者ID:bdeneuter,项目名称:rx-mindstorms,代码行数:5,代码来源:ColorSensor.java

示例12: main

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的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

示例13: getColorSensor

import lejos.hardware.sensor.EV3ColorSensor; //导入依赖的package包/类
public EV3ColorSensor getColorSensor() {
  return colorSensor;
}
 
开发者ID:magnusbae,项目名称:HelloBrick,代码行数:4,代码来源:EV3Helper.java


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