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
mob41 edited this page Jan 15, 2017
·
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 org.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();
}Advanced functions please check the JavaDoc for more information.
All motors listed in http://www.ev3dev.org/docs/motors/ are supported. Keep in mind that all Power Functions motors are not automatically detected, and they use the DCMotor class.
| Manufacturer | P/N | Name | Auto-detected | Supported |
|---|---|---|---|---|
| Actuonix | L12-EV3-100 | L12 EV3 100mm | No | Yes |
| Actuonix | L12-EV3-50 | L12 EV3 50mm | No | Yes |
| Lego | 43362 | Motor 9V Mini-motor, newer lighter weight | No | Via DCMotor |
| Lego | 45502 | EV3 Large Servo Motor | Yes | Yes |
| Lego | 45503 | EV3 Medium Servo Motor | Yes | Yes |
| Lego | 47154 | Technic Motor 9V Geared | No | Via DCMotor |
| Lego | 70823 | Motor 9V Micromotor | No | Via DCMotor |
| Lego | 71427 | Motor 9V Mini-motor, older heavier weight | No | Via DCMotor |
| Lego | 74569 | Technic Motor 9V | No | Via DCMotor |
| Lego | 88002 | Power Functions Train Motor | No | Via DCMotor |
| Lego | 88003 | Power Functions L-Motor | No | Via DCMotor |
| Lego | 88004 | Power Functions Servo-Motor | No | Via DCMotor |
| Lego | 8882 | Power Functions XL-Motor | No | Via DCMotor |
| Lego | 8883 | Power Functions M-Motor | No | Via DCMotor |
| Lego | 9670 | E-Motor | No | Via DCMotor |
| Lego | 9842 | Interactive Servo Motor (NXT) | Yes | Yes |