Robotsystem from Robot Group Leipzig: controllertest.cpp Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# controllertest.cpp

Go to the documentation of this file.

    00001 #include<iostream>
    00002 #include<vector>
    00003 using namespace std;
    00004
    00005 #include "selforg/sinecontroller.h"
    00006 #include "selforg/invertnchannelcontroller.h"
    00007
    00008 int main(){
    00009   AbstractController* controller = new InvertNChannelController(5 );
    00010   controller->init(2,2);
    00011   controller->print(stderr,0);
    00012   return 0;
    00013   sensor sensors[3] = {0.1,-0.1,0.3};
    00014   motor motors[2];
    00015   // short circuit
    00016   for(int i=0; i < 5; i++){
    00017     sensors[0]=motors[0]+(double(rand())/RAND_MAX-0.5)*0.3;
    00018     sensors[1]=motors[1]+(double(rand())/RAND_MAX-0.5)*0.3;
    00019     sensors[2]=motors[1]+(double(rand())/RAND_MAX-0.5)*0.3;
    00020     controller->stepNoLearning(sensors, 2, motors, 2);
    00021   }
    00022   for(int i=0; i < 50000; i++){
    00023     sensors[0]=motors[0]+(double(rand())/RAND_MAX-0.5)*0.3;
    00024     sensors[1]=motors[1]+(double(rand())/RAND_MAX-0.5)*0.3;
    00025     sensors[2]=motors[1]+(double(rand())/RAND_MAX-0.5)*0.3;
    00026     //    cout << i << " S0: " << sensors[0] << ", " <<" S1: " << sensors[1];
    00027     list<Inspectable::iparamval> list_ = controller->getInternalParams();
    00028     vector<Inspectable::iparamval> v(list_.begin(), list_.end());
    00029 //     cout << i << " C00: " << list_[6] << ", " <<" C01: " << list_[7] << ", " <<
    00030 //       " C02: " << list_[8] << ", " <<" C10: " << list_[9] << ", " <<
    00031 //       " C11: " << list_[10] << ", " <<" C12: " << list_[11] << endl;
    00032     cout << i << " C00: " << v[4] << ", " <<" C01: " << v[5] << ", " <<
    00033       " C10: " << v[6] << ", " <<" C11: " << v[7]  << endl;
    00034
    00035     controller->step(sensors, 2, motors, 2);
    00036     cout << i << " Motor values: " << motors[0] << ", " << motors[1] << endl;
    00037   }
    00038   cout << "Motor values: " << motors[0] << ", " << motors[1] << endl;
    00039   return 0;
    00040 }
    00041
    00042