Motor¶
-
class
Motor
(varargin)¶ - List of methods:
High-level class to work with motors.
This class is supposed to ease the use of the brick’s motors. It is possible to set all kinds of parameters, request the current status of the motor ports and of course send commands to the brick to be executed on the respective port.
Notes
- You don’t need to create instances of this class. The EV3-class automatically creates instances for each motor port, and you can work with them via the EV3-object.
- The Motor-class represents motor ports, not individual motors!
- If you start a motor with power=0, the internal state will still be set to ‘isRunning’
- When an input argument of a method is marked as optional, the argument needs to be ‘announced’ by a preceding 2nd argument, which is a string containing the name of the argument. For example, Motor.setProperties may be given a power-parameter. The syntax would be as follows: brickObject.motorA.setProperties(‘power’, 50);
-
power
¶ Power level of motor in percent. [WRITABLE]
Type: numeric in [-100, 100]
-
speedRegulation
¶ Speed regulation turned on or off. When turned on, motor will try to ‘hold’ its speed at given power level, whatever the load. In this mode, the highest possible speed depends on the load and mostly goes up to around 70-80 (at this point, the Brick internally inputs 100% power). When turned off, motor will constantly input the same power into the motor. The resulting speed will be somewhat lower, depending on the load. [WRITABLE]
Type: bool
-
smoothStart
¶ Degrees/Time indicating how far/long the motor should smoothly start. Depending on limitMode, the input is interpreted either in degrees or milliseconds. The first {smoothStart}-milliseconds/degrees of limitValue the motor will slowly accelerate until reaching its defined speed. See also
limitValue
,limitMode
. [WRITABLE]Type: numeric s. t. smoothStart+smoothStop < limitValue
-
smoothStop
¶ Degrees/Time indicating how far/long the motor should smoothly stop. Depending on limitMode, the input is interpreted either in degrees or milliseconds. The last [smoothStop]-milliseconds/degrees of limitValue the motor will slowly slow down until it has stopped. See also
limitValue
,limitMode
. [WRITABLE]Type: numeric s. t. smoothStart+smoothStop < limitValue
-
limitValue
¶ Degrees/Time indicating how far/long the motor should run. Depending on limitMode, the input is interpreted either in degrees or milliseconds. See also
limitMode
. [WRITABLE]Type: numeric>=0
-
limitMode
¶ Mode for motor limit. See also
limitValue
. [WRITABLE]Type: ‘Tacho’|’Time’
-
brakeMode
¶ Action done when stopping. If ‘Coast’, the motor will (at tacholimit, if ~=0) coast to a stop. If ‘Brake’, the motor will stop immediately (at tacholimit, if ~=0) and hold the brake. [WRITABLE]
Type: ‘Brake’|’Coast’
-
debug
¶ Debug turned on or off. In debug mode, everytime a command is passed to the sublayer (‘communication layer’), there is feedback in the console about what command has been called. [WRITABLE]
Type: bool
-
isRunning
¶ True if motor is running. [READ-ONLY]
Type: bool
-
tachoCount
¶ Current tacho count in degrees. [READ-ONLY]
Type: numeric
-
currentSpeed
¶ Current speed of motor. If speedRegulation=on this should equal power, otherwise it will probably be lower than that. See also
speedRegulation
. [READ-ONLY]Type: numeric
-
type
¶ Type of connected device if any. [READ-ONLY]
Type: DeviceType
-
internalReset
(motor)¶ Resets internal tacho count. Use this if motor behaves weird (i.e. not starting at all, or not correctly running to limitValue).
The internal tacho count is used for positioning the motor. When the motor is running with a tacho limit, internally it uses another counter than the one read by tachoCount. This internal tacho count needs to be reset if you physically change the motor’s position or it coasted into a stop. If the motor’s brakemode is ‘Coast’, this function is called automatically.
Notes
- A better name would probably be resetPosition…
- Gets called automatically when starting the motor and the internal tacho count is > 0
See also MOTOR.RESETTACHOCOUNT /
resetTachoCount
-
resetTachoCount
(motor)¶ Resets tachocount.
See also MOTOR.TACHOCOUNT /
tachoCount
-
setBrake
(motor, brake)¶ Apply or release brake of motor.
Parameters: brake (bool) – If true, brake will be pulled Notes
- This method does not affect Motor.brakeMode. After the next run, the motor will again be stopped as specified in Motor.brakeMode.
See also MOTOR.BRAKEMODE /
brakeMode
-
setProperties
(motor, varargin)¶ Sets multiple Motor properties at once using MATLAB’s inputParser.
Parameters: - debug (bool) – [OPTIONAL]
- smoothStart (numeric in [0, limitValue]) – [OPTIONAL]
- smoothStop (numeric in [0, limitValue]) – [OPTIONAL]
- speedRegulation (bool) – [OPTIONAL]
- brakeMode ('Coast'|'Brake') – [OPTIONAL]
- limitMode ('Time'|'Tacho') – [OPTIONAL]
- limitValue (numeric > 0) – [OPTIONAL]
- power (numeric in [-100,100]) – [OPTIONAL]
- batteryMode ('Voltage'|'Percentage') – [OPTIONAL]
Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); brick.motorA.setProperties('debug', 'on', 'power', 50, 'limitValue', 720, 'speedRegulation', 'on'); % Instead of: brick.motorA.debug = 'on'; % brick.motorA.power = 50; % brick.motorA.limitValue = 720; % brick.motorA.speedRegulation = 'on';
-
start
(motor)¶ Starts the motor.
-
stop
(motor)¶ Stops the motor.
Notes
- If this motor has been started synced with another one (either as master or slave, using Motor.syncedStart), syncedStop() will be called, stopping both motors.
See also MOTOR.START, MOTOR.SYNCEDSTOP /
start()
,syncedStop()
-
syncedStart
(motor, syncMotor, varargin)¶ Starts this motor synchronized with another.
The motor, with which this method is called, acts as a master, meaning that the synchronized control is done with it und uses its parameters. When syncedStart is called, the master sets some of the slave’s (syncMotor) properties to keep it consistent with the physical brick. So, for example, if the master has another power-value than the slave, the slave’s power-value will be set to that of the master when syncedStart() is called. The following parameters will be affected on the slave: power, brakeMode, limitValue, speedRegulation
- Arguments:
syncMotor (Motor): The motor-object to sync with turnRatio (numeric in [-200,200]): Ratio between the two master’s and the
slave’s motor speed. With values!=0 one motor will be slower than the other or even turn into the other direction. This can be used for turning car-like robots, for example. [OPTIONAL] (Read in Firmware-comments in c_output.c):
-> 0 is moving straight forward
-> Negative values turn to the left
-> Positive values turn to the right
-> Value -100 stops the left motor
-> Value +100 stops the right motor
-> Values less than -100 makes the left motor run the opposite direction of the right motor (Spin)
-> Values greater than +100 makes the right motor run the opposite direction of the left motor (Spin)- Notes:
- This is a pretty ‘heavy’ function, as it tests if both motors are connected AND aren’t running, wasting four packets, keep that in mind.
Example: brick = EV3(); brick.connect('usb'); motor = brick.motorA; slave = brick.motorB; motor.power = 50; motor.syncedStart(slave); % Do stuff motor.stop(); See also MOTOR.STOP, MOTOR.SYNCEDSTOP / :meth:`stop`, :meth:`syncedStop`
-
syncedStop
(motor)¶ Stops both motors previously started with syncedStart.
Notes
- This method is called automatically by stop(), if the motors have been started using syncedStart, and the regular stop-method has been called afterwards.
See also MOTOR.SYNCEDSTART, MOTOR.STOP /
syncedStart()
,stop()
-
waitFor
(motor)¶ Stops execution of program as long as motor is running.
Notes
- This one’s a bit tricky. The opCode which is supposed to be used here, OutputReady, makes the brick stop sending responses until the motor has stopped. For security reasons, in this toolbox there is an internal timeout for receiving messages from the brick. It raises an error if a reply takes too long, which would happen in this case. As a workaround, there is an infinite loop that catches errors from outputReady and continues then, until outputReady will actually finish without an error.
- Workaround: Poll isRunning until it is false (No need to check if motor is connected as speed correctly returns 0 if it’s not)