-
Notifications
You must be signed in to change notification settings - Fork 184
Clean-up responseClass #491
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
|
@akeeste Just a quick clarification, but is the intent here to move more of the functions coded within the the WEC-Sim Library to external MATLAB functions that allow for better version control? Therefore, you haven't changed any of the code just where it is found? |
source/functions/orbital_velocity.m
Outdated
| @@ -1,5 +1,5 @@ | |||
| function [u,v,w,xa,ya,za] = orbital_velocity(disp,k,omega,waveAmp,theta,t,rampT, beta, h, g) | |||
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.
@akeeste I'm struggling to find where this function is used within WEC-Sim. Although, we need to calculate the flow velocity and acceleration to calculate the Morison Element forces, we do this in the ME block and do not reference a separate function. Trying to determine if this is perhaps an outdated function that could be removed?
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 just looked at the orbital velocity calculation in the ME block, it looks like an updated / rewritten version of the stand-alone function. It seems that it's likely outdated and not used
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.
Thanks, that was my initial conclusion after reviewing this file and noticing this is not called in the ME block. If no one else on the WEC-Sim team has a reason to keep this function then suggest removing before pushing to the dev branch.
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.
@nathanmtom I agree
|
@nathanmtom Yes the functions are moved to a single location so that they are easier to track. They are not changed functionally. I hadn't really looked at orbital_velocity, just noticed a typo and corrected it. I just searched the entire source directory but can't find anywhere that it is called |
source/objects/bodyClass.m
Outdated
| rotMat(3,3) = ax(3)*ax(3)*(1-cos(t)) + cos(t); | ||
| xn = x*rotMat; | ||
| end | ||
| % function xn = rotateXYZ(obj,x,ax,t) |
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.
Currently, these lines are commented out. After this pull request is approved and before pushing to the dev branch will these lines be removed from the bodyClass.m? This comment also goes for offsetXYZ.m file below.
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 I meant to remove those comments, I'll push that before merging with dev
source/objects/constraintClass.m
Outdated
| rotMat(3,3) = ax(3)*ax(3)*(1-cos(t)) + cos(t); | ||
| xn = x*rotMat; | ||
| end | ||
| % function xn = rotateXYZ(obj,x,ax,t) |
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.
Repeating comment, but suggest removing the commented lines before final push to the dev branch.
source/objects/mooringClass.m
Outdated
| rotMat(3,3) = ax(3)*ax(3)*(1-cos(t)) + cos(t); | ||
| xn = x*rotMat; | ||
| end | ||
| % function xn = rotateXYZ(obj,x,ax,t) |
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.
Repeat comment, about removing commented sections before pushing to dev branch.
source/objects/ptoClass.m
Outdated
| rotMat(3,3) = ax(3)*ax(3)*(1-cos(t)) + cos(t); | ||
| xn = x*rotMat; | ||
| end | ||
| % function xn = rotateXYZ(obj,x,ax,t) |
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.
One more documentation of removing commented lines to clean up code.
|
@akeeste All of the changes |
| @@ -0,0 +1,22 @@ | |||
| function rotMat = eulXYZ2RotMat(phi, theta, psi) | |||
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 probably a broader point...but have we decided on a naming convention for functions?
My personal preference would be eulxyz_2_rotmat(), but I think I used eulXYZ2RotMat() originally in keeping with the rest of the code. But IIRC there were mixed conventions and we wanted to resolve that problem? Are we going for camel case function names?
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.
in fact, the orbital_velocity() function below has an underscore. I would prefer underscores for functions, camel case for variables. Let me know what you think 👍
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 agree the naming convention is a bit inconsistent, especially with variables. I think this is a broader cleanup item on the project board.
I think we have waited to address this so far because there were concerns about backwards compatibility if a lot of the class variables are renamed
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.
yeah that's a good point, it will take time to propagate the convention throughout the whole code. But perhaps this PR is a good moment to decide on a convention? (If we haven't already)
Once we decide on coding conventions, we can also include that in the developer documentation section @H0R5E
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.
@dav-og I was going to bring up the convention today, but ran out of time.
How about we leave these camel case for now? The rest of the functions in /source/functions are currently camel case. Though I agree, we should have a different convention for variables, functions, classes. Maybe the team can discuss during the working meeting.
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 love to see some kind of coding guidelines introduced. It would be great to see a Python style line length restriction, as some of the lines are way too long at the moment. Consistent naming style is great too - I'm not sure if you necessarily need to distinguish every type of variable, but consistency helps a lot.
I wouldn't recommend implementing this in a big bang style, however, as you won't be able to properly review such a huge change. This kind of thing is best implemented as other changes are being made, at least until there is very little left to modify.
I think someone should open an issue to discuss it. We might need a doodle poll to vote on the options!
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.
Another thing is you can get a handle on the "accepted" naming conventions from the MATLAB docs. E.g:
There isn't any clarity on how a variable should be named. Personally I prefer UPPERCASE GLOBALS, for instance.
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.
@dav-og and @akeeste we decided on camel case for WEC-Sim a long time ago (many years ago), and I think we should stick with it. Yes, we do have functions/variables that did not follow this naming convention, and we should try to clean them up this year as we we come across them. This is the general cleanup on the project board @akeeste referred do.
|
@nathanmtom I just pushed a commit to cleanup the commented functions. The simulink blocks that I removed the functions from are:
In each case, the function is changed at the lowest level in the imbedded matlab function of each block. |
…into cleanup_respClass
I think the quaternion2EulXYZ.m file you've created should be called in Hydrodynamic Body/Structure/Motion Sensor as well? Also in the description of that function: I don't think its a list of quaternions? Just one quaternion |
|
@dav-og I'll update the descriptions for the quarternions. There's not really a change here, as I didn't end up making it an external function. I can make it an external function, so that git can track a text file. Before we do that across the library though, I'm curious to know if there is a speed difference in how simulink calls functions (interpreted matlab function vs embedded matlab function vs calculated in simulink, etc). |
|
@akeeste I'm not sure about the speed difference, but I'm inclined to move to do an external function just so that we can make our jobs easier on SCM. I'm willing to take the hit on speed, assuming it's not a huge difference. If you're curious you could compare the time :) |
|
@dav-og @kmruehl My solution was to keep an embedded matlab function (untracked), but only use it point to an external matlab function that can be tracked, i.e.: I'm curious to see Hunter's solution in the PR that he will post. Hopefully that will give us another solution, or fix the tracking problem entirely as is. |
|
hey @akeeste
the updated description states:
I think its 'Euler/Tait-Bryan angles; x-y-z extrinsic convention' |
|
@dav-og |
This PR cleans up the eulXYZ2RotMat and rotMatXYZ2Eul functions appended on to the responseClass. New functions are created in one location that can be called by the classes and Simulink.
Similarly, rotateXYZ and offsetXYZ functions are created so they can be tracked in a single location. The old methods are removed from the classes and simulink, and changed to point to the scripts in the function directory.