Skip to content
Snippets Groups Projects
Commit a8517f1a authored by ='s avatar =
Browse files

Initial commit

Adds the beta-version of the toolbox along with examples, a How-To and
convenient documents.
parents
Branches
Tags v0.1
No related merge requests found
Showing
with 347 additions and 0 deletions
/deprecated/*
File added
% init the connection
disp('Connecting ... ')
% brick usb init
b = Brick('ioType','usb');
% beep to indicate connection
b.beep();
% print information
disp('===================================')
disp('EV3 example code')
disp('===================================')
disp('u - increase motor speed')
disp('d - decrease motor speed')
disp('t - start the motor')
disp('s - stop the motor')
disp('b - beep')
disp('o - output the tachometer')
disp('c - clear the tachometer')
disp('v - output the brick voltage')
disp('f - quit the program');
disp('===================================')
% user intput
userIn = '';
% motor power
motorPower = 10;
% set motor power and start
b.outputPower(0,Device.MotorA,motorPower)
b.outputStart(0,Device.MotorA)
while(~strcmp(userIn,'f'))
% get input
userIn = input('> Input(u,d,t,s,b,o,c,v,f): ','s');
% increase speed
if (userIn == 'u')
motorPower = motorPower+10;
if motorPower >= 100
motorPower = 100;
end
b.outputPower(0,Device.MotorA,motorPower)
disp(['> Motor Power: ' num2str(motorPower)]);
end
% decrease speed
if (userIn == 'd')
motorPower = motorPower-10;
if motorPower <= -100
motorPower = -100;
end
b.outputPower(0,Device.MotorA,motorPower)
disp(['> Motor Power: ' num2str(motorPower)]);
end
% start the motor
if (userIn == 't')
b.outputStart(0,Device.MotorA)
disp('> Motor Started');
end
% stop the motor
if (userIn == 's')
b.outputStop(0,Device.MotorA,0)
disp('> Motor Stopped');
end
% beep test
if (userIn == 'b')
b.beep();
disp('> Beep');
end
% output the tachometer
if (userIn == 'o')
tacho = b.outputGetCount(0,Device.MotorA);
disp(['> Tachometer: ' num2str(tacho)]);
end
% clear the tachometer
if (userIn == 'c')
b.outputClrCount(0,Device.MotorA)
disp('> Cleared tacho');
end
% voltage output
if (userIn == 'v')
v = b.uiReadVbatt;
disp(['> Brick voltage: ' num2str(v) 'V']);
end
end
% delete the brick object
delete(b)
\ No newline at end of file
function testConnSpeed(ioType, serPort, it, withResponse)
%testConnSpeed Test connection speed in various modi.
% This is a test function to test how many packets can be sent and received with bluetooth and
% usb. MotorB will run at power 10 for 15 seconds. In 'withResponse'-mode, the isRunning() on
% the brick is polled, therefore on every time step a packet is sent and received. With
% 'withResponse'-mode turned off, a resetTachoCount is sent on each iteration (without waiting
% for a reply).
%
% * ioType: 'bt' or 'usb'
% * serPort: 0 if 'usb', else '/dev/rfcommx'
% * it: number if iterations
% * withResponse: 0 or 1
b = EV3();
if strcmp(ioType, 'bt')
b.connect('ioType', ioType, 'serPort', serPort);
else
b.connect('ioType', 'usb');
end
m = b.motorB;
m.setProperties('power', 10, 'limitMode', 'Time', 'limitValue', 15000);
m.resetTachoCount();
if withResponse
for i = 0:it-1
m.start();
t = 0;
tic;
while m.isRunning()
t = [t; toc];
end
fprintf('Iteration %d\n', i+1);
fprintf('\tTime: %fs\n', t(length(t)));
fprintf('\tReceived packets: %d\n', length(t));
fprintf('\tPackets per sec: %f\n', length(t)/t(length(t)));
pause(0.5);
end
else
for i = 0:it-1
m.start();
t = 0;
tic;
while t < 15
m.resetTachoCount(); % Has no effect but at least sends a packet
t = [t; toc];
end
fprintf('Iteration %d\n', i+1);
fprintf('\tTime: %fs\n', t(length(t)));
fprintf('\tSent packets: %d\n', length(t));
fprintf('\tPackets per sec: %f\n', length(t)/t(length(t)));
pause(0.5);
end
end
b.disconnect();
b.delete();
end
\ No newline at end of file
% Connect with physical brick. If battery charge less than 10% abort. Otherwise,
% create a SyncMotor-object for ports A & B and set some propeties.
% Turn speed regulation on motors A & B on in order to be able to read speed values later.
% ('help Motor.speed' for a little more info)
% Pause program until both motors are connected and then start them.
% As long as they run, print out current speed of both motors.
% Finally, disconnect.
clear all;
b = EV3();
b.connect('ioType', 'bt', 'serPort', '/dev/rfcomm1');
if b.batteryValue < 10
fprintf('Battery charge too low.');
b.disconnect();
else
s = b.coupleMotors('AB', 'useMotorParams', 0);
s.setProperties('Power', 50, 'speedRegulation', 'on', ...
'limitMode', 'Time', 'turnRatio', 50);
s.limitValue = 5000;
s.brakeMode = 'Coast';
b.motorA.speedRegulation = 'on';
b.motorB.speedRegulation = 'on';
s.mode = DeviceMode.Motor.Rotations;
while ~s.motorAtPort
s.update();
pause(0.5);
end
s.start();
while s.isRunning()
fprintf('Speed on A: %d\n',b.motorA.speed);
fprintf('Speed on B: %d\n',b.motorB.speed);
pause(0.1);
end
s.disconnect(); s.delete();
b.disconnect(); b.delete();
end
b = EV3('debug', 1);
b.connect('ioType', 'bt', 'serPort', '/dev/rfcomm0');
tic;
t = 0;
while 1
if b.motorA.motorAtPort && b.motorB.motorAtPort
if b.sensor3.sensorAtPort && b.sensor4.sensorAtPort
if b.sensor3.type == DeviceType.Color
b.sensor3.value
break;
end
end
end
b.update();
t = [t; toc];
end
b.motorA.setProperties('power', 50, 'speedRegulation', 'on', 'smoothStart', 10, 'limitMode', 'time', 'limitValue', 3000);
b.motorA.start();
while b.motorA.isRunning()
b.sensor3.value
b.sensor4.value
b.motorA.tachoCount
end
b.motorB.power = 50;
b.motorB.limitValue = 4*360;
b.motorB.waitFor();
b.sensor3.value
b.motorA.tachoCount
b.sensor3.reset
b.motorA.tachoCount
b.beep
b.disconnect
b.delete
File added
# libhidapi-libusb.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.7ubuntu1
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# The name that we can dlopen(3).
dlname='libhidapi-libusb.so.0'
# Names of this library.
library_names='libhidapi-libusb.so.0.0.0 libhidapi-libusb.so.0 libhidapi-libusb.so'
# The name of the static archive.
old_library='libhidapi-libusb.a'
# Linker flags that can not go in dependency_libs.
inherited_linker_flags=' -pthread'
# Libraries that this one depends upon.
dependency_libs=' -lrt -lusb-1.0'
# Names of additional weak libraries provided by this library
weak_library_names=''
# Version information for libhidapi-libusb.
current=0
age=0
revision=0
# Is this an already installed library?
installed=yes
# Should we warn about portability when linking against -modules?
shouldnotlink=no
# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''
# Directory that this library needs to be installed in:
libdir='/usr/local/MATLAB/R2013b/toolbox/EV3/lib'
File added
classdef Color < uint8
enumeration
Reflect (0)
Ambient (1)
Col (2)
end
end
\ No newline at end of file
classdef Error < uint8
%Error Test
enumeration
Undefined (0)
end
end
\ No newline at end of file
classdef Gyro < uint8
enumeration
Angular (0)
Rate (1)
end
end
\ No newline at end of file
classdef InfraRed < uint8
enumeration
Prox (0)
Seek (1)
Remote (2)
end
end
\ No newline at end of file
classdef Motor < uint8
enumeration
Degrees (0)
Rotations (1)
Speed (2)
end
end
classdef NXTColor < uint8
enumeration
Reflect (0)
Ambient (1)
Color (2)
Green (3)
Blue (4)
Raw (5)
end
end
\ No newline at end of file
classdef NXTLight < uint8
enumeration
Reflect (0)
Ambient (1)
end
end
\ No newline at end of file
classdef NXTSound < uint8
enumeration
DB (0)
DBA (1)
end
end
classdef NXTTemperature < uint8
enumeration
C (0)
F (1)
end
end
\ No newline at end of file
classdef NXTTouch < uint8
enumeration
Pushed (0)
Bumps (1)
end
end
\ No newline at end of file
classdef NXTUltraSonic < uint8
enumeration
CM (0)
IN (1)
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment