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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/CCA/test.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           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 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #ifdef _MSC_VER
    00015 #pragma warning( disable : 4786 )
    00016 #endif
    00017
    00018 #include <iostream>
    00019 #include <cstdio>
    00020 #include <cassert>
    00021 #include <string>
    00022 #include <vector>
    00023 #include "CCAModel.h"
    00024 #include "HardCodedModels.h"
    00025
    00027
    00028 using namespace Mers::Models::CCA;
    00029 using namespace std;
    00030
    00032
    00033 int createValveDriverModel()
    00034 {
    00035         CCAModel m("VDM");
    00036
    00037         createValveDriverModel(m);
    00038   return 0;
    00039 }
    00040
    00042
    00043 int createTechsat21PropulsionModel()
    00044 {
    00045         CCAModel m("TS21PM");
    00046
    00047         createSimpleTechsat21Model(m);
    00048   return 0;
    00049 }
    00050
    00052
    00058 int main() {
    00059         CCAValues               temp_values(true);
    00060         CCAClause               temp_c_CCAClause(CCAClause::CONJUNCTIVE);
    00061         CCAClause               temp_d_CCAClause(CCAClause::DISJUNCTIVE);
    00062         CCASentence     temp_constraint(CCASentence::CNF);
    00063
    00064         CCAModel my_model("Test Model");
    00065
    00066         // Domain
    00067         temp_values.insert_value(CCAValue("positive"));
    00068         temp_values.insert_value(CCAValue("zero"));
    00069         my_model.insert_domain("Flow", temp_values);
    00070         temp_values.makeEmpty();
    00071
    00072         // Domain
    00073         temp_values.insert_value(CCAValue("idle"));
    00074         temp_values.insert_value(CCAValue("close-cmd"));
    00075         temp_values.insert_value(CCAValue("open-cmd"));
    00076         my_model.insert_domain("Valve-CMD", temp_values);
    00077         temp_values.makeEmpty();
    00078
    00079         // Domain
    00080         temp_values.insert_value(CCAValue("stuck-closed"));
    00081         temp_values.insert_value(CCAValue("closed"));
    00082         temp_values.insert_value(CCAValue("open"));
    00083         my_model.insert_domain("Valve-State", temp_values);
    00084         temp_values.makeEmpty();
    00085
    00086         // Variables
    00087         my_model.insert_variable("NewValve.Outflow", CCAVariable::DEPENDENT, "Flow");
    00088         my_model.insert_variable("NewValve.Inflow", CCAVariable::DEPENDENT, "Flow");
    00089         my_model.insert_variable("NewValve.CMD", CCAVariable::CONTROL, "Valve-CMD");
    00090         my_model.insert_variable("NewValve.Mode", CCAVariable::STATE, "Valve-State");
    00091
    00092         // State Costraint
    00093         CCAAssignment   temp_assignment
    00094                 = my_model.get_assignment("NewValve.Outflow", "positive", CCAAssignment::NEGATIVE);
    00095         temp_d_CCAClause.insert_assignment(temp_assignment);
    00096         temp_assignment = my_model.get_assignment("NewValve.Inflow", "positive", CCAAssignment::POSITIVE);
    00097         temp_d_CCAClause.insert_assignment(temp_assignment);
    00098         temp_constraint.insert_clause(temp_d_CCAClause);
    00099         temp_d_CCAClause.clear();
    00100         temp_assignment = my_model.get_assignment("NewValve.Inflow", "positive", CCAAssignment::NEGATIVE);
    00101         temp_d_CCAClause.insert_assignment(temp_assignment);
    00102         temp_assignment = my_model.get_assignment("NewValve.Outflow", "positive", CCAAssignment::POSITIVE);
    00103         temp_d_CCAClause.insert_assignment(temp_assignment);
    00104         temp_constraint.insert_clause(temp_d_CCAClause);
    00105         temp_d_CCAClause.clear();
    00106         temp_assignment = my_model.get_assignment("NewValve.Outflow", "zero", CCAAssignment::NEGATIVE);
    00107         temp_d_CCAClause.insert_assignment(temp_assignment);
    00108         temp_assignment = my_model.get_assignment("NewValve.Inflow", "zero", CCAAssignment::POSITIVE);
    00109         temp_d_CCAClause.insert_assignment(temp_assignment);
    00110         temp_constraint.insert_clause(temp_d_CCAClause);
    00111         temp_d_CCAClause.clear();
    00112         temp_assignment = my_model.get_assignment("NewValve.Inflow", "zero", CCAAssignment::NEGATIVE);
    00113         temp_d_CCAClause.insert_assignment(temp_assignment);
    00114         temp_assignment = my_model.get_assignment("NewValve.Outflow", "zero", CCAAssignment::POSITIVE);
    00115         temp_d_CCAClause.insert_assignment(temp_assignment);
    00116         temp_constraint.insert_clause(temp_d_CCAClause);
    00117         temp_d_CCAClause.clear();
    00118         my_model.set_state_constraint("NewValve.Mode", "open", temp_constraint);
    00119         temp_constraint.clear();
    00120
    00121         // State Costraint
    00122         temp_assignment = my_model.get_assignment("NewValve.Inflow", "zero", CCAAssignment::POSITIVE);
    00123         temp_d_CCAClause.insert_assignment(temp_assignment);
    00124         temp_constraint.insert_clause(temp_d_CCAClause);
    00125         temp_d_CCAClause.clear();
    00126         temp_assignment = my_model.get_assignment("NewValve.Outflow", "zero", CCAAssignment::POSITIVE);
    00127         temp_d_CCAClause.insert_assignment(temp_assignment);
    00128         temp_constraint.insert_clause(temp_d_CCAClause);
    00129         temp_d_CCAClause.clear();
    00130         my_model.set_state_constraint("NewValve.Mode", "closed", temp_constraint);
    00131         temp_constraint.clear();
    00132
    00133         // State Costraint
    00134         temp_assignment = my_model.get_assignment("NewValve.Inflow", "zero", CCAAssignment::POSITIVE);
    00135         temp_d_CCAClause.insert_assignment(temp_assignment);
    00136         temp_constraint.insert_clause(temp_d_CCAClause);
    00137         temp_d_CCAClause.clear();
    00138         temp_assignment = my_model.get_assignment("NewValve.Outflow", "zero", CCAAssignment::POSITIVE);
    00139         temp_d_CCAClause.insert_assignment(temp_assignment);
    00140         temp_constraint.insert_clause(temp_d_CCAClause);
    00141         temp_d_CCAClause.clear();
    00142         my_model.set_state_constraint("NewValve.Mode", "stuck-closed", temp_constraint);
    00143         temp_constraint.clear();
    00144
    00145         // Transitions
    00146         temp_assignment = my_model.get_assignment("NewValve.CMD", "close-cmd", CCAAssignment::NEGATIVE);
    00147         temp_c_CCAClause.insert_assignment(temp_assignment);
    00148         my_model.insert_transition("NewValve.Mode", "open", "open", temp_c_CCAClause, 1);
    00149         temp_c_CCAClause.clear();
    00150         temp_assignment = my_model.get_assignment("NewValve.CMD", "close-cmd", CCAAssignment::POSITIVE);
    00151         temp_c_CCAClause.insert_assignment(temp_assignment);
    00152         my_model.insert_transition("NewValve.Mode", "open", "closed", temp_c_CCAClause, 1);
    00153         temp_c_CCAClause.clear();
    00154         temp_assignment = my_model.get_assignment("NewValve.CMD", "open-cmd", CCAAssignment::NEGATIVE);
    00155         temp_c_CCAClause.insert_assignment(temp_assignment);
    00156         my_model.insert_transition("NewValve.Mode", "closed", "closed", temp_c_CCAClause, 1);
    00157         temp_c_CCAClause.clear();
    00158         temp_assignment = my_model.get_assignment("NewValve.CMD", "open-cmd", CCAAssignment::POSITIVE);
    00159         temp_c_CCAClause.insert_assignment(temp_assignment);
    00160         my_model.insert_transition("NewValve.Mode", "closed", "open", temp_c_CCAClause, 1);
    00161         temp_c_CCAClause.clear();
    00162         my_model.insert_transition("NewValve.Mode", "stuck-closed", "stuck-closed", temp_c_CCAClause, 1);
    00163         temp_c_CCAClause.clear();
    00164
    00165         // Set state type
    00166         my_model.set_state_type("NewValve.Mode", "open", CCAState::NOMINAL);
    00167         my_model.set_state_type("NewValve.Mode", "closed", CCAState::NOMINAL);
    00168         my_model.set_state_type("NewValve.Mode", "stuck-closed", CCAState::FAILURE);
    00169
    00170         cout << my_model;
    00171
    00172         return 0;
    00173 }
    00174