Code covered by the BSD License  

Highlights from
Data-driven Control

4.7
4.7 | 12 ratings Rate this file 72 Downloads (last 30 days) File Size: 452 KB File ID: #42758 Version: 1.1

Data-driven Control

by

 

14 Aug 2013 (Updated )

Files used in webinar Data-driven Control conducted on 12 July 2012

| Watch this File

File Information
Description

Files used in webinar Data-driven Control: How to Design a Controller When a Plant Model is Not Available on 12 July 2012

Through this webinar and product demonstrations, you will learn how to design and implement a PID controller when a plant model is not available. Through a DC motor control example, you will learn how to:

- Apply input signals (voltage) to the motor and collect output (angular position) test data
- Identify and validate linear and nonlinear plant models using multiple data sets
- Design a linear controller based on the linear motor model and simulate its performance against the nonlinear model
- Implement and test the controller on a target hardware platform

Required Products Control System Toolbox
Simulink
Simulink Control Design
System Identification Toolbox
MATLAB
MATLAB release MATLAB 8.0 (R2012b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (44)
27 May 2015 kemo

kemo (view profile)

Hello Every one,
I have a problem in "EmbeddedOpenLoop" . When i try to run the model on target hardware it gives me this error

"Making simulation target "EmbeddedOpenLoop_sfun", ...

'EmbeddedOpenLoop_sfun.bat' is not recognized as an internal or external command,
operable program or batch file. " .

I am using R2013 ,

Comment only
01 Apr 2015 Sina

Sina (view profile)

Hi Pravallika.
I have a few problems,
1. I am using a Uno board with Simulink 2013.
I need to transmit encoder data from arduino to simulink to plot for the system identification. I used your models and changes them slightly to my need.
I then used a S-function builder block to run my arduino using input voltage.
At this point, I am reading an analog data from pin 1 and trying to transmit it to serial. There are two problems
The read data has delay. Also, after some time it is a constant value (I guess it reads 0 or 1 only) I have to rebuild my arduino model and try again to work.
Please advise.
Bests,
Sina

Thanks for your help!

31 Mar 2015 Sina

Sina (view profile)

 
18 Mar 2015 Steve

Steve (view profile)

Yes you can use the L298N but it will be better to use the sn75441one, it priovides more channel current.

I am not sure wrt potentiometer question.

Comment only
17 Mar 2015 Emad Mohiyeddini

I want to start doing this nice project but i need some help:
what type of motor driver should i use ? can i use Use a Arduino L298N Dual H-Bridge ?
and how or where do u place a potentiometer for 360 degree position feedback ?

09 Mar 2015 Steve

Steve (view profile)

Does anyone know why the second custom regressor is >0.7 and <-0.34. From what i think, is that from the plot of the z7(deadzone), the minimum voltage value is 0.7 that causes it to first increase in angle however for the maximum angle to decrease the minimum voltage was not -0.34 but -0.56 which occurred at time 38.9 i.e at time 38.9 the motor first experienced some decrease and at this time the voltage was -0.56V and not -0.34 V ?

Comment only
09 Mar 2015 Steve

Steve (view profile)

@fai zal i dont have any coding for the communication. The external mode is easy to implement on the mega. Just configure the settings under tools>prepare to run, ensure that external mode is selected. Also ensure that external mode is selected next to the duration. Then click build model, after click connect to target and then click the play button.

Comment only
28 Feb 2015 fai zal

@Steve my error in Expected = 1x4 Actual = 1x0 Block Closed Loop Interface/Serial Motor Interface/Serial Interface to Arduino is solve now,,,please HELP me can you attach you communication between arduino and matlab (coding in matlab and coding in arduino),,

Comment only
27 Feb 2015 fai zal

@Steve i get this error when trying to run on the hardware not simulation, thanks for that advice.

Comment only
27 Feb 2015 Steve

Steve (view profile)

@fai zal, you get this error when trying to run on the hardware or simulation? If it is hardware, i get the same when trying to use my UNO but i got it to work one time and from then on i use my mega and run the external mode program. I will look into your problem some more and see if I can get back to you.

Comment only
26 Feb 2015 fai zal

i can get very good graph in step response from this project but my timeout from this analysis will happen when this error appear Expected = 1x4 Actual = 1x0 Block Closed Loop Interface/Serial Motor Interface/Serial Interface to Arduino. when this error happen my analysis will stop immediately, please help me

Comment only
26 Feb 2015 fai zal

thanks @steve,,but why this error happen again error Expected = 1x4 Actual = 1x0 Block Closed Loop Interface/Serial Motor Interface/Serial Interface to Arduino

Comment only
26 Feb 2015 Steve

Steve (view profile)

This simulink file is for use for arduino running on external mode and it is for real time testing on hardware after you have created your controller etc before.

https://www.dropbox.com/s/akey9miogo9yn0i/Beta.slx?dl=0

I hope you all solve that error soon.

Comment only
25 Feb 2015 fai zal

@steve please attach that file that i could use to run in real time on the hardware using external mode,,,anyone can solve this error Expected = 1x4 Actual = 1x0 Block Closed Loop Interface/Serial Motor Interface/Serial Interface to Arduino (#84) ,,please

Comment only
23 Feb 2015 Steve

Steve (view profile)

@yonas and @fai . I got that error too. What I did that seemed to work was I downloaded the embeded program first to my arduino and then I run the host model. the order made a difference. If you have a Arduino Mega I can send you the files that you could use to run in real time on the hardware using external mode, instead of the files from the Real Time folder provided that runs on your UNO.

Comment only
22 Feb 2015 fai zal

@yonas, @Ahmed mahlawy please help me if you found the solution about that problem thanks

Comment only
17 Feb 2015 Steve

Steve (view profile)

Why did you choose those data sets : z7,z3 & z6 for use as the working data sets ?

i.e what is specific about those for use as the working data set as oppose to others ?

Comment only
03 Feb 2015 Ahmed mahlawy

@yonas habte do you found any answer to demoLibrary/Utilities/10-bit to Angle problem?please inform me if you found the solution.. thank you.

24 Jan 2015 yonas habte

Size mismatch for MATLAB expression 'int16'. Expected = 1x4 Actual = 1x0 Block Serial Motor Interface/Serial Interface to Arduino (#37) While executing: none

24 Jan 2015 yonas habte

error loading demoLibrary/Utilities/10-bit to Angle in the Host_serial_final_MATLAB/Serial Motor Interface pleas help what is the problem

23 Jan 2015 Steve

Steve (view profile)

@Jason In my opinion its not necessary, you can use a simple H-bridge like a LM293.

@Steve I got two motors working using external mode on the mega. I will send you the simulink model.

Comment only
22 Jan 2015 Jason

Jason (view profile)

What is the IC board the arduino is connected to? Is it off the shelf? can I buy one? Is it necessary?
thanks
Jason

Comment only
17 Jan 2015 Steve Ramdass

Hello, by chance was anyone able to get two motors working with this model ? I am having some difficulty getting 2 to work on my Mega :(
Any direction or help will greatly be appreciated :)

@Isaiah, yea you should set back to zero but its not entirely necessary because we just want the response (pattern).
Yea you make the iddata set right after you have simulated each voltage command.

Comment only
29 Dec 2014 Steve

Steve (view profile)

Hi all, Its me again. I just have a few small questions.

In the data acquisition category, when we send the test voltage signals, sometimes the resulting angle is not zero set initially so the angle will sometimes start from say 100 and drive to some angle dependent on the voltage level sent. Should i set the angle of the servo's horn to zero every time i send a new voltage signal ?

Also,
When creating the iddata sets, i saw the example you did on how to make z4. Do you make the iddata set right after you simulated "one" voltage command or is it done after you have sent all the voltage commands and received the corresponding angles ? In addition, the process to make another iddata is simply just the same as you did with z4 just using a different z(num) ?

Comment only
09 Dec 2014 Steve

Steve (view profile)

@Pravallika I tried running mex -setup but i got back the same error when i tried to build. This is what i did

>mex -setup

Please verify your choices:

Compiler: Microsoft Visual C++ 2012
Location: C:\Program Files (x86)\Microsoft Visual Studio 11.0

Are these correct [y]/n? y

***************************************************************************
Warning: MEX-files generated using Microsoft Visual C++ 2012 require
that Microsoft Visual Studio 2012 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************


Trying to update options file: C:\Users\Isaiah\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat
From template: C:\PROGRA~1\MATLAB\R2013a\bin\win64\mexopts\msvc110opts.bat

Done . . .

Comment only
09 Dec 2014 Pravallika

Thanks Steve!

@Eric, Isaiah: Like Steve mentioned, running mex -setup to choose a compiler should help.

Also, you can get the real time pacer block from here:
http://www.mathworks.com/matlabcentral/fileexchange/29107-real-time-pacer-for-simulink/

Comment only
09 Dec 2014 Steve Ramdass

Hey Eric, you should try running "mex -setup" and select a C Compiler. @Isaiah De Freitas, you should run mex -setup too in matlab command window. It will ask you a series of questions there for selection of a C-compiler. Hope you all get through. Cheers....

Excellent Tutorial

09 Dec 2014 Eric Coleman

Hi, Excellent Tutorial. Unfortunately I can't get it to work for me. I am using 2013a. When i try to build the EmbededOpenLoop i get the following error >

"EmbeddedOpenLoop_sfun", ...

'EmbeddedOpenLoop_sfun.bat' is not recognized as an internal or external command,
operable program or batch file."

Also, when I try to build the Host_serial_final_Matlab i get the following error

"Level-2 MATLAB S-function 'msfun_realtime_pacer' does not exist."

Also i should note that I changed the file format from .mdl to .slx because it was recommended .

08 Dec 2014 Steve

Steve (view profile)

For both the "Open Loop" and "Host_serial_final_MATLAB" simulink systems after i set up the uno under the tools option and click run or build, I get the following errors "Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks.
Use 'mex -setup' to select a supported C-compiler" reported by Simulink and "Model error" reported by simulink. I am using 2012b.
*********************************************
By the way, aid anyone get it to work on 2014a ?

Comment only
05 Dec 2014 saif malik

@pravallika Thankyou so much pravallika.. Appreciate it!

Comment only
05 Dec 2014 Steve

Steve (view profile)

no problem, and thanks on behalf of saif.

Comment only
01 Dec 2014 Steve

Steve (view profile)

 
01 Dec 2014 Pravallika

@Isaiah: Thanks for explaining the connections! You should be able to follow any of the instructions that show up on google search to change the servo motor to continuous rotation as well.

@Ariful, Saif: To address the error -
1) Right click on the block it in the error: 'Host_serial_final_MATLAB/Serial Motor Interface'.
2) Click on Properties.
3) Go to the 'Callbacks' tab.
4) Click on 'StartFcn' in the list on the left pane.
5) Edit the commands in the pane on the right to reflect your COM port settings.

Comment only
28 Nov 2014 Steve

Steve (view profile)

I hope both of you all receive a solution soon. Correct me if I am wrong but I think the connections are like:
First off remove the internal circuitry of the RC servo leaving only the wires connected to the DC motor and the wires coming from the pot. Connect the DC motor wires to the respective (one for forward and one lead for backward) PWM output pins ( i think in this case we used pins 10 and 11) of your motor shield/driver. Connect the wiper lead from the pot to an analog input pin ( in this case i think it is pin 0). Keep in mind also that we have to use an external power source for the motor driver.

Comment only
28 Nov 2014 saif malik

@ariful
Hi! I have the same error..I am using matlab 2013a. If you somehow resolve it do let me know. Also plz tell me how have you physically connected the hardware as I cannot understand the connections in the pdf paper.
Plz reply asap..

Comment only
26 Nov 2014 Ariful

Ariful (view profile)

Hi Thanks for this webniar. when i tried to work with this i am getting the following error fro the host serial model. i have successfully downloaded the model on arduino uno and my port is 6 for uno. please help me eliminate the error.
thanks again

Error evaluating 'StartFcn' callback of SubSystem block 'Host_serial_final_MATLAB/Serial Motor Interface'.

Open failed: Port: COM4 is not available. Available ports: COM3, COM6.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.

Comment only
13 Nov 2014 Pravallika

@Isaiah:
If I was to physically move the horn(arm) of the motor after a desired input angle was set, will the horn retract back to its desired angle?

- Yes. In fact, you might find it difficult to move the motor position since the controller will be acting against you.

Is this a hobby servo motor modified by removing the internal circuitry?

- Yes, we modified it for continuous rotation.

Comment only
11 Nov 2014 Steve

Steve (view profile)

This is excellent work.
I have just two questions (anyone can answer) :

If I was to physically move the horn(arm) of the motor after a desired input angle was set, will the horn retract back to its desired angle?
Also,
Is this a hobby servo motor modified by removing the internal circuitry?

Comment only
03 Mar 2014 miguel

miguel (view profile)

10-bit to Angle ?

Comment only
27 Feb 2014 Pravallika

@Mohamed: If you have confirmed that your model simulates slower than real-time, you can use other techniques to speed up your simulation such as Accelerator mode. You can then use one of the Pacer blocks on MATLAB Central to slow your simulation down to soft real-time. If this does not work for you, please feel free to contact our technical support who might be able to recommend an appropriate suggestion once they have more details pertaining to your application.

@phil: Thank you for your feedback. You are right, we could not use External mode on Arduino Uno as it is unsupported due to memory limitations of the board. Due to this, we created a host model that runs soft real-time on the PC that communicates with the application on the board. However, for Arduino Mega 2560 external mode is supported in MATLAB R2012b. You should be able to forgo the host model and collect your data via external mode.

Comment only
19 Feb 2014 Mohamed

Great Work ...
but, I need to decrease the sampling time to 0.0004 in order to identify a fast motor.
How can I do this without losing the real time.

Comment only
11 Feb 2014 Mohamed  
25 Dec 2013 phil

phil (view profile)

This is a great webinar. It might be worth mentioning that you can not use this method of data collection in External mode. When using the arduino mega for example. You can not log signal data in external mode. Rather you should connect a regular scope and save its data to the workspace. (this is with R2012b)

16 Sep 2013 Madhu

Madhu (view profile)

 
Updates
14 Aug 2013 1.1

Added updated zip file with copyright info.

Contact us