- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Reconfiguration/Discrete/test.cpp

    00001 //=============================================================================
    00002 //
    00003 // Copyright (c) 2001           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Author:                      Seung H. Chung
    00010 // Organization:        Model-based Embedded and Robotic Systems Group
    00011 //                                      Massachusetts Institute of Technology
    00012 //
    00013 //
    00014 //
    00015 //=============================================================================
    00016
    00017 #ifdef _MSC_VER
    00018 #pragma warning( disable : 4786 )
    00019 #endif
    00020
    00021 #include <cassert>
    00022 #include <iostream>
    00023 #include <list>
    00024 #include <string>
    00025 #include <Mers/Solvers/Entailment/GI/GoalInterpreter.h>
    00026 #include <Mers/Utils/Containers/intList.h>
    00027 #include <Mers/Models/CCA/CCAModel.h>
    00028 #include <Mers/Models/CCA/Io/Mof/MOFReader.h>
    00029 #include "mrInterface.h"
    00030 #include "modeReconfiguration.h"
    00031 #include <Mers/Utils/Logging/logger.h>
    00032
    00033 using namespace std;
    00034 using namespace Mers::Models::CCA;
    00035 using namespace Mers::Solvers::Entailment::GI;
    00036 using namespace Mers::Models::CCA::Io::Mof;
    00037 using namespace Mers::Utils::Containers;
    00038 using namespace Mers::Models::Base;
    00039
    00040 CCAModel *      load_MOF(string MOF_file_name);
    00041 void    run_ModeReconfiguration_shell(mrInterface *mr_interface_p, CCAModel const *model_p);
    00042 void    print_ModeReconfiguration_shell_help(char ch);
    00043 void    print_variables(CCAVariables const * variable_p, char ch);
    00044 void    eat_space_or_tab(istream &stream);
    00045 void    clear_stream(istream &stream);
    00046 bool    read_pair_of_int(istream &stream, int &int_1, int &int_2);
    00047 void    valve_driver_and_valve_test();
    00048 void    printStringList(list<string> const & s);
    00049
    00050
    00051 int
    00052 main(int argc, char** argv)
    00053 {
    00054         argc--;
    00055         argv++;
    00056
    00057         CCAModel *model_p;
    00058         string MOF_file_name = "../../../Mers/Models/CCA/Io/Mof/switch.mof";
    00059
    00060         if (argc > 0)  // mof test file given...
    00061         {
    00062                 MOF_file_name = string(argv[0]);
    00063                 if( argc > 1 )
    00064                         log4cplus::PropertyConfigurator::doConfigure( argv[1] );
    00065         }
    00066         if( argc <= 1 )
    00067                 log4cplus::BasicConfigurator::doConfigure();
    00068         model_p = load_MOF(MOF_file_name);
    00069         cout << "Using " << MOF_file_name << " model..." << endl << endl;
    00070
    00071         GoalInterpreter * gi = new GoalInterpreter(model_p);
    00072         // This version turns on some debugging:
    00073         //GoalInterpreter * gi = new GoalInterpreter(model_p, 1);
    00074         modeReconfiguration *   mode_reconfiguration_p =
    00075                 new modeReconfiguration(*model_p, gi);
    00076         mode_reconfiguration_p->setDebug(false);
    00077         mrInterface                     *       mr_interface_p = new mrInterface(*mode_reconfiguration_p);
    00078
    00079         cout << endl << "Running demo..." << endl << endl;
    00080         run_ModeReconfiguration_shell(mr_interface_p, model_p);
    00081         cout << endl << MOF_file_name << "... demo done." << endl;
    00082
    00083         assert(mr_interface_p);
    00084         delete mr_interface_p;
    00085
    00086         assert(mode_reconfiguration_p);
    00087         delete mode_reconfiguration_p;
    00088
    00089         assert(model_p);
    00090         delete model_p;
    00091
    00092         exit(0);
    00093         return 0;
    00094 }
    00095
    00096
    00097 void
    00098 printStringList(list<string> const & s)
    00099 {
    00100         cout << "(";
    00101         list<string>::const_iterator sIter;
    00102         bool start = true;
    00103         for (sIter = s.begin(); sIter != s.end(); sIter++)
    00104         {
    00105                 if (start)
    00106                         start = false;
    00107                 else
    00108                         cout << ", ";
    00109                 cout << (*sIter);
    00110         }
    00111         cout << ")";
    00112 }
    00113
    00114
    00115 CCAModel *
    00116 load_MOF(string MOF_file_name)
    00117 {
    00118         CCAModel *model_p = new CCAModel();
    00119         if (MOF_file_name == "")
    00120         {
    00121                 delete model_p;
    00122                 cerr << endl << "No MOF file specified." << endl;
    00123                 exit(-1);
    00124         }
    00125         else if(MOFReader::loadMOF(MOF_file_name.c_str(), *model_p))
    00126         {
    00127                 delete model_p;
    00128                 cerr << endl << "Could not load " << MOF_file_name << "." << endl;
    00129                 exit(-1);
    00130         }
    00131         return model_p;
    00132 }
    00133
    00134
    00135 void
    00136 run_ModeReconfiguration_shell(mrInterface *mr_interface_p, CCAModel const *model_p)
    00137 {
    00138         intList        goals;
    00139         list<string>   goalsString;
    00140         int                var_index, val_index;
    00141         string         var_string, val_string;
    00142         char           char_p[300];
    00143         bool           quit_shell = false;
    00144
    00145         cout << endl << "REACTIVE PLANNER Shell: Enter 'h' for help.";
    00146         cout << endl << endl;
    00147
    00148         while (!quit_shell)
    00149         {
    00150                 cout << "> " << flush;
    00151                 eat_space_or_tab(cin);
    00152                 cin.get(char_p, 2);
    00153
    00154                 switch (char_p[0])
    00155                 {
    00156                         case 'c':
    00157                         case 'C':
    00158                                 // 'c' or 'C' corresponds to update current state.
    00159                                 if (read_pair_of_int(cin, var_index, val_index) == false)
    00160                                 {
    00161                                         cout << "Error: 'c' must be followed by pair(s) of integers." << endl;
    00162                                 }
    00163                                 else
    00164                                 {
    00165                                         mr_interface_p->update_current_state(var_index, val_index);
    00166                                 }
    00167                                 // check for further pairs...
    00168                                 while (read_pair_of_int(cin, var_index, val_index))
    00169                                 {
    00170                                         mr_interface_p->update_current_state(var_index, val_index);
    00171                                 }
    00172                                 break;
    00173                         case 'd':
    00174                         case 'D':
    00175                                 // 'd' or 'D' corresponds to toggling debug state
    00176                                 mr_interface_p->setDebug(!mr_interface_p->getDebug());
    00177                                 cout << "debug: " << (mr_interface_p->getDebug() ? "ON" : "OFF") << endl;
    00178                                 break;
    00179                         case 'g':
    00180                         case 'G':
    00181                                 // 'g' or 'G' corresponds to update goal state.
    00182                                 if (read_pair_of_int(cin, var_index, val_index) == false)
    00183                                 {
    00184                                         cout << "Error: 'g' must be followed by pair(s) of integers." << endl;
    00185                                 }
    00186                                 else
    00187                                 {
    00188                                         goals.push_back(var_index);
    00189                                         goals.push_back(val_index);
    00190                                 }
    00191                                 // check for further pairs...
    00192                                 while (read_pair_of_int(cin, var_index, val_index))
    00193                                 {
    00194                                         goals.push_back(var_index);
    00195                                         goals.push_back(val_index);
    00196                                 }
    00197                                 break;
    00198                         case 'h':
    00199                         case 'H':
    00200                                 // 'h' or 'H' or '?' corresponds to display help.
    00201                                 eat_space_or_tab(cin);
    00202                                 if (cin.peek() == '\n')
    00203                                 {
    00204                                         print_ModeReconfiguration_shell_help('h');
    00205                                 }
    00206                                 else
    00207                                 {
    00208                                         cin >> char_p;
    00209                                         if (char_p[0] != '\0')
    00210                                         {
    00211                                                 print_ModeReconfiguration_shell_help(char_p[0]);
    00212                                         }
    00213                                         else
    00214                                         {
    00215                                                 print_ModeReconfiguration_shell_help('h');
    00216                                         }
    00217                                 }
    00218                                 break;
    00219                         case 'n':
    00220                         case 'N':
    00221                                 // 'n' or 'N' corresponds to generate next commands.
    00222                                 cout << "Command: " << mr_interface_p->generate_commands(goals);
    00223                                 cout << endl;
    00224                                 goals.clear();
    00225                                 break;
    00226                         case 'q':
    00227                         case 'Q':
    00228                                 // 'q' or 'Q' corresponds to quit.
    00229                                 quit_shell = true;
    00230                                 break;
    00231                         case 'r':
    00232                         case 'R':
    00233                                 // 'r' or 'R' corresponds to reachable states.
    00234                                 cout << "Reachable states: " << mr_interface_p->generate_reachable_states();
    00235                                 cout << endl;
    00236                                 break;
    00237                         case 'v':
    00238                         case 'V':
    00239                                 // 'v' or 'V' corresponds to display all variables.
    00240                                 eat_space_or_tab(cin);
    00241                                 if (cin.peek() == '\n')
    00242                                 {
    00243                                         print_variables(model_p->variables_p(), 'a');
    00244                                         cout << endl;
    00245                                 }
    00246                                 else
    00247                                 {
    00248                                         cin >> char_p;
    00249                                         if (char_p[0] == '-' && char_p[1] != '\0')
    00250                                         {
    00251                                                 print_variables(model_p->variables_p(), char_p[1]);
    00252                                                 cout << endl;
    00253                                         }
    00254                                         else
    00255                                         {
    00256                                                 print_variables(model_p->variables_p(), 'a');
    00257                                                 cout << endl;
    00258                                         }
    00259                                 }
    00260                                 mr_interface_p->showVariables();
    00261                                 cout << endl;
    00262                                 break;
    00263                         case '\0':
    00264                         case '\n':
    00265                                 // a blank line - skip.
    00266                         case '/':
    00267
    00268                                 // assumed to be a comment
    00269                                 // could check the second line too...
    00270                                 break;
    00271                         default:
    00272                                 cout << "Error: '" << char_p << "' is not a recognized command." << endl;
    00273                                 break;
    00274                 }
    00275                 clear_stream(cin);
    00276         }
    00277 }
    00278
    00279
    00280 void
    00281 print_ModeReconfiguration_shell_help(char ch)
    00282 {
    00283         switch (ch)
    00284         {
    00285                 case 'c':
    00286                 case 'C':
    00287                         cout << "NAME" << endl;
    00288                         cout << "\tc - assert current state" << endl << endl;
    00289                         cout << "SYNOPSIS" << endl;
    00290                         cout << "\tc (VARIABLE_INDEX = VALUE_INDEX)" << endl << endl;
    00291                         cout << "DESCRIPTION" << endl;
    00292                         cout << "\tAssert state VARIABLE_INDEX = VALUE_INDEX as the current state."
    00293                                  << endl;
    00294                         break;
    00295                 case 'g':
    00296                 case 'G':
    00297                         cout << "NAME" << endl;
    00298                         cout << "\tg - assert goal state" << endl << endl;
    00299                         cout << "SYNOPSIS" << endl;
    00300                         cout << "\tg (VARIABLE_INDEX = VALUE_INDEX)" << endl << endl;
    00301                         cout << "DESCRIPTION" << endl;
    00302                         cout << "\tAsserts goal VARIABLE_INDEX = VALUE_INDEX as the goal state."
    00303                                  << endl;
    00304                         break;
    00305                 case 'h':
    00306                 case 'H':
    00307                         cout << "  c # # ... : assert current state(s)" << endl;
    00308                         cout << "  g # # ... : assert goal state(s)" << endl;
    00309                         cout << "  n         : generate next commands" << endl;
    00310                         cout << "  r         : display reachable states" << endl;
    00311                         cout << "  v         : display variables" << endl;
    00312                         cout << "  h         : displays this help" << endl;
    00313                         cout << "  d         : toggles debug mode" << endl;
    00314                         cout << "  q         : quit" << endl;
    00315                         cout << endl;
    00316                         break;
    00317                 case 'n':
    00318                 case 'N':
    00319                         cout << "NAME" << endl;
    00320                         cout << "\tn - generate next commands" << endl << endl;
    00321                         cout << "SYNOPSIS" << endl;
    00322                         cout << "\tn" << endl << endl;
    00323                         cout << "DESCRIPTION" << endl;
    00324                         cout << "\tGenerates next commands from current and goal states."
    00325                                  << endl;
    00326                         break;
    00327                 case 'q':
    00328                 case 'Q':
    00329                         cout << "NAME" << endl;
    00330                         cout << "\tq - quit Titan Interface test" << endl << endl;
    00331                         cout << "SYNOPSIS" << endl;
    00332                         cout << "\tq" << endl << endl;
    00333                         cout << "DESCRIPTION" << endl;
    00334                         cout << "\tQuits out of Titan Interface test."
    00335                                  << endl;
    00336                         break;
    00337                 case 'v':
    00338                 case 'V':
    00339                         cout << "NAME" << endl;
    00340                         cout << "\tv - displays the model variables and the corresponding indicies"
    00341                                  << endl << endl;
    00342                         cout << "SYNOPSIS" << endl;
    00343                         cout << "\tv [OPTION]" << endl << endl;
    00344                         cout << "DESCRIPTION" << endl;
    00345                         cout << "\tDisplays the model variables and the corresponding indicies" << endl;
    00346                         cout << "\tand domain." << endl << endl;
    00347                         cout << "\t-c\tdisplays only control variables." << endl;
    00348                         cout << "\t-d\tdisplays only dependent variables." << endl;
    00349                         cout << "\t-o\tdisplays only observable variables." << endl;
    00350                         cout << "\t-s\tdisplays only state variables." << endl;
    00351                         break;
    00352         }
    00353 }
    00354
    00355 void
    00356 print_variable(ostream &out, CCAVariable const &variable)
    00357 {
    00358         out << variable.getName() << '[' << variable.getUID()
    00359                 << "]   {";
    00360         BaseModelDomain const &domain = *(variable.getDomain());
    00361         for(unsigned int valUID = 0; valUID < domain.getLength(); valUID++){
    00362                 if(valUID != 0)
    00363                         out << ", ";
    00364                 BaseModelValue const * value = domain[valUID];
    00365                 out << value->getName() << '[' << value->getUID() << ']';
    00366         }
    00367         out << '}';
    00368 }
    00369
    00370
    00371 void
    00372 print_variables(CCAVariables const *variables_p, char ch)
    00373 {
    00374         CCAVariables::const_iterator c_it;
    00375
    00376         switch (ch)
    00377         {
    00378                 case 'c':
    00379                 case 'C':
    00380                         for (c_it = variables_p->begin(); c_it != variables_p->end(); c_it++){
    00381                                 if (c_it->getVariableType() == CCAVariable::CONTROL){
    00382                                         print_variable(cout, *c_it);
    00383                                         cout << endl;
    00384                                 }
    00385                         }
    00386                         break;
    00387                 case 'd':
    00388                 case 'D':
    00389                         for (c_it = variables_p->begin(); c_it != variables_p->end(); c_it++){
    00390                                 if (c_it->getVariableType() == CCAVariable::DEPENDENT){
    00391                                         print_variable(cout, *c_it);
    00392                                         cout << endl;
    00393                                 }
    00394                         }
    00395                         break;
    00396                 case 'o':
    00397                 case 'O':
    00398                         for (c_it = variables_p->begin(); c_it != variables_p->end(); c_it++){
    00399                                 if (c_it->getVariableType() == CCAVariable::OBSERVABLE){
    00400                                         print_variable(cout, *c_it);
    00401                                         cout << endl;
    00402                                 }
    00403                         }
    00404                         break;
    00405                 case 's':
    00406                 case 'S':
    00407                         for (c_it = variables_p->begin(); c_it != variables_p->end(); c_it++){
    00408                                 if (c_it->getVariableType() == CCAVariable::STATE){
    00409                                         print_variable(cout, *c_it);
    00410                                         cout << endl;
    00411                                 }
    00412                         }
    00413                         break;
    00414                 default:
    00415                         for (c_it = variables_p->begin(); c_it != variables_p->end(); c_it++){
    00416                                 print_variable(cout, *c_it);
    00417                                 cout << endl;
    00418                         }
    00419         }
    00420 }
    00421
    00422
    00423 void
    00424 eat_space_or_tab(istream &stream)
    00425 {
    00426         while(stream.peek() == ' ' || stream.peek() == '\t')
    00427         {
    00428                 stream.ignore(1);
    00429         }
    00430 }
    00431
    00432
    00433 void
    00434 clear_stream(istream &stream)
    00435 {
    00436         while(stream.peek() != '\n')
    00437         {
    00438                 stream.ignore(1);
    00439         }
    00440         stream.ignore(1);
    00441 }
    00442
    00443
    00444 bool
    00445 read_pair_of_int(istream &stream, int &int_1, int &int_2)
    00446 {
    00447         if (stream.peek() == '\n')
    00448         {
    00449                 return false;
    00450         }
    00451         while( (stream.peek() < '0' || stream.peek() > '9') && stream.peek() != '\n')
    00452         {
    00453                 stream.ignore(1);
    00454         }
    00455         if (stream.peek() == '\n')
    00456         {
    00457                 return false;
    00458         }
    00459         stream >> int_1;
    00460         while( (stream.peek() < '0' || stream.peek() > '9') && stream.peek() != '\n')
    00461         {
    00462                 stream.ignore(1);
    00463         }
    00464         if (stream.peek() == '\n')
    00465         {
    00466                 return false;
    00467         }
    00468         stream >> int_2;
    00469         return true;
    00470 }
    00471
    00472
    00473
    00474
    00475 /*int           runValveDriverDemo(mrInterface &my_mrInterface);
    00476 int             runTechsat21DemoOn(mrInterface &my_mrInterface);
    00477 int             runTechsat21MOFOn(mrInterface &my_mrInterface);
    00478 int             runTechsat21MOFOff(mrInterface &my_mrInterface);
    00479 void    loadTechsat21MOF(model & mdl);
    00480 int             testDriver(string modelName, model_init_func initFunc, demo_driver_func driverFunc);
    00481
    00482 //#define BYPASS_GI
    00483
    00484 int
    00485 main()
    00486 {
    00487         //testDriver("Valve Driver", createValveDriverModel, runValveDriverDemo);
    00488         //testDriver("Techsat-21", createSimpleTechsat21Model, runTechsat21Demo);
    00489         testDriver("Techsat21 MOF", loadTechsat21MOF, runTechsat21MOFOn);
    00490         //testDriver("Techsat21 MOF", loadTechsat21MOF, runTechsat21MOFOff);
    00491
    00492         exit(0);
    00493         return 0;
    00494 }
    00495
    00496 int
    00497 runValveDriverDemo(mrInterface &my_mrInterface)
    00498 {
    00499         intList goal_intList;
    00500         goal_intList.push_back(1);
    00501         goal_intList.push_back(1);
    00502         goal_intList.push_back(2);
    00503         goal_intList.push_back(1);
    00504         cout << "Initial goals:" << endl;
    00505         cout << "    " << goal_intList << endl << endl;
    00506
    00507         my_mrInterface.update_current_state(1,1);
    00508         my_mrInterface.update_current_state(2,0);
    00509         cout << "Commands generated by updates (1,2);(2,0):" << endl;
    00510         cout << "    " << my_mrInterface.generate_commands(goal_intList) << endl;
    00511         my_mrInterface.update_current_state(1,0);
    00512         my_mrInterface.update_current_state(2,0);
    00513         cout << "Commands generated by updates (1,0);(2,0):" << endl;
    00514         cout << "    " << my_mrInterface.generate_commands(goal_intList) << endl;
    00515         my_mrInterface.update_current_state(1,0);
    00516         my_mrInterface.update_current_state(2,1);
    00517         cout << "Commands generated by updates (1,0);(2,1):" << endl;
    00518         cout << "    " << my_mrInterface.generate_commands(goal_intList) << endl;
    00519         my_mrInterface.update_current_state(1,1);
    00520         my_mrInterface.update_current_state(2,1);
    00521         cout << "Commands generated by updates (1,1);(2,1):" << endl;
    00522         cout << "    " << my_mrInterface.generate_commands(goal_intList) << endl;
    00523         my_mrInterface.update_current_state(1,3);
    00524         my_mrInterface.update_current_state(2,1);
    00525         cout << "Commands generated by updates (1,3);(2,1):" << endl;
    00526         cout << "    " << my_mrInterface.generate_commands(goal_intList) << endl;
    00527
    00528         return 0;
    00529 }
    00530
    00531
    00532 int
    00533 runTechsat21DemoOn(mrInterface &my_mrInterface)
    00534 {
    00535         intList goal_intList;
    00537         // Goal State
    00538         //
    00539         // valve1       open
    00540         // valve2       open
    00541         // dciu         off
    00542         // thruster     on
    00544
    00545         goal_intList.push_back(26);
    00546         goal_intList.push_back(3);
    00547         goal_intList.push_back(0);
    00548         goal_intList.push_back(3);
    00549         goal_intList.push_back(17);
    00550         goal_intList.push_back(2);
    00551         goal_intList.push_back(12);
    00552         goal_intList.push_back(2);
    00553
    00554         my_mrInterface.update_current_state(26,4);
    00555         my_mrInterface.update_current_state(0,4);
    00556         my_mrInterface.update_current_state(17,2);
    00557         my_mrInterface.update_current_state(12,3);
    00558         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00559         my_mrInterface.update_current_state(26,4);
    00560         my_mrInterface.update_current_state(0,4);
    00561         my_mrInterface.update_current_state(17,1);
    00562         my_mrInterface.update_current_state(12,3);
    00563         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00564         my_mrInterface.update_current_state(26,4);
    00565         my_mrInterface.update_current_state(0,3);
    00566         my_mrInterface.update_current_state(17,1);
    00567         my_mrInterface.update_current_state(12,3);
    00568         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00569         my_mrInterface.update_current_state(26,3);
    00570         my_mrInterface.update_current_state(0,3);
    00571         my_mrInterface.update_current_state(17,1);
    00572         my_mrInterface.update_current_state(12,3);
    00573         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00574         my_mrInterface.update_current_state(26,3);
    00575         my_mrInterface.update_current_state(0,3);
    00576         my_mrInterface.update_current_state(17,1);
    00577         my_mrInterface.update_current_state(12,2);
    00578         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00579         my_mrInterface.update_current_state(26,3);
    00580         my_mrInterface.update_current_state(0,3);
    00581         my_mrInterface.update_current_state(17,2);
    00582         my_mrInterface.update_current_state(12,2);
    00583         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00584         my_mrInterface.update_current_state(26,3);
    00585         my_mrInterface.update_current_state(0,3);
    00586         my_mrInterface.update_current_state(17,1);
    00587         my_mrInterface.update_current_state(12,0);
    00588         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00589
    00590         return 0;
    00591 }
    00592
    00593 int
    00594 runTechsat21MOFOn(mrInterface &my_mrInterface)
    00595 {
    00596         intList goal_intList;
    00597
    00598         #ifdef BYPASS_GI
    00600         // Goal State
    00601         //
    00602         // valve1       open
    00603         // valve2       open
    00604         // dciu         off
    00605         // thruster     on
    00607
    00608         cout << "Bypassing GI..." << endl;
    00609
    00610         goal_intList.push_back(5);
    00611         goal_intList.push_back(3);
    00612         goal_intList.push_back(0);
    00613         goal_intList.push_back(3);
    00614         goal_intList.push_back(16);
    00615         goal_intList.push_back(2);
    00616         goal_intList.push_back(10);
    00617         goal_intList.push_back(2);
    00618         #else
    00620         // Goal State
    00621         //
    00622         // TS-Propulsion.thrust-out     true
    00624
    00625         cout << "Using GI..." << endl;
    00626
    00627         goal_intList.push_back(25);
    00628         goal_intList.push_back(0);
    00629         //goal_intList.push_back(5);
    00630         //goal_intList.push_back(4);
    00631         #endif
    00632
    00633         cout << endl << "Goal is: " << goal_intList << endl << endl;
    00634
    00636         // Start State
    00637         //
    00638         // valve1       closed
    00639         // valve2       closed
    00640         // dciu         off
    00641         // thruster     off
    00643
    00644         intList res;
    00645
    00646         my_mrInterface.update_current_state(5,4);
    00647         my_mrInterface.update_current_state(0,4);
    00648         my_mrInterface.update_current_state(16,2);
    00649         my_mrInterface.update_current_state(10,3);
    00650         cout << "Current state should be: [(5 = 4) (0 = 4) (16 = 2) (10 = 3)]" << endl;
    00651         cout << "Expecting (31, 0)" << endl;
    00652         res = my_mrInterface.generate_commands(goal_intList);
    00653         cout << "RP commands: " << res << endl;
    00654         cout << endl;
    00655
    00656         my_mrInterface.update_current_state(5,4);
    00657         my_mrInterface.update_current_state(0,4);
    00658         my_mrInterface.update_current_state(16,1);
    00659         my_mrInterface.update_current_state(10,3);
    00660         cout << "Current state should be: [(5 = 4) (0 = 4) (16 = 1) (10 = 3)]" << endl;
    00661         cout << "Expecting (29, 0), could also be (30, 0) or (28, 0)" << endl;
    00662         res = my_mrInterface.generate_commands(goal_intList);
    00663         cout << "RP commands: " << res << endl;
    00664         cout << endl;
    00665
    00666         my_mrInterface.update_current_state(5,4);
    00667         my_mrInterface.update_current_state(0,3);
    00668         my_mrInterface.update_current_state(16,1);
    00669         my_mrInterface.update_current_state(10,3);
    00670         cout << "Current state should be: [(5 = 4) (0 = 3) (16 = 1) (10 = 3)]" << endl;
    00671         cout << "Expecting (30, 0), could also be (28, 0)" << endl;
    00672         res = my_mrInterface.generate_commands(goal_intList);
    00673         cout << "RP commands: " << res << endl;
    00674         cout << endl;
    00675
    00676         my_mrInterface.update_current_state(5,3);
    00677         my_mrInterface.update_current_state(0,3);
    00678         my_mrInterface.update_current_state(16,1);
    00679         my_mrInterface.update_current_state(10,3);
    00680         cout << "Current state should be: [(5 = 3) (0 = 3) (16 = 1) (10 = 3)]" << endl;
    00681         cout << "Expecting (28, 0)" << endl;
    00682         res = my_mrInterface.generate_commands(goal_intList);
    00683         cout << "RP commands: " << res << endl;
    00684         cout << endl;
    00685
    00686         //my_mrInterface.setDebug(true);
    00687
    00688         my_mrInterface.update_current_state(5,3);
    00689         my_mrInterface.update_current_state(0,3);
    00690         my_mrInterface.update_current_state(16,1);
    00691         my_mrInterface.update_current_state(10,2);
    00692         cout << "Current state should be: [(5 = 3) (0 = 3) (16 = 1) (10 = 2)]" << endl;
    00693         cout << "Expecting (31, 1)" << endl;
    00694         res = my_mrInterface.generate_commands(goal_intList);
    00695         cout << "RP commands: " << res << endl;
    00696         cout << endl;
    00697
    00698         my_mrInterface.update_current_state(5,3);
    00699         my_mrInterface.update_current_state(0,3);
    00700         my_mrInterface.update_current_state(16,2);
    00701         my_mrInterface.update_current_state(10,2);
    00702         cout << "Current state should be: [(5 = 3) (0 = 3) (16 = 2) (10 = 2)]" << endl;
    00703         cout << "Expecting No Command" << endl;
    00704         res = my_mrInterface.generate_commands(goal_intList);
    00705         cout << "RP commands: " << res << endl;
    00706         cout << endl;
    00707
    00708         //my_mrInterface.setDebug(true);
    00709
    00710         my_mrInterface.update_current_state(5,3);
    00711         my_mrInterface.update_current_state(0,3);
    00712         my_mrInterface.update_current_state(16,1);
    00713         my_mrInterface.update_current_state(10,0);
    00714         cout << "Current state should be: [(5 = 3) (0 = 3) (16 = 1) (10 = 0)]" << endl;
    00715         cout << "Expecting unreachable" << endl;
    00716         res = my_mrInterface.generate_commands(goal_intList);
    00717         cout << "RP commands: " << res << endl;
    00718         cout << endl;
    00719
    00720         return 0;
    00721 }
    00722
    00723
    00724 int
    00725 runTechsat21MOFOff(mrInterface &my_mrInterface)
    00726 {
    00727         intList goal_intList;
    00728
    00729         #ifdef BYPASS_GI
    00731         // Goal State
    00732         //
    00733         // valve1       closed
    00734         // valve2       closed
    00735         // dciu         off
    00736         // thruster     off
    00738
    00739         goal_intList.push_back(5);
    00740         goal_intList.push_back(3);
    00741         goal_intList.push_back(0);
    00742         goal_intList.push_back(3);
    00743         goal_intList.push_back(16);
    00744         goal_intList.push_back(2);
    00745         goal_intList.push_back(10);
    00746         goal_intList.push_back(2);
    00747
    00748         #else
    00750         // Goal State
    00751         //
    00752         // TS-Propulsion.thrust-out     false
    00753         // TS-Propulsion.Pressure1-out low
    00755
    00756         goal_intList.push_back(25);
    00757         goal_intList.push_back(1);
    00758         goal_intList.push_back(27);
    00759         goal_intList.push_back(0);
    00760         #endif
    00761
    00763         // Start State
    00764         //
    00765         // valve1       open
    00766         // valve2       open
    00767         // dciu         off
    00768         // thruster     on
    00770
    00771         my_mrInterface.update_current_state(5,3);
    00772         my_mrInterface.update_current_state(0,3);
    00773         my_mrInterface.update_current_state(16,2);
    00774         my_mrInterface.update_current_state(10,2);
    00775         cout << "Expecting (31, 0)" << endl;
    00776         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00777         my_mrInterface.update_current_state(5,3);
    00778         my_mrInterface.update_current_state(0,3);
    00779         my_mrInterface.update_current_state(16,1);
    00780         my_mrInterface.update_current_state(10,2);
    00781         cout << "Expecting (28, 1), could also be (30, 1) or (29, 1)" << endl;
    00782         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00783         my_mrInterface.update_current_state(5,3);
    00784         my_mrInterface.update_current_state(0,3);
    00785         my_mrInterface.update_current_state(16,1);
    00786         my_mrInterface.update_current_state(10,3);
    00787         cout << "Expecting (30, 1), could also be (29, 1)" << endl;
    00788         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00789         my_mrInterface.update_current_state(5,4);
    00790         my_mrInterface.update_current_state(0,3);
    00791         my_mrInterface.update_current_state(16,1);
    00792         my_mrInterface.update_current_state(10,3);
    00793         cout << "Expecting (29, 1) or No Command" << endl;
    00794         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00795         my_mrInterface.update_current_state(5,4);
    00796         my_mrInterface.update_current_state(0,4);
    00797         my_mrInterface.update_current_state(16,1);
    00798         my_mrInterface.update_current_state(10,3);
    00799         cout << "Expecting (31, 1) or No Command" << endl;
    00800         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00801         my_mrInterface.update_current_state(5,4);
    00802         my_mrInterface.update_current_state(0,4);
    00803         my_mrInterface.update_current_state(16,2);
    00804         my_mrInterface.update_current_state(10,3);
    00805         cout << "Expecting No Command" << endl;
    00806         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00807         my_mrInterface.update_current_state(5,3);
    00808         my_mrInterface.update_current_state(0,3);
    00809         my_mrInterface.update_current_state(16,1);
    00810         my_mrInterface.update_current_state(10,0);
    00811         cout << "Expecting unreachable" << endl;
    00812         cout << my_mrInterface.generate_commands(goal_intList) << endl;
    00813
    00814         return 0;
    00815 }
    00816
    00817 void
    00818 loadTechsat21MOF(model & mdl)
    00819 {
    00820         if(MOFReader::loadMOF("../Model/MOFReader/propulsion.mof", mdl))
    00821         {
    00822                 exit(0);
    00823         }
    00824 }
    00825
    00826 typedef  void (model_init_func)(model &);
    00827 typedef  int  (demo_driver_func)(mrInterface &);
    00828
    00829 int
    00830 testDriver(string modelName, model_init_func initFunc, demo_driver_func driverFunc)
    00831 {
    00832         cout << "Testing " << modelName << " model..." << endl << endl;
    00833         model my_model(modelName);
    00834
    00835         initFunc(my_model);
    00836
    00837         modeReconfiguration my_modeReconfiguration(my_model);
    00838         //my_modeReconfiguration.setDebug(true);
    00839
    00840         mrInterface my_mrInterface(my_modeReconfiguration);
    00841         //my_mrInterface.setDebug(true);
    00844
    00845         cout << endl << "Running demo..." << endl << endl;
    00846         driverFunc(my_mrInterface);
    00847         cout << endl << modelName << " demo done." << endl;
    00848
    00849         return 0;
    00850 }
    00851 */
    00852