EV3

class source.EV3(varargin)
List of methods:

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);
motorA

Motor – Motor-object interfacing port A. See also Motor.

motorB

Motor – Motor-object interfacing port B. See also Motor.

motorC

Motor – Motor-object interfacing port C. See also Motor.

motorD

Motor – Motor-object interfacing port D. See also Motor.

sensor1

Sensor – Motor-object interfacing port 1. See also Sensor.

sensor2

Sensor – Motor-object interfacing port 2. See also Sensor.

sensor3

Sensor – Motor-object interfacing port 3. See also Sensor.

sensor4

Sensor – Motor-object interfacing port 4. See also Sensor.

debug

numeric in {0,1,2} – 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
batteryMode

string in {‘Percentage’, ‘Voltage’} – Mode for reading battery charge. See also batteryValue. [WRITABLE]

batteryValue

numeric – Current battery charge. Depending on batteryMode, the reading is either in percentage or voltage. See also batteryMode. [READ-ONLY]

isConnected

bool – True if virtual brick-object is connected to physical one. [READ-ONLY]

Example

% This example expects a motor at port A and a (random) sensor at port 1
b = EV3(); %
b.connect(‘usb’); %
ma = b.motorA; %
ma.setProperties(‘power’, 50, ‘limitValue’, 720); %
ma.start(); %
% fun
ma.waitFor(); %
disp(b.sensor1.value); %
b.beep(); %
delete b; %

beep(ev3)

Plays a ‘beep’-tone on brick.

Notes

  • This equals playTone(10, 1000, 100).

Example

b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
b.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
b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
% Setup usb connection, beep when connection has been established b = EV3(); %
b.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

b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
% do stuff
b.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

b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
b.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

b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
b.setProperties(‘debug’, ‘on’, ‘batteryMode’, ‘Voltage’); %
% Instead of: b.debug = ‘on’; b.batteryMode = ‘Voltage’; %

See also EV3.DEBUG, EV3.BATTERYMODE / debug, batteryMode

stopAllMotors(ev3)

Sends a stop-command to all motor-ports.

stopTone(ev3)

Stops tone currently played.

Example

b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
b.playTone(10,100,100000000); % Accidentally given wrong tone duration :)
b.stopTone(); % Stops tone immediately.

tonePlayed(ev3)

Tests if tone is currently played.

Returns:status – True if a tone is being played
Return type:bool
Example
b = EV3(); %
b.connect(‘bt’, ‘serPort’, ‘/dev/rfcomm0’); %
b.playTone(10, 100, 1000); %
pause(0.5); % Small pause is necessary as tone does not start instantaneously
b.tonePlayed(); % -> Outputs 1 to console.