Prev: 'mvnrnd', I need some better understanding
Next: AWGN channel cascade with Rayleigh Channel in Simulink
From: Stig Haugstad on 25 Jan 2010 16:21 I have Lego NXT robot that I use the "RWTH - Mindstorms NXT Toolbox for MATLAB" to program. I want my vehicle to do something as easy as: 1. Drive towards wall and reduce speed as the distance gets smaller (Ultrasonic sensor). If the distance is less than 5, the program should stop running. 2. At the same time I want to run a while loop that "reads" how many times a button is pressed. If it is pressed 5 times the program should stop running. I want both of these to run at the same time in parallel. Is it possible to multi-thread in Matlab?
From: Gautam Vallabha on 26 Jan 2010 09:29
"Stig Haugstad" <stig.b.haugstad(a)gmail.com> wrote in message <hjl200$3mo$1(a)fred.mathworks.com>... > I have Lego NXT robot that I use the "RWTH - Mindstorms NXT Toolbox for MATLAB" to program. I want my vehicle to do something as easy as: > > 1. Drive towards wall and reduce speed as the distance gets smaller (Ultrasonic sensor). If the distance is less than 5, the program should stop running. > 2. At the same time I want to run a while loop that "reads" how many times a button is pressed. If it is pressed 5 times the program should stop running. > > I want both of these to run at the same time in parallel. It is not possible to multithread in MATLAB. I suggest creating a TIMER object that gets invoked every 100 msec, and the timer function can check the ultrasonic sensor as well as the button: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/timer.html http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f9-38055.html Alternatively, you could create two timer objects (one for each activity). Make sure to use ExecutionMode = 'fixedSpacing', BusyMode = 'drop', and be careful with your use of global/shared variables. Gautam |