plugins - modifying parameters during the mission sequence

Development of custom GMAT plugins

plugins - modifying parameters during the mission sequence

Postby marchand » Fri Jun 28, 2013 1:37 pm

I have an object I designed using the plugin framework with both parameters you set, when you first create the object, and calculated parameters you can get during the mission sequence, which are functions of the parameters defined when the object was first created. I used the IsParameterReadOnly to set the calculated parameters as read-only. Now, what I'd like to do, is be able to change the writable parameters inside the mission sequence, so the calculated parameters are updated internally and then I can "get" them again. Much in the same way as you would do with a Spacecraft object:

Code: Select all
Create Spacecraft mySC;
% define your spacecraft below

Create Variable myVar;

BeginMissionSequence

%Print the current x-coordinate of the spacecraft
ConsolePrint mySC.X;

% Define a variable that is the x-coordinate plus 1000.0 km
GMAT myVar  = mySC.X + 1000;

% Update the spacecraft's x-coordinate
mySC.X = myVar;

% Print the spacecraft's new x-coordinate
ConsolePrint mySC.X;


Which GmatBase methods would allow me to do this? Apparently it's not just the get/set parameter methods, because I tried that but it won't let me. I'm currently only able to set the parameters outside the mission sequence, and get the parameters back during the mission sequence, including the calculated parameters.


Any guidance would be greatly appreciated.
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm

Re: plugins - modifying parameters during the mission sequen

Postby jjkparker » Mon Jul 01, 2013 1:30 pm

Joel J. K. Parker
Flight dynamics engineer, GMAT team
http://gmatcentral.org
jjkparker
 
Posts: 617
Joined: Thu Jan 07, 2010 9:48 pm
Location: NASA Goddard Space Flight Center, Greenbelt, MD

Re: plugins - modifying parameters during the mission sequen

Postby marchand » Mon Jul 01, 2013 3:03 pm

Thanks, but I am possibly more confused now than I was before :^)

What I did in my plug-in is essentially what is described in the first half of the documents you sent me. That is, as you would for any object, making sure that all the class parameter getters and setters are appropriately defined for the corresponding parameter enumerations of that particular object. I can confirm that this is consistent with the first half of the steps outlined in the links you sent, but not with the second half.

In both examples, that second half alludes to modifications to the GMAT base code, under the src/base/parameter folder. I haven't had a need to access the Parameter class before, so I went to the architectural specification but, alas, that section (20.1) is completely empty, except for a short paragraph in the header of the section. That paragraph does seem to suggest that the parameter class is for calculated "objects" that are used in stopping conditions. That is not the case in my example, since my object is not related to a Spacecraft object at all.

I did a grep search through all the plugins available, and none create a new Parameter via the plug-in framework. So, the question then becomes, do I need the parameter class at all if I want to be able to access calculated parameters that are NOT related to the Spaceraft class? Basically, I want to be able to reset one parameter, inside the mission sequence, and then retrieve the updated calculated parameter that depended on that. These parameters are not time dependent, but changing them will change the coefficients that are used to evaluate an expression, which gives me the number I want to retrieve in the missions sequence.

Thoughts?
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm

Re: plugins - modifying parameters during the mission sequen

Postby marchand » Sat Aug 10, 2013 1:47 am

I forgot to post the resolution to this problem. Thanks to a lot of breakpoints and debugging, I was able to figure out the trick to making the parameters “writable” in the mission sequence.

The problem was in the Assignment class, which was called by the Validator, roughly line #1477 below. You can see it was trying to access this method on the object that owns the parameter. Since the method didn’t exist in my MyUserDefinedObject, the call to obj->IsParameterCommandModeSettable was just returning false, and with the ! sign in front it made it a true so it never finished the assignment. The curious thing is that it didn’t give me an error about the method not existing. It simply assigned a false when it couldn’t find it.

Code: Select all
         if (!obj->IsParameterCommandModeSettable(id))
         {
            settabilityError = "The field " +
                  toWrapper->GetDescription() + " cannot be set after "
                  "the Mission Sequence has started";
            omitLHSBecauseOfSettability = true;
            return false;
         }


The solution was to simply add the method to my object:

Code: Select all
bool MyUserDefinedObject::IsParameterCommandModeSettable(const Integer id) const
{
  // All parameters are command mode settable
   return true;
}


I also figured out that to allow assignment of one object to another inside the mission sequence, you have to set :

Code: Select all
blockCommandModeAssignment = false


in your object’s constructor. It’s one of the member variables of GmatBase, not documented in the architectural specification, and it defaults to true. After I added that, I am now able to do this from the script. This would allow me, for instance, to define two objects of type MyUserDefinedObject, call them obj1 and obj2, then do this from the mission sequence:

Code: Select all
GMAT obj2  = obj1


You can do this with Spacecraft objects already, but the option is set to default to false in general.

In regards to "Parameters", turns out these are not accessed at all when you “set” quantities in the BeginMissionSequence script. I verified this with the Spacecraft object by getting and setting eccentricity from the mission sequence. The only times I ever got the debugger to "step into" any of the parameter classes was when I was writing a ReportFile or outputting the parameter information to a subscriber. So, the Parameter route was not a viable solution for this particular issue.
marchand
 
Posts: 86
Joined: Tue Feb 21, 2012 2:42 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron