-
Notifications
You must be signed in to change notification settings - Fork 184
Controller Class and Library #967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
docs/user/advanced_features.rst
Outdated
| control methods) seeks to adjust | ||
| the natural frequency of the device to match the wave frequency. | ||
| .. figure:: /_static/images/impedance.PNG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtgrasb, the file extension needs to be lowercase to match the file name (i.e. .. figure:: /_static/images/impedance.png). It matters because Linux is case-sensitive and the docs are built on a Linux runner.
The other figure paths need to be changed similarly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@H0R5E
Thanks! Should be fixed now
|
Current plan is to keep this PR all together here in WEC-Sim to be reviewed. After reviewing, the example cases will be moved to the applications repo, but first we need to review the controller class and library. |
|
Hi @jtgrasb TODO Test: Someone with the bare minimum WEC-Sim required toolboxes test this and ensure functionality on everything except where toolboxes are missing (e.g., MPC). Overall, this is excellent and is major addition to WEC-Sim functionality and I can see it serving a great role in future WEC-Sim courses especially if they are integrated with a broader Wave Energy course. Detailed remarks to follow. I avoided making changes to the library/functions unless I was sure they were intended.
|
| FeRao = squeeze(floatHydro.hydro_coeffs.excitation.re(3,:))'*simu.rho*simu.gravity + squeeze(floatHydro.hydro_coeffs.excitation.im(3,:))'*simu.rho*simu.gravity*1j; | ||
| Fexc = ampSpect.*FeRao; | ||
|
|
||
| % Define the intrinsic mechanical impedance for the device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just the heave mechanical impedance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this code is currently just addressing heave motion for simplicity
|
|
||
| % Define the intrinsic mechanical impedance for the device | ||
| mass = simu.rho*floatHydro.properties.volume; | ||
| addedMass = squeeze(floatHydro.hydro_coeffs.added_mass.all(3,3,:))*simu.rho; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems hard coded to only be the vertical motion and for generalization would have expected it to be selectable; however, you have mentioned that we need coordinate transformations to get the the impedpence at a different location. The MPC WECCCOMP example does something similar by building the dynamic equation of motion about the rotational point. Because most of these examples are custom, I think putting these as examples in the applications case is better than inside of WEC-Sim Master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, currently it is hard-coded for just heave, but I could work on it being selectable DOF. See Kelley’s comment - the plan is to move the examples to the applications case after review. The reason it was put in WEC-Sim master to be reviewed is to make it function with the controllerClass and library - do you think these are useful in master or should they also be removed and integrated as part of the applications case?
|
|
||
| % Define the intrinsic mechanical impedance for the device | ||
| mass = simu.rho*floatHydro.properties.volume; | ||
| addedMass = squeeze(floatHydro.hydro_coeffs.added_mass.all(3,3,:))*simu.rho; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to my above comment, but if we are hard coding these then I think it needs to be an applications case. Also, is this impedance also solely for the float? I have not reviewed the .slx file yet, but if the spar is also allowed to move technically you need to include the coupling terms to generate the impedence describing the relative motion between two bodies. Correction, now that I see you are only using the RM3 float (single body) I understand; however, given how the RM3 is referred to as a two-body system I think this is confusing. If you wanted to use an existing example for a single body heave only case, the IEA OES Task 10 is a better option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I can work on switching the float out with IEA OES Task 10 sphere to be more clear.
| %% Run quadprog | ||
|
|
||
| if mpcStruct.MPCSetup.currentIteration > mpcStruct.modelPredictiveControl.Ho + mpcStruct.modelPredictiveControl.order % Only run mpcStruct after buffer is full, otherwise Fe predictions are not accurate | ||
| options = optimoptions('quadprog','Algorithm','interior-point-convex','Display','off', 'MaxIter', 600); % Can't set x0 w/ interior-point-convex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quadprog is part of the optimization toolbox and will not run with base MATLAB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this being moved to the applications case, the extra toolbox shouldn't be an issue from what I understand.
| the following equation and can be used to formulate optimal control | ||
| implementation: | ||
| .. math:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This equation is appropriate for a single oscillating body, but is not generalizable to a multiple body system. As such, I am still in favor of an example case as this class is not going to be fully generalizable to more complex WECs that we see users researching through issues.
|
Thanks for proposing this PR @jtgrasb, clearly there is a lot of work gone into getting this controller toolbox ready be be integrated into the WEC-Sim. My initial thought is that this is still better suited as a suite of WEC-Sim Application Cases as you already have the 5 controller cases for the RM3 (only float), but none of the other examples. Also the limitation for using the latching/declutching only in regular waves is a bit misleading since there are several papers out there that tie the hold/release times that are tied to the natural period of the device and this is going to perhaps result in quite a few questions from the user community which is going to have us dive deeper into control theory. By itself this would not be an issue, but considering where we draw the line for technical support I think needs to be considered. Also, since the toolbox suite you have generated is not generalizable to say the OSWEC or a two body attenuator design because of needing to shift the hydro coefficients away from the center of gravity to a hinge I think prevents this from being used for a wider range of concepts that WEC-Sim can support. Given we have kept WECCCOMP separate and it has an advanced MPC controller available, I think this would make for an excellent applications case, but this is not ready to be pulled into WEC-Sim master. At least not at this time, I think research from both labs have shown that sysID using WEC-Sim is an option to generate a linearized system of equations that you can then use to build a controller. This would allow us to generalize the controller better to represent the wide diversity of WECs we see. You are also using just the float of the RM3 model, when it was designed as a two-body system, and although it can still demonstrate the control approaches you have coded, in my opinion it will not be recognized by our users about the additional complexities such as including a second body or changing from say translational to rotational motion. Again I think you have done a lot of great work to get the PR to be mergeable with WEC-Sim Master, but I still think it is still better suited as an application case. More focused questions/comments are:
|
| wave, it is simple to see the difference between the natural frequency of | ||
| the device and the wave frequency. Complex conjugate control (and many other | ||
| control methods) seeks to adjust | ||
| the natural frequency of the device to match the wave frequency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a couple of comments about the challenges of adjusting the natural frequency of the device to match the wave frequency. In general, a resonant condition is not desire in any application, but this is not the case here, so it would be good to comment on this.
| in WEC-Sim. At a high level, the controller class interacts with the rest of | ||
| WEC-Sim as shown in the diagram below: | ||
|
|
||
| .. figure:: /_static/images/code_structure/PTOSimClass_diagram.png |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change figure to controller class diagram
|
@dforbush2 Thanks for the comments!
|
|
@nathanmtom Thanks for the comments!
|
523dfc5 to
8352bf4
Compare
|
Great work on this PR @jtgrasb. The examples are clear and the documentation is well written. I made a couple of comments on the documentation one of them regarding the challenges of adjusting the natural frequency of the device to match the wave frequency. It would be useful to add a couple of comments on this. |
62205fa to
4df3a5a
Compare
|
Thanks for all the comments and suggestions. I am working on incorporating your comments into a PR for the wec-sim applications case. I had some questions that I wanted to address first. @dforbush2 @nathanmtom @jleonqu Best, |
I have added a controller class to WEC-Sim to allow users to easily add control methods to their WEC models. I wanted to start a PR to get the review started/any feedback. This PR includes: