Robotsystem from Robot Group Leipzig: invertnchannelcontroller_gnu.hpp Source File

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

- File List
- File Members

# invertnchannelcontroller_gnu.hpp

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
    00003  *    martius@informatik.uni-leipzig.de                                    *
    00004  *    fhesse@informatik.uni-leipzig.de                                     *
    00005  *    der@informatik.uni-leipzig.de                                        *
    00006  *                                                                         *
    00007  *   ANY COMMERCIAL USE FORBIDDEN!                                         *
    00008  *                                                                         *
    00009  *   $Log: invertnchannelcontroller_gnu.hpp,v $
    00010  *   Revision 1.2  2005/10/27 15:02:06  fhesse
    00011  *   commercial use added
    00012  *                              *
    00013  *                                                                         *
    00014  ***************************************************************************/
    00015
    00016 AbstractController* getController_Gnu(int sensornumber, int motornumber,
    00017                                       int param1/*=0*/, double param2/*=0*/)
    00018 {
    00019   if(param1 < 2) param1 = 2;
    00020   return new InvertNChannelController_Gnu(sensornumber, param1);
    00021 }
    00022
    00023
    00024 InvertNChannelController_Gnu::InvertNChannelController_Gnu(int channels, int _buffersize)
    00025   :InvertNChannelController(channels, _buffersize),
    00026    plotlog("c.dat"),plotlog_x("x.dat"),plotlog_a("a.dat")
    00027 {
    00028
    00029   // add channels to gnuplot
    00030   for (int i=0; i<number_channels; i++){
    00031     plotlog.addChannel("h["+intToStr(i)+"]");
    00032     plotlog_x.addChannel("x["+intToStr(i)+"]");
    00033     plotlog_x.addChannel("y["+intToStr(i)+"]");
    00034     for (int j=0; j<number_channels; j++){
    00035       plotlog.addChannel("c["+intToStr(i)+"]["+intToStr(j)+"]");
    00036       plotlog_a.addChannel("a["+intToStr(i)+"]["+intToStr(j)+"]");
    00037     }
    00038   }
    00039   plotlog.command("set zeroaxis");
    00040   //plotlog.print_names_list();   //print nameslist in logfiles
    00041
    00042   plotlog_x.command("set zeroaxis");
    00043   //plotlog_x.print_names_list();
    00044
    00045   plotlog_a.command("set zeroaxis");
    00046   //plotlog_a.print_names_list();
    00047
    00048 };
    00049
    00050
    00051 /// plots internal values
    00052 void InvertNChannelController_Gnu::plot(const sensor* x, const motor* y){
    00053
    00054   // put value in buffer for plotting/writing
    00055   for (int i=0; i<number_channels; i++){
    00056     plotlog.putData("h["+intToStr(i)+"]",h.val(i,0));
    00057     plotlog_x.putData("x["+intToStr(i)+"]",x[i]);
    00058     plotlog_x.putData("y["+intToStr(i)+"]",y[i]);
    00059     for (int j=0; j<number_channels; j++){
    00060       plotlog.putData("c["+intToStr(i)+"]["+intToStr(j)+"]",C.val(i,j));
    00061       plotlog_a.putData("a["+intToStr(i)+"]["+intToStr(j)+"]",A.val(i,j));
    00062     }
    00063   }
    00064
    00065   t++;
    00066   if (t%100) return;  // plot/write only ervery 100th step
    00067
    00068   plotlog.plot();     // plot values in window
    00069   //plotlog.print();    // write values to logfile
    00070
    00071   plotlog_x.plot();
    00072   //plotlog_x.print();
    00073
    00074   plotlog_a.plot();
    00075   //plotlog_a.print();
    00076
    00077
    00078 };
    00079
    00080
    00081 /// performs one step (includes learning). Calulates motor commands from sensor inputs.
    00082 void InvertNChannelController_Gnu::step(const sensor* x_, int number_sensors,
    00083                                         motor* y_, int number_motors){
    00084   InvertNChannelController::step(x_, number_sensors, y_, number_motors);
    00085   t--;
    00086
    00087   plot(x_, y_);
    00088
    00089   t++;
    00090 };
    00091
    00092
    00093 /// performs one step without learning. Calulates motor commands from sensor inputs.
    00094 void InvertNChannelController_Gnu::stepNoLearning(const sensor* x_, int number_sensors,
    00095                                                   motor* y_, int number_motors){
    00096   InvertNChannelController::stepNoLearning(x_, number_sensors, y_, number_motors);
    00097   t--;
    00098   plot(x_, y_);
    00099   t++;
    00100 };
    00101
    00102
    00103 /// converts integer to string
    00104 std::string InvertNChannelController_Gnu::intToStr(int value)
    00105 {
    00106   std::ostringstream stream;
    00107   stream << value;
    00108   return stream.str();
    00109 };
    00110
    00111
    00112
    00113
    00114
    00115