This repository was archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Motor
Anthony Law edited this page Apr 11, 2016
·
4 revisions
First of all, you have to create LegoPort, as mentioned in tutorial LegoPort.
LegoPort port = new LegoPort(LegoPort.OUTPUT_A);Then, we can play with the motors now! Import the Motor class.
import ev3dev.hardware.Motor;And then, create a new instance of it.
Motor motor = new Motor(port); //Use the last created portYou can command it with different commands:
-
motor.runForever()A function to cause the motor to run until another command is sent -
motor.runToAbsPos()A function to run to an absolute position specified bysetPosition_SP(int pos) -
motor.runToRelPos()A function to run to an position relative to the current position value. -
motor.runTimed()A function to run the motor for the amount of time specified insetTime_SP(int ms) -
motor.runDirect()A function to run the motor at the duty cycle specified bysetDutyCycle_SP(int dutycycle_sp) -
motor.stop()A function to stop any of the run commands before they are complete using the command specified bysetStopCommand(String command) -
motor.reset()A function to reset all of the motor parameter attributes to their default value. This will also have the effect of stopping the motor.
Example code:
public static void main(String[] args) throws IOException, InvalidException{
LegoPort port = new LegoPort(LegoPort.OUTPUT_A);
Motor motor = new Motor(port);
motor.setTime_SP(5000);
motor.setDutyCycle_SP(50);
motor.runTimed();
}Different advanced functions / variable are not mentioned here. Check the JavaDoc for more information.