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


Java Motor类代码示例

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


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

示例1: run

import lejos.nxt.Motor; //导入依赖的package包/类
@Override
public void run() {
	CS.resetCartesianZero();
	LCD.clear();
	Motor.A.forward();
	Motor.B.backward();
	LCD.drawString("a",1,5);
	while(!Button.ESCAPE.isPressed()){
	LCD.drawString("b",2,5);
	int robotangle = (int) (Math.toDegrees(getRobotangle()));
	LCD.clear();
	LCD.drawInt(robotangle, 1, 1);

	LCD.drawInt((int) getRobotpos().x, 1, 2);
	LCD.drawInt((int) getRobotpos().y, 1, 3);


	}
}
 
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:20,代码来源:Navigation.java

示例2: rotate

import lejos.nxt.Motor; //导入依赖的package包/类
/** 
 * Turn the robot right or left 
 *  
 * @param side if negative turns left , else right 
 */ 
private static void rotate( int side ){ 
     
     
    // turn right 
    if( side >= 0 ){ 
        Motor.A.forward(); 
        Motor.B.backward(); 
    } 
     
    // turn left 
    else{ 
        Motor.B.forward(); 
        Motor.A.backward(); 
    } 
}
 
开发者ID:xladde,项目名称:hsw,代码行数:21,代码来源:Linie.java

示例3: changeHeadPosition

import lejos.nxt.Motor; //导入依赖的package包/类
public void changeHeadPosition () {
	if (this.isInFrontPosition)
		Motor.C.rotateTo(0, false);
	else
		Motor.C.rotateTo(95, false);
	this.isInFrontPosition = !this.isInFrontPosition;
}
 
开发者ID:yoann-dufresne,项目名称:AFIA_Robots,代码行数:8,代码来源:WallDiscoverer.java

示例4: getAngle

import lejos.nxt.Motor; //导入依赖的package包/类
private double getAngle(long timeshift) {
	double v = new Double(Motor.A.getSpeed()) * Config.WHEEL_CIRCUMFERENCE / 360.0; // meters/seconds
	double deltaD = v * new Double(timeshift) / 1000.0; // meters
	double angle = Math.atan(deltaD / Config.LIGHTS_DISTANCE) * 360.0 / (2*Math.PI);
	
	return angle;
}
 
开发者ID:yoann-dufresne,项目名称:AFIA_Robots,代码行数:8,代码来源:LineObserver.java

示例5: Movement

import lejos.nxt.Motor; //导入依赖的package包/类
public Movement(Position position) {
	this.right = Motor.A;
	this.right.setSpeed(550);
	this.left = Motor.B;
	this.left.setSpeed(550);
	this.position = position;
	this.needCalm = false;
	this.isRotating = false;
}
 
开发者ID:yoann-dufresne,项目名称:AFIA_Robots,代码行数:10,代码来源:Movement.java

示例6: getRobotangle

import lejos.nxt.Motor; //导入依赖的package包/类
public double getRobotangle(){
	robotnewangle = robotangle - (Math.toRadians(CS.getDegreesCartesian()));
	robotangle = (Math.toRadians(CS.getDegreesCartesian()));
	
	leftwheelangle = ((Math.toRadians(Motor.A.getTachoCount())) - leftwheeloldangle);
	rightwheelangle = ((Math.toRadians(Motor.B.getTachoCount())) - rightwheeloldangle);
	
	leftdist = ((wheeldiameter*Math.PI)*leftwheelangle/(2*Math.PI));
	rightdist = ((wheeldiameter*Math.PI)*rightwheelangle/(2*Math.PI));
	
	return robotangle;
}
 
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:13,代码来源:Navigation.java

示例7: action

import lejos.nxt.Motor; //导入依赖的package包/类
@Override
public void action() {
	
	simnav.setTurnSpeed(30);
	simnav.setMoveSpeed(50);
	DS.stopSendData();
	
	Motor.A.setSpeed(30);
	Motor.A.rotate(360, false);
	
	int shortestdist = 1000;
	int shortestdistangle = 0;
	
	for (int x = (DS.LatestRobotData.size()-1); x > 0; x--) {
			if ( DS.LatestRobotData.get(x).getHeadDistance() < shortestdist){
				shortestdist = DS.LatestRobotData.get(x).getHeadDistance();
				shortestdistangle = DS.LatestRobotData.get(x).getHeadHeading();
			}	
	}
	
	
	Motor.A.setSpeed(200);
	Motor.A.rotate(-270);
	Motor.A.setSpeed(50);
	
	if ( shortestdistangle < 180 )simnav.rotate(shortestdistangle);
	else simnav.rotate (shortestdistangle - 360);
	
	DS.startSendData();
	takeControl = false;

}
 
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:33,代码来源:Initialization.java

示例8: run

import lejos.nxt.Motor; //导入依赖的package包/类
@Override
public void run() {
	int Tolerance = 5;
	int HeadFor;
	CompassSensor sensor = new CompassSensor(SensorPort.S1);
	Motor.A.setSpeed(5);
	sensor.resetCartesianZero();
	
	HeadFor = (int) sensor.getDegreesCartesian();

	while(!Button.ESCAPE.isPressed()) {
		LCD.drawInt((int) HeadFor, 1, 1);
		LCD.drawInt((int) Motor.A.getTachoCount(), 1, 2);
		LCD.drawInt((int) sensor.getDegreesCartesian(), 1, 3);

		if(sensor.getDegreesCartesian() > (HeadFor + Tolerance)){
			LCD.drawInt(1, 1, 4);
			Motor.A.backward();
		}else if(sensor.getDegreesCartesian() < (HeadFor - Tolerance)){
			LCD.drawInt(2, 1, 4);
			Motor.A.forward();
		}else{
			Motor.A.stop();
			LCD.drawInt(0, 1, 4);
		}
		
		LCD.refresh();
		
		try {
			Thread.sleep(25);
		} catch (InterruptedException e) {
		}
		
		LCD.clear();
	}
	
}
 
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:38,代码来源:CompassTest.java

示例9: init

import lejos.nxt.Motor; //导入依赖的package包/类
/** 
 *  
 * Initializes the robot machine, set ups the engines and sensors. 
 *  
 */ 
private static void init(){ 
     
    // get variables and sensors 
    sensor1 = new LightSensor(SensorPort.S1); 

    Motor.A.regulateSpeed(true); 
    Motor.B.regulateSpeed(true); 

    time_at_degree = (int) time_at_degree*(turningSpeed); 
}
 
开发者ID:xladde,项目名称:hsw,代码行数:16,代码来源:Linie.java

示例10: rotateAndFind

import lejos.nxt.Motor; //导入依赖的package包/类
/** 
 *  
 * Checks the position in relationship to  
 * the black line while the robot is rotating. 
 *  
 * @param wait_time time that is needed by the robot to rotate an angle 
 * @return line found or not ? 
 * @throws Exception  
 */ 
private static boolean rotateAndFind( float wait_time ) throws Exception{ 
     
    // set speed down to turning speed 
    setSpeed( turningSpeed ); 
     
    // initialize variables 
    int waited = 0; 
     
    // check the line until the rotating stops 
    while( waited < wait_time ){ 

        // Accelerate while you rotate 
        if( Motor.A.getSpeed() < 280 ){ 
            Motor.A.setSpeed( Motor.A.getSpeed() + 5 ); 
            Motor.B.setSpeed( Motor.B.getSpeed() + 5 ); 
        } 
         
        // check position of robot 
        if( isOnLine() ){ 
            stopEngines(); 
            return true;                 
        } 


        // sleep a little bit 
        Thread.sleep(5); 
         
        // increase timers 
        waited += 5; 
    } 
     
    // return false if you didn't found the 
    // black line 
    return false; 
}
 
开发者ID:xladde,项目名称:hsw,代码行数:45,代码来源:Linie.java

示例11: init

import lejos.nxt.Motor; //导入依赖的package包/类
private static void init() {
	// TODO Auto-generated method stub
	// Touchsensor, Lichtsensor instanzieren
	EXIT = new TouchSensor(SensorPort.S2);
	LIGHT = new LightSensor(SensorPort.S1);
	// Motoren zuweisen
	L = Motor.C;
	R = Motor.A;
	// letzte Richtung festlegen
	last_dir = DLEFT;
	// aktuelle Postion ermitteln und zuweisen
	last_pos = isOnLine() ? POS_BLACK : POS_WHITE;
}
 
开发者ID:xladde,项目名称:hsw,代码行数:14,代码来源:BigCourse.java

示例12: onDestroy

import lejos.nxt.Motor; //导入依赖的package包/类
@Override
protected void onDestroy() {
	super.onDestroy();
	if(conn!=null){
		Motor.B.stop();
		Motor.C.stop();
		desconectarNXT();
	}
	if (mBluetoothAdapter.isEnabled()) {
		mBluetoothAdapter.disable();
	}
	
}
 
开发者ID:marianmoldovan,项目名称:atclegonxt,代码行数:14,代码来源:ATCLego.java

示例13: onStop

import lejos.nxt.Motor; //导入依赖的package包/类
@Override
protected void onStop() {
	super.onDestroy();
	if(conn!=null){
		Motor.B.stop();
		Motor.C.stop();
		desconectarNXT();
	}
	
}
 
开发者ID:marianmoldovan,项目名称:atclegonxt,代码行数:11,代码来源:ATCLego.java

示例14: Control

import lejos.nxt.Motor; //导入依赖的package包/类
public Control(boolean sound) {
	this.sensorUltrasonico = new UltrasonicSensor(SensorPort.S2);
	this.sensorDelantero = new TouchSensor(SensorPort.S4);
	this.sensorTrasero = new TouchSensor(SensorPort.S1);

	this.sound=sound;
	
	Motor.B.setPower(this.potenciaMotor);
	Motor.C.setPower(this.potenciaMotor);
}
 
开发者ID:marianmoldovan,项目名称:atclegonxt,代码行数:11,代码来源:Control.java

示例15: adelante

import lejos.nxt.Motor; //导入依赖的package包/类
public void adelante() {
	if (this.accion == 1 || this.accion == 10)
		return;
	int ultimaAccion = this.accion;
	this.accion = 1;

	if (!puedeAdelante())
		return;

	if (esGiro(ultimaAccion)) {
		Motor.B.setPower(this.potenciaMotor);
		Motor.C.setPower(this.potenciaMotor);
	}

	Motor.B.forward();
	Motor.C.forward();

	new Thread() {
		@Override
		public void run() {
			while (accion == 1) {
				if (!puedeAdelante()) {
					parar();
				}
				try {
					Thread.sleep(50);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}.start();
}
 
开发者ID:marianmoldovan,项目名称:atclegonxt,代码行数:35,代码来源:Control.java


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