Is it possible to use two different toolboxes at once?

2 Ansichten (letzte 30 Tage)
Karl-Axel Ruuth
Karl-Axel Ruuth am 4 Jan. 2018
Kommentiert: Karl-Axel Ruuth am 5 Jan. 2018
Hi!
I need to write a code that allows a Lego Mindstorms Ev3 robot to travel in a straight line until it encounters a magnetic field. The problem is that I have one toolbox for the code that the magnetic sensor uses and another toolbox that makes the robot travel in a straight line. Is it possible to make use of both toolboxes at once?
The toolbox I use for the magnetic sensor I got from
https://wiki.qut.edu.au/download/attachments/172135780/EV3.zip?version=1&modificationDate=1391352088000&api=v2
And the toolbox for the movement of the robot is Mathlabs own Lego Mindstorms toolbox and the code I use is the one you get when you type edit('gostraight_closeloop.m')
When I need to use the toolbox for the magnetic sensor I need to type:
b = Brick('ioType','usb');
And when I need to use mathlabs own toolbox to move the robot I need to type:
mylego = legoev3('usb');
Is it possible that I can use both of these toolboxes at once?

Antworten (1)

Image Analyst
Image Analyst am 4 Jan. 2018
Yes. Nearly everyone here has multiple toolboxes and uses functions from several of them in the same program. It won't be a problem.
  3 Kommentare
Image Analyst
Image Analyst am 5 Jan. 2018
I don't know anything about the Lego functionality. What does "at the same time" mean to you? In the same program, like one line of code after the other? Or truly at the same time like you have the Parallel Processing Toolbox and you have completely separate threads running different code on each CPU?
Karl-Axel Ruuth
Karl-Axel Ruuth am 5 Jan. 2018
I mean that I need to have the magnetic sensor scanning at the same time as the robot is moving in a straight line. The code I use for the movement of the robot is the following:
mylego = legoev3('USB');
mymotor1 = motor(mylego, 'A');
mymotor2 = motor(mylego, 'B');
%Forward---------------------------------------------------------
EXE_TIME = 3;
PERIOD = 0.1;
SPEED = -40;
P = -0.009;
mymotor1.Speed = SPEED;
mymotor2.Speed = SPEED;
resetRotation(mymotor1);
resetRotation(mymotor2);
start(mymotor1);
start(mymotor2);
t = timer('TimerFcn', 'stat=false;', 'StartDelay',EXE_TIME);
start(t);
stat = true;
lastR1 = 0;
lastR2 = 0;
while stat == true
r1 = readRotation(mymotor1);
r2 = readRotation(mymotor2);
speed1 = (r1 - lastR1)/PERIOD;
speed2 = (r2 - lastR2)/PERIOD;
diff = speed1 - speed2;
mymotor1.Speed = mymotor1.Speed - int8(diff * P);
lastR1 = r1;
lastR2 = r2;
pause(PERIOD);
end
stop(mymotor1);
stop(mymotor2);
pause(0.5);
%Back------------------------------------------------------------
EXE_TIME = 3;
PERIOD = 0.1;
SPEED = 40;
P = 0.008;
mymotor1.Speed = SPEED;
mymotor2.Speed = SPEED;
resetRotation(mymotor1);
resetRotation(mymotor2);
start(mymotor1);
start(mymotor2);
t = timer('TimerFcn', 'stat=false;', 'StartDelay',EXE_TIME);
start(t);
stat = true;
lastR1 = 0;
lastR2 = 0;
while stat == true
r1 = readRotation(mymotor1);
r2 = readRotation(mymotor2);
speed1 = (r1 - lastR1)/PERIOD;
speed2 = (r2 - lastR2)/PERIOD;
diff = speed1 - speed2;
mymotor1.Speed = mymotor1.Speed - int8(diff * P);
lastR1 = r1;
lastR2 = r2;
pause(PERIOD);
end
stop(mymotor1);
stop(mymotor2);
clear
-----------------------------------------------------------------
And the code I use for reading with the magnetic sensor is the following:
b = Brick('ioType','usb');
tic;
while (toc <= 20) % Runs for 10 sec'
pause(0.5);
reading = b.inputReadSI(0,Device.Port1,Device.ColReflect);
disp(reading)
end
clear
-----------------------------------------------------------------
My problem is that I need to have
legoev3('USB');
and
Brick('ioType','usb');
working simultaneously as you can see in the two codes above. But I've yet to figure out how to achieve this.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu ROS Toolbox Supported Hardware finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by