Skip to content

MyPluginGUI RTXI Functions

anselg edited this page Jan 23, 2014 · 4 revisions

Back

###RTXI Functions Jump to explanations for lines 48-52 and 54-79

 48 void  
 49 MyPluginGUI::execute(void)  
 50 {  
 51   return;  
 52 }  
 53   
 54 void  
 55 MyPluginGUI::update(DefaultGUIModel::update_flags_t flag)  
 56 {  
 57   switch (flag)  
 58     {  
 59   case INIT:  
 60     period = RT::System::getInstance()->getPeriod() * 1e-6; // ms  
 61     setParameter("GUI label", some_parameter);  
 62     setState("A State", some_state);  
 63     break;  
 64   case MODIFY:  
 65     some_parameter = getParameter("GUI label").toDouble();  
 66     break;  
 67   case UNPAUSE:  
 68     break;  
 69   case PAUSE:  
 70     break;  
 71   case PERIOD:  
 72     period = RT::System::getInstance()->getPeriod() * 1e-6; // ms  
 73     break;  
 74   default:  
 75     break;  
 76   
 77     }  
 78   
 79 }  

49: execute is used when MyPluginGUI needs to modify data within RTXI. The real-time system takes samples at a certain rate, and with each period it calls execute. This enables users to alter real-time data, and with the use of any INPUT and OUTPUT parameters in the vars array, they process and produce real-time signals. Functions that do this can be defined outside the execute function as long as they are called within it.

The execute function does not have any definition to begin with. When called, it immediately returns nothing back to whatever called it. The user is free to add functionality to it.

55-79: The update function is the mechanism by which the GUI buttons and any displayed values are modified. Whenever the system detects an event in the GUI, such as a value changing or a user pushing a button, it puts up a flag, coincidentally called flag, with a type associated with the change that occurred.

The update function contains a switch logical structure, which is a tool implemented within C and many other languages. Essentially, switch statements operate on some sort of flag whose value determines some sort of response. For each possible value of the flag, the user can specify some sort of response. The responses are made by using:

.
.
.
case SOME_VALUE:  
   ... desired response ...;  
   break;
case SOME_DIFFERENT_VALUE:
   ... desired response ...;  
   break;
.
.
.

For values of flag that are not handled by any case, the user can specify default behavior by using default: instead of case SOME_VALUE:.

The base code contains five defined cases: INIT, MODIFY, UNPAUSE, PAUSE, PERIOD, and EXIT.

  1. INIT is used when the program is initialized. It is optional, and is called only on line 40.
  2. MODIFY is used when a parameter in the GUI is changed by the user. In the base code, the GUI label parameter is displayed in the GUI as a label that says "GUI label" followed by a text box containing a floating point value that the user can modify by typing some new value in the text box. When a value is typed in and the user clicks the "Modify" button in the GUI, the MODIFY flag goes off, the update function is called, and the changed value is extracted, converted to std::double, and stored in some_parameter.
  3. UNPAUSE's function is, as one may easily guess, to indicate when the user hits the "Pause" button on the GUI to unpause the module.
  4. PAUSE means the user paused the module.
  5. PERIOD is used when the period of the real-time system is altered.
  6. EXIT causes the module to close.

Again, these flags are specific to RTXI.

Clone this wiki locally