Sie sind auf Seite 1von 6

Creating a Matlab GUI for DC MOTORS

By Juan C. Cadena and Elizabeth Sandoval, EE444 Fall 2011

Table of Contents
Creating a Matlab GUI for DC MOTORS ...................................................................................... 1 Testing our motors with MATLAB ................................................................................................ 2 Using the MATLAB GUI ............................................................................................................... 5 Conclusion ...................................................................................................................................... 6

Creating a Matlab GUI for DC MOTORS


In this particular experiment we want to implement a MATLAB GUI to control our DC motors and stepper motor. As we increase (move up) the slider we will be able to see the speed of our DC motors increase. We will also be able to control the stepper motor with push buttons for left and right panning. The motions will allows us to simulate the control of the rover during the final mission. For this experiment we will need the following materials: Assembled Rover USB Cable MATLAB Software

1|Page

August 19, 2012

Testing our motors with MATLAB


1.

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.

Open MATLAB and run arduino.m file.

5.

You should get the following window once arduino.m file is run

2|Page

August 19, 2012

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.

The following should be seen


EDU>> a=arduino('COM14') Attempting connection ...... General Script detected ! Arduino successfully connected ! a = arduino object connected to COM14 port General Shield Server running on the arduino board Servo 1 is DETACHED Servo 2 is DETACHED The speed of motor number 1 The speed of motor number 2 The speed of motor number 3 The speed of motor number 4 The speed of stepper number The speed of stepper number

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

Servo Methods: servoStatus servoAttach servoDetach servoRead servoWrite

3|Page

August 19, 2012

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

Pin IO Methods: pinMode digitalRead digitalWrite analogRead analogWrite

8.

Click on motorRun for examples of coding into Matlab

--- 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

August 19, 2012

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.

Using the MATLAB GUI


Double click on the dc_slider.m file to open the m.file editor. This is where you will make the following changes.
1.

In the dc_slider.m file make sure to change the COM port corresponding to your Arduino.

In this case the Arduino is set up for COM14


2.

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

August 19, 2012

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.

If everything goes well then the following should appear

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

August 19, 2012

Das könnte Ihnen auch gefallen