1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* 
 * File:   XABSLBehaviorControl.h
 * Author: thomas
 *
 * Created on 9. Januar 2009, 21:31
 */

#ifndef _XABSLBehaviorControl_H
#define _XABSLBehaviorControl_H

#include <ModuleFramework/Module.h>
#include <ModuleFramework/ModuleManager.h>

// engine
#include <XabslEngine/XabslEngine.h>
#include <XabslEngine/XabslTools.h>

#include "Tools/Xabsl/XabslFileInputSource.h"
#include "Tools/Debug/DebugRequest.h"
#include <DebugCommunication/DebugCommandManager.h>
/*

#include "Representations/Modeling/BodyState.h"
#include "Representations/Infrastructure/CameraSettings.h"

#include "PlatformInterface/Platform.h"
*/

#include "Representations/Modeling/BehaviorStateComplete.h"
#include "Representations/Modeling/BehaviorStateSparse.h"


// symbols
#include "Symbols/BallSymbols.h"
#include "Symbols/GameSymbols.h"
#include "Symbols/MotionSymbols.h"
#include "Symbols/TeamSymbols.h"
#include "Symbols/SensorSymbols.h"
#include "Symbols/MathSymbols.h"
#include "Symbols/LedSymbols.h"
#include "Symbols/SelflocSymbols.h"
#include "Symbols/OdometrySymbols.h"
#include "Symbols/FieldSymbols.h"
#include "Symbols/StrategySymbols.h"
#include "Symbols/SoundSymbols.h"
#include "Symbols/PathSymbols.h"
#include "Symbols/RemoteSymbols.h"


// ErrorHandler
class MyErrorHandler : public xabsl::ErrorHandler
{
public:

  MyErrorHandler(std::ostream& out);
  void printError(const char* txt);

  void printMessage(const char* txt);

  virtual ~MyErrorHandler();

private:
  std::ostream& out;
};

//////////////////// BEGIN MODULE INTERFACE DECLARATION ////////////////////


BEGIN_DECLARE_MODULE(XABSLBehaviorControl)
  REQUIRE(FrameInfo)
  REQUIRE(SelfLocGoalModel)
  REQUIRE(BallModel)
  REQUIRE(PlayerInfo)
  REQUIRE(MotionStatus)
  REQUIRE(FieldInfo)
  REQUIRE(RobotPose)
  REQUIRE(CompassDirection)
  REQUIRE(MotionRequest)

  PROVIDE(BehaviorStateSparse)
  PROVIDE(BehaviorStateComplete)
  PROVIDE(DebugRequest)
  PROVIDE(DebugDrawings)
  PROVIDE(StopwatchManager)
  PROVIDE(DebugCommandManager)
END_DECLARE_MODULE(XABSLBehaviorControl)
//////////////////// END MODULE INTERFACE DECLARATION //////////////////////

class XABSLBehaviorControl : 
  private XABSLBehaviorControlBase, 
  private ModuleManager, 
  public DebugCommandExecutor
{
public:
  XABSLBehaviorControl();
  virtual ~XABSLBehaviorControl();

  virtual void execute();

  void loadBehaviorFromFile(std::string file, std::string agent);

  virtual void executeDebugCommand(
    const std::string& command, 
    const std::map<std::string,std::string>& arguments, 
    std::ostream &outstream);

private:
  /** Register all needed symbols */
  void registerXABSLSymbols();

  /** update symbols */
  void updateXABSLSymbols();

  /** udpate output symbols */
  void updateOutputSymbols();

  /** some debug drawings */
  void draw();

  xabsl::Engine* theEngine;
  MyErrorHandler theErrorHandler;
  std::stringstream error_stream;

  // TODO: remove this member
  std::string agentName;

  /** time passed into the xabsl engine */
  unsigned int xabslTime;

  // needed for serialization
  std::vector<double> inputDecimalBuffer;
  std::vector<bool> inputBooleanBuffer;
  std::vector<int> inputEnumBuffer;
  std::vector<double> outputDecimalBuffer;
  std::vector<bool> outputBooleanBuffer;
  std::vector<int> outputEnumBuffer;

  void fillActiveOptionsSparse(naothmessages::BehaviorStateSparse &status);
  void fillActionSparse(const xabsl::Action* source, naothmessages::XABSLActionSparse* dest);
  void fillRegisteredBehavior(naothmessages::BehaviorStateComplete &status);
  void fillRegisteredSymbolsSparse(naothmessages::BehaviorStateSparse &status);
  void fillRegisteredSymbolsSparserer(naothmessages::BehaviorStateSparse &status);

  //symbols
  ModuleCreator<BallSymbols>* theBallSymbols;
  ModuleCreator<GameSymbols>* theGameSymbols;
  ModuleCreator<MotionSymbols>* theMotionSymbols;
  ModuleCreator<TeamSymbols>* theTeamSymbols;
  ModuleCreator<SensorSymbols>* theSensorSymbols;
  ModuleCreator<MathSymbols>* theMathSymbols;
  ModuleCreator<LedSymbols>* theLedSymbols;
  ModuleCreator<SelflocSymbols>* theSelflocSymbols;
  ModuleCreator<OdometrySymbols>* theOdometrySymbols;
  ModuleCreator<FieldSymbols>* theFieldSymbols;
  ModuleCreator<StrategySymbols>* theStrategySymbols;
  ModuleCreator<SoundSymbols>* theSoundSymbols;
  ModuleCreator<PathSymbols>* thePathSymbols;
  ModuleCreator<RemoteSymbols>* theRemoteSymbols;
};

#endif  /* _XABSLBehaviorControl_H */