EV3¶
-
class
source.
EV3
(varargin)¶ - List of methods:
connect()
disconnect()
stopAllMotors()
beep()
playTone()
stopTone()
tonePlayed()
setProperties()
High-level class to work with physical bricks.
This is the ‘central’ class (from user’s view) when working with this toolbox. It delivers a convenient interface for creating a connection to the brick and sending commands to it. An EV3-object creates 4 Motor- and 4 Sensor-objects, one for each port.
Notes
- Creating multiple EV3 objects and connecting them to different physical bricks has not been thoroughly tested yet, but seems to work on a first glance.
- 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);
-
debug
¶ Debug mode. [WRITABLE]
- 0: Debug turned off
- 1: Debug turned on for EV3-object -> enables feedback in the console about what firmware-commands have been called when using a method
- 2: Low-level-Debug turned on -> each packet sent and received is printed to the console
Type: numeric in {0,1,2}
-
batteryMode
¶ Mode for reading battery charge. See also
batteryValue
. [WRITABLE]Type: string in {‘Percentage’, ‘Voltage’}
-
batteryValue
¶ Current battery charge. Depending on batteryMode, the reading is either in percentage or voltage. See also
batteryMode
. [READ-ONLY]Type: numeric
-
isConnected
¶ True if virtual brick-object is connected to physical one. [READ-ONLY]
Type: bool
Example: # This example expects a motor at port A and a (random) sensor at port 1 brick = EV3(); brick.connect('usb'); motorA = brick.motorA; motorA.setProperties('power', 50, 'limitValue', 720); motorA.start(); motorA.waitFor(); disp(brick.sensor1.value); brick.beep(); delete brick;
-
beep
(ev3)¶ Plays a ‘beep’-tone on brick.
Notes
- This equals playTone(10, 1000, 100).
Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); brick.beep();
-
connect
(ev3, varargin)¶ Connects EV3-object and its Motors and Sensors to physical brick.
Parameters: - connectionType (string in {'bt', 'usb'}) – Connection type
- serPort (string in {'/dev/rfcomm1', '/dev/rfcomm2', ...}) – Path to serial port (necessary if connectionType is ‘bt’). [OPTIONAL]
- beep (bool) – If true, EV3 beeps if connection has been established. [OPTIONAL]
Example: % Setup bluetooth connection via com-port 0 brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); % Setup usb connection, beep when connection has been established brick = EV3(); brick.connect('usb', 'beep', 'on', );
See also ISCONNECTED /
isConnected
-
disconnect
(ev3)¶ Disconnects EV3-object and its Motors and Sensors from physical brick.
Notes
- Gets called automatically when EV3-object is destroyed.
Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); % do stuff brick.disconnect();
-
playTone
(ev3, volume, frequency, duration)¶ Plays tone on brick.
Parameters: - volume (numeric in [0, 100]) – in percent
- frequency (numeric in [250, 10000]) – in Hertz
- duration (numeric > 0) – in milliseconds
Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); brick.playTone(40, 5000, 1000); % Plays tone with 40% volume and 5000Hz for 1 second.
-
setProperties
(ev3, varargin)¶ Set multiple EV3 properties at once using MATLAB’s inputParser.
Parameters: - debug (numeric in {0,1,2}) – see EV3.debug [OPTIONAL]
- batteryMode (string in {'Voltage'/'Percentage'}) – see EV3.batteryMode [OPTIONAL]
Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); brick.setProperties('debug', 'on', 'batteryMode', 'Voltage'); % Instead of: b.debug = 'on'; b.batteryMode = 'Voltage';
See also EV3.DEBUG, EV3.BATTERYMODE /
debug
,batteryMode
-
stopTone
(ev3)¶ Stops tone currently played.
Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); brick.playTone(10,100,100000000); brick.stopTone(); % Stops tone immediately.
-
tonePlayed
(ev3)¶ Tests if tone is currently played.
Returns: True if a tone is being played Return type: status (bool) Example: brick = EV3(); brick.connect('bt', 'serPort', '/dev/rfcomm0'); brick.playTone(10, 100, 1000); pause(0.5); % Small pause necessary since tone not startong immediately brick.tonePlayed(); % -> Outputs 1 to console.