OpenServo.com Forum Index OpenServo.com
Discussion of the OpenServo project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Matlab model

 
Post new topic   Reply to topic    OpenServo.com Forum Index -> Theory and Algorithms
View previous topic :: View next topic  
Author Message
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Mon Jun 26, 2006 6:03 am    Post subject: Matlab model Reply with quote

I finally got a sane matlab model going. Anyone want to play around with it? It implements the nonlinear dc-motor equations (including an attached weight and gear ratio) and a single Z-PID position controller loop. It can, of course, be improved by a lot, but you can already fool around with tuning.

There are 2 things that I'll implement now: get an estimate of the parameters of a real servo (so that the dc motor part behaves realistically), and implement the control strategy that is being used now in the openservo (so that the controller behaves the same).
After that I'll implement the more advanced controllers.

Cheers,
ZZZ
Back to top
View user's profile Send private message
P. Teodoro
Guest





PostPosted: Tue Dec 12, 2006 4:06 pm    Post subject: Matlab for identification Reply with quote

I'm a student of University of Lisbon doing his master in simulation of a Humanoid (Bioloid <http://www.robosavvy.com>). After getting the communications working between Matlab/Simulink and the microcontroller of the robot, I managed to get some responses of the servos (AX-12+).

I verified that the servos are open loop for speed. So I send a reference speed for the servos and read the actual position of the servos. Then I do a derivation of position to get the actual speed of the servos.

Here is an example of the response.



I was thinking use ARMAX for identification.
Can you give some advice? It would be much appreciated.
I?m looking forward to hear from you.

Regards,
Pedro
Back to top
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Tue Jan 09, 2007 7:14 am    Post subject: Reply with quote

Hi,

yes, the original openservo algorithm posted here is open loop for the speed. This is something I intend to change, as soon as I can get back to working on the openservo theory.

As for identification, an ARMAX is not a bad idea acctually, I've used it in the past. Could I impose on you to write a small text describing the theory behind the algorithm, so that I can include it in the Theory document?

Currently, I'm inclining towards a Least Squares approach for identification, one of The Complicated Ones: Recursive Least Squares with Variable Forgetting Factor. It's fast on the parameter changes, not complicated to implement on this architecure, and it fits the non-linear profile imo. Haven't gotten around to testing it on my openservo simulator though.

Did I mention that my simulator is working now? well, sort of, still got some wrinkles...

Cheers,
ZZZ

------------------------------------------
Zedd? Zedd is NOT dead, just temporarily mind-numb...
Back to top
View user's profile Send private message
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1030
Location: Manchester, UK

PostPosted: Tue Jan 09, 2007 6:25 pm    Post subject: Reply with quote

I can vaguely remember ARMAX but I don't think I can remember anything but the lecturer saying ""Polynomial representation of transfer function"". Sounds great though Wink

Now, this simulator... sounds interesting. Does it run in Matlab still, or did you take it to a different language?

Good to see you again Z


Barry
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Tue Jan 09, 2007 10:00 pm    Post subject: Reply with quote

Hi Barry,

no, not matlab anymore, got tired of waiting eons for the simulations to finish. I took it to C/C++, compiled under Borland C++ builder 6. I can get a realtime simulation this way, and you can play with the tuning all you want.

I still have a stupid bug that corrupts the graphics though, and causes the whole thing to crash.

Just as a preview: I wrote all the code in Ansi C, and made wrapper C++ classes for each thing. This means that the Ansi C code could be used as is on the AVR, and the classes can be used for simulation purposes, testing, and whatever else. I have absolutely NO idea what the memory requirements for the AVR will be though, but it shouldn't be that different from the current situation.

Hope to crash-fix this thing by next week.

Cheers,
ZZZ
Back to top
View user's profile Send private message
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Tue Jan 09, 2007 10:03 pm    Post subject: Reply with quote

oh, by Ansi C code I mean the object equations:
one set of funtions for a DPID controller, one for a DIPD, one for ZPID, one for a differential filter, one for a moving window filter, one for............

u get the picture Smile

Z.
Back to top
View user's profile Send private message
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Tue Jan 09, 2007 10:09 pm    Post subject: Reply with quote

lol and the simulator name is BOSS: Basic OpenServo Simulator

dont laugh! Wink

Z.
Back to top
View user's profile Send private message
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Tue Feb 06, 2007 8:15 pm    Post subject: Reply with quote

Just a small progress report on the BOSS:

got the equations working, got the gui sort of setup, and I finnally figured out what the problem is with the simulation loop. It turns out that windows has only ms accuracy on the software timers, unlike Lunux which has us accuracy.

So, what I thought were us were ms, and in counting time slices, I had a factor of 1000 messing me up.

Sigh, yet another reason not to develop under windows. Why do I bother??

In any case, considering that I have everything else sort of ready, I'll try to figure out how to fix this now.

Also, as a comment, I'm just implementing a single control loop for this first version, and not the whole control strategy I mention in my theory document. I'll do that on the next version, otherwise I'll never finish this thing...

Cheers,
ZZZ
Back to top
View user's profile Send private message
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1030
Location: Manchester, UK

PostPosted: Tue Feb 06, 2007 8:19 pm    Post subject: Reply with quote

I look forward to seeing this, Z!

I just had to get over the whole windows timer issue the recently, so I empathise completely.

Barry
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
SOI Sentinel



Joined: 30 Mar 2006
Posts: 44

PostPosted: Wed Feb 07, 2007 2:04 am    Post subject: Reply with quote

This is QUITE nice, I'll have to keep an eye on your work more.

Aside: I'm working on some modelling for work right now in Scilab. Have you ever looked at it? It's an OSS Matlab analogue. There are also some Matlab-Scilab converters included, too, so it may not be too much rework.
Back to top
View user's profile Send private message
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Wed Feb 07, 2007 10:46 pm    Post subject: Reply with quote

Well, I tried using matlab/simulink for this, but it's just waaayyy too slow. I'm simulating with time steps of 10us, so matlab takes its sweet time.

So I moved to C/C++. I developed a... well sort of an object tree for the math objects. you get controller objects (ZPID, DPID and so on), u get math model objects (servo model), filter objects, and so on.

The core objects are written in ANSI C, so they can be used directly in the AVR (I hope), and I wrote wrapper classes for use in the simulator. Only thing is, I wrote everything with doubles, at least for starters, cause I didnt want to have to worry about int arithmetic errors. After this has been tested a bit, I'll get the whole fixed point arithmetic thing into it.

I'm rewriting the entire simulation loop and calculation engine :'( all that I had before is useless now cause of windows. Oh well...

Also, this SHOULD be portable to Linux. I'm using CLX instead of VCL. But I dont have a linux system set up, so have no way of testing that.

gonna get rid of a bug in the handling of the shared memory of the graphs now... opengl ftw!!

ZZZ

--------------------------------------------
Zedd a la well done (hot here!!)
Back to top
View user's profile Send private message
ginge
Site Admin


Joined: 14 Jan 2006
Posts: 1030
Location: Manchester, UK

PostPosted: Wed Feb 07, 2007 10:51 pm    Post subject: Reply with quote

Hey Z, you should look at windows High Performance Counter. There are a few librarys for implementing style *nix clock accuracy. A quick Google found me this:-
http://search.cpan.org/~crenz/Win32-PerfCounter-0.02/PerfCounter.pm

Barry
_________________
http://www.headfuzz.co.uk/
http://www.robotfuzz.co.uk/
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Zeddicus



Joined: 21 May 2006
Posts: 109

PostPosted: Thu Feb 08, 2007 2:38 am    Post subject: Reply with quote

Thanks Barry, I had already looked at something similar, this looks interesting too.

The problem is not in reading the time accurately, but in getting the execution thread to sleep for an accurate time slice. All sleep or suspend calls for windows I have seen so far use ms accuracy. This sort of defeats the purpose of the high performance counter. If anyone out there knows of a way to get a thread to sleep with microsecond accuracy under windows, I could use the info!!!

An example:
Usually, when u want to execute a piece of code with a very specific frequency, u do something like this:

thread()
{
int period=1000000/frequency; //in us
int time1, time1, exectime;

while(go)
{
time1=readtime();

... execute code

time2=readtime();
exectime=time2-time1;
sleep(period-exectime);
}

}

under linux this works, because the sleep call takes a time value specified in microseconds.

hope that's understandable...

and I just figured out that the bug I mentioned earlier was not related to the handling of the shared memory. It seems that opengl is not implemented in the same way under linux as it is under windows. So, since I'm using CLX for linux compatibility, I can't use opengl, at least not without losing my sanity.
This means I have to draw the old fashioned way with a Canvas.
Sigh, windows 1 - linux 1.

Cheers,
Z
Back to top
View user's profile Send private message
servomek1



Joined: 22 May 2007
Posts: 2
Location: Boston, MA

PostPosted: Tue May 22, 2007 12:37 pm    Post subject: Re: Matlab model Reply with quote

I would very much like to play around with it--when you say "nonlinear", might that include coulomb friction?

Zeddicus wrote:
I finally got a sane matlab model going. Anyone want to play around with it? It implements the nonlinear dc-motor equations (including an attached weight and gear ratio) and a single Z-PID position controller loop. It can, of course, be improved by a lot, but you can already fool around with tuning.

There are 2 things that I'll implement now: get an estimate of the parameters of a real servo (so that the dc motor part behaves realistically), and implement the control strategy that is being used now in the openservo (so that the controller behaves the same).
After that I'll implement the more advanced controllers.

Cheers,
ZZZ
Back to top
View user's profile Send private message
Jiellen_27



Joined: 04 Nov 2010
Posts: 2

PostPosted: Thu Nov 04, 2010 6:27 am    Post subject: Reply with quote

Hello guys!

I am new in this site and I had no idea about this,can you please share me some info concerning this?
_________________
how to treat depression
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    OpenServo.com Forum Index -> Theory and Algorithms All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group