Beruflich Dokumente
Kultur Dokumente
Table of Contents
Creating a Matlab GUI for DC MOTORS ...................................................................................... 1 Testing our motors with MATLAB ................................................................................................ 2 Using the MATLAB GUI ............................................................................................................... 5 Conclusion ...................................................................................................................................... 6
1|Page
Download srv_gyro.pde. and upload it to Arduino board, which will allow us to communicate between the Arduino and MATLAB software. Make sure to down load the DC Motor folder and place it in a place where you can access it through Matlab. MATLAB should show it as follows:
2.
3.
4.
5.
You should get the following window once arduino.m file is run
2|Page
6.
Type the following line in the command line to make sure the Arduino and MATLAB are talking to each other. In my case my arduino is COM14 (make sure you know which COM your arduino is using). Make sure to replace COM14 with your corresponding COM#. EDU>> a=arduino('COM14')
7.
is set to: 0 is set to: 0 is set to: 0 is set to: 0 1 is set to: 2 is set to:
over 255 over 255 over 255 over 255 0 over 255 0 over 255
3|Page
DC Motors and Stepper Methods: motorSpeed motorRun stepperSpeed stepperStep Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Digital Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin Pin 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 is is is is is is is is is is is is is is is is is is currently currently currently currently currently currently currently currently currently currently currently currently currently currently currently currently currently currently UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED UNASSIGNED
8.
--- help for arduino/motorRun --a.motorRun(num,dir); runs a given DC motor. The first argument before the function name, a, is the arduino object. The second argument, num, is the number of the motor, which can go from 1 to 4 (the motor ports are numbered on the motor shield). The third argument, dir, should be a string that can be 'forward' (runs the motor forward) 'backward' (runs the motor backward) or 'release', (stops the motor). Note that since version 3.0, a +1 is interpreted as 'forward', a 0 is interpreted as 'release', and a -1 is interpreted as 'backward'. Returns Random results if motor shield is not connected. Examples: a.motorRun(1,'forward'); a.motorRun(3,'backward'); a.motorRun(2,-1); a.motorRun(1,'release'); % % % % runs motor 1 forward runs motor 3 backward runs motor 2 backward releases motor 1
9.
Add the following lines of code to make sure we have communication and that Matlab is working properly. EDU>> a.motorSpeed(1,100) EDU>> a.motorRun(1,'forward') EDU>> a.motorRun(1,'release') Line 1 will set the speed of our motor
4|Page
Line 2 will set our motor to go forward Line 3 will set tell our motor to stop
10.
Now we can see that our Arduino works with MATLAB, but it is not convenient to keep typing all the lines of code to control our motors. So we will now implement a MATLAB GUI to control our motors. By using the GUI we will be able to control both motors and see our motors work depending on our parameters.
In the dc_slider.m file make sure to change the COM port corresponding to your Arduino.
Make sure to also change the speed of the motors at which you want them to start when you press the forward push button.
Ideally you want to test your motors to see at what speed they begin running. In my case my motors begin to turn at speed 80.
3.
For the stepper motor make sure that these parameters make a smooth transition when executing the stepper moving right or left
% handles structure with handles and user data (see GUIDATA) handles.a.stepperSpeed(2,50) handles.a.stepperStep(2,'forward','interleave',10)
5|Page
4.
When you execute the dc_slider.m file you should get the following in the command line. Attempting connection ...... General Script detected ! Arduino successfully connected ! EDU>>
5.
Conclusion
As a result of the research I found that the GUI is very limited in parameters that we would want to achieve, such as making the two DC motors start at the same time. Using the GUI the motors have to be individually started and modified because we only have one mouse/touch pad to work with on a computer/laptop. I would suggest that for future development of the GUI, use RB11 because it has updates for GUI and better editing options.
6|Page