Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
plotoption.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2011 LpzRobots development team *
3  * Georg Martius <georg dot martius at web dot de> *
4  * Frank Guettler <guettler at informatik dot uni-leipzig dot de *
5  * Frank Hesse <frank at nld dot ds dot mpg dot de> *
6  * Ralf Der <ralfder at mis dot mpg dot de> *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the *
20  * Free Software Foundation, Inc., *
21  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22  * *
23  ***************************************************************************/
24 
25 
26 #ifndef PLOTOPTION_H_
27 #define PLOTOPTION_H_
28 
29 #include <stdio.h>
30 #include <list>
31 #include <utility>
32 #include <string>
33 #include <vector>
34 
35 class Configurable;
36 class Inspectable;
37 
38 /** Output mode for agent.
39  */
40 enum PlotMode {
41  /// dummy (does nothing) is there for compatibility, might be removed later
43  /// write into file
45  /// plotting with guilogger (gnuplot)
47  /// plotting with guiscreen (gnuplot) in file logging mode
49  /// plotting with matrixVisualizer
51 
52  /// Acustic output of robotic values via external SoundMan
54 
55  /// gui for ECBRobots (see lpzrobots/ecbrobots), should be usable with OdeRobots, too
57 
58  /// dummy used for upper bound of plotmode type
60 };
61 
62 
63 /** This class contains options for the use of an external plot utility like guilogger or neuronviz
64  or just simply file output
65  */
66 class PlotOption {
67 public:
68  friend class WiredController;
69  friend class PlotOptionEngine;
70 
72  : pipe(0), interval(1), mode(NoPlot), parameter("")
73  {
74  mask.resize(256);
75  }
76 
77  /**
78  creates a new plotting object
79  @param mode output type @see PlotMode
80  @param interval every i-th step is plotted
81  @param parameter free parameters for plotting tool
82  &param filter filter for channels, @see setFilter(const std::string)
83 
84  Note: the argument whichSensor is removed. You can adjust this in the wirings now.
85  */
86  PlotOption( PlotMode mode, int interval = 1, std::string parameter=std::string(), std::string filter=std::string())
87  : pipe(0), interval(interval), mode(mode), parameter(parameter)
88  {
89  if(!filter.empty()){
90  setFilter(filter);
91  }
92  mask.resize(256);
93  }
94 
95  virtual ~PlotOption(){}
96 
97  virtual PlotMode getPlotOptionMode() const { return mode; }
98 
99  /// sets a filter to this plotoption: To export only selected channels
100  virtual void setFilter(const std::list<std::string>& accept, const std::list<std::string>& ignore);
101  /// sets a filter to this plotoption: syntax: +accept_substr -ignore_substr ...
102  virtual void setFilter(const std::string& filter);
103 
104  // flushes pipe (depending on mode)
105  virtual void flush(long step);
106 
107  /// nice predicate function for finding by mode
108  struct matchMode : public std::unary_function<const PlotOption&, bool> {
109  matchMode(PlotMode mode) : mode(mode) {}
110  int mode;
111  bool operator()(const PlotOption& m) { return (m.mode == mode); }
112 
113  };
114 
115  void addConfigurable(const Configurable*);
116  void setName(const std::string& name) { this->name = name;}
117  const std::string& getName() const { return name; }
118 
119  bool open(); ///< opens the connections to the plot tool
120  void close();///< closes the connections to the plot tool
121 
122  virtual bool useChannel(const std::string& name);
123 
124  virtual int printInspectables(const std::list<const Inspectable*>& inspectables, int cnt=0);
125 
126  virtual int printInspectableNames(const std::list<const Inspectable*>& inspectables, int cnt=0);
127 
128  virtual void printInspectableInfoLines( const std::list<const Inspectable*>& inspectables);
129 
130  /** prints a network description of the structure given by the inspectable object. (mostly unused now)
131  The network description syntax is as follow
132  \code
133  #N neural_net NETWORKNAME
134  #N layer LAYERNAME1 RANK?
135  #N neuron N0 BIASN0?
136  #N neuron N1 BIASN1?
137  #N layer LAYERNAME2 RANK?
138  #N neuron K0 BIASK0?
139  #N neuron K1 BIASK1?
140  ...
141  #N connection C00 N0 K0
142  #N connection C10 N0 K1
143  #N connection C01 N1 K0
144  #N connection C11 N1 K1
145  ...
146  #N nn_end
147  \endcode
148  All identifiers are alphanumeric without spaces.
149  */
150  void printNetworkDescription(const std::string& name, const Inspectable* inspectable);
151 
152  FILE* pipe;
153  long t;
154  int interval;
155  std::string name;
156 
157 private:
158  PlotMode mode;
159  std::string parameter; ///< additional parameter for external command
160  std::list<std::string> accept; ///< channels to accept (use) (empty means all)
161  std::list<std::string> ignore; ///< channels not ignore (empty means ignore non)
162  std::vector<bool> mask; ///< mask for accepting channels (calculated from accept and ignore)
163 };
164 
165 #endif /* PLOTOPTION_H_ */
PlotMode
Output mode for agent.
Definition: plotoption.h:40
plotting with matrixVisualizer
Definition: plotoption.h:50
write into file
Definition: plotoption.h:44
virtual void printInspectableInfoLines(const std::list< const Inspectable * > &inspectables)
Definition: plotoption.cpp:263
PlotOption(PlotMode mode, int interval=1, std::string parameter=std::string(), std::string filter=std::string())
creates a new plotting object
Definition: plotoption.h:86
int mode
Definition: plotoption.h:110
plotting with guiscreen (gnuplot) in file logging mode
Definition: plotoption.h:48
matchMode(PlotMode mode)
Definition: plotoption.h:109
Acustic output of robotic values via external SoundMan.
Definition: plotoption.h:53
Definition: plotoptionengine.h:38
dummy (does nothing) is there for compatibility, might be removed later
Definition: plotoption.h:42
The WiredController contains a controller and a wiring, which connects the controller with the robot...
Definition: wiredcontroller.h:58
int interval
Definition: plotoption.h:154
virtual PlotMode getPlotOptionMode() const
Definition: plotoption.h:97
PlotOption()
Definition: plotoption.h:71
std::string name
Definition: plotoption.h:155
virtual void flush(long step)
Definition: plotoption.cpp:139
virtual int printInspectableNames(const std::list< const Inspectable * > &inspectables, int cnt=0)
Definition: plotoption.cpp:209
virtual int printInspectables(const std::list< const Inspectable * > &inspectables, int cnt=0)
Definition: plotoption.cpp:235
This class contains options for the use of an external plot utility like guilogger or neuronviz or ju...
Definition: plotoption.h:66
void setName(const std::string &name)
Definition: plotoption.h:116
bool operator()(const PlotOption &m)
Definition: plotoption.h:111
virtual ~PlotOption()
Definition: plotoption.h:95
Interface for inspectable objects.
Definition: inspectable.h:48
Abstact class for configurable objects.
Definition: configurable.h:81
virtual bool useChannel(const std::string &name)
Definition: plotoption.cpp:193
dummy used for upper bound of plotmode type
Definition: plotoption.h:59
void close()
closes the connections to the plot tool
Definition: plotoption.cpp:94
const std::string & getName() const
Definition: plotoption.h:117
plotting with guilogger (gnuplot)
Definition: plotoption.h:46
void printNetworkDescription(const std::string &name, const Inspectable *inspectable)
prints a network description of the structure given by the inspectable object.
Definition: plotoption.cpp:277
FILE * pipe
Definition: plotoption.h:152
bool open()
opens the connections to the plot tool
Definition: plotoption.cpp:38
gui for ECBRobots (see lpzrobots/ecbrobots), should be usable with OdeRobots, too ...
Definition: plotoption.h:56
nice predicate function for finding by mode
Definition: plotoption.h:108
virtual void setFilter(const std::list< std::string > &accept, const std::list< std::string > &ignore)
sets a filter to this plotoption: To export only selected channels
long t
Definition: plotoption.h:153
void addConfigurable(const Configurable *)