Conscience Core
CommandParser.h
Go to the documentation of this file.
1 #ifndef CscEnvironmentInteractionCommandParser_h
2 #define CscEnvironmentInteractionCommandParser_h
3 
4 #include "../Command.h"
7 
11 
12 #include <functional>
13 #include <unordered_set>
14 
15 using std::function, std::runtime_error, conscience_utils::logging::CscLogger, std::unordered_set;
16 
17 using namespace conscience_core::core_objects;
18 using namespace conscience_core::ai;
19 
22 }
23 
25 
28  vector<string> commandArguments;
29  optional<int> knowledgeId = {};
30 };
31 
33 
34 public:
35  static CscEnvironmentInteractionCommandParser *getInstance();
36 
37  ptr<CscCommand> parseFromString(const string &commandString);
38  const CscStringCommandParts splitCommandParts(const string &commandString);
39  unordered_set<CommandTypeId> getSupportedCommandIds();
40 
42 
43 protected:
45  const ConscienceEncoder &conscienceEncoder,
46  CscEntityModelsRepository &entityModelRepository,
48 
49 private:
50  typedef function<ptr<CscCommand>(CscCommandParseContext &params)> ParseCommandFunction;
51 
52  const map<CommandTypeId, ParseCommandFunction> *parseFunctions = nullptr;
53 
54  const map<CommandTypeId, ParseCommandFunction> &getParseFunctions();
55 
56  ParseCommandFunction getParseFunction(const CommandTypeId &commandId, bool autoParseFunctionOnly);
57 
58  inline static CscEnvironmentInteractionCommandParser *instance = nullptr;
59  inline static unique_ptr<CscLogger> logger = nullptr;
60 
61  const ConscienceEncoder &conscienceEncoder;
62  CscEntityModelsRepository &entityModelRepository;
64 
65  ptr<CscCommand> createCommandMemberToStateFromMember(CscCommandParseContext &parseParams);
66  ptr<CscCommand> createCommandMemberToObjectFromMember(CscCommandParseContext &parseParams);
67  ptr<CscCommand> createCommandMemberToState(CscCommandParseContext &parseParams);
68  ptr<CscCommand> createCommandMemberFocusState(CscCommandParseContext &parseParams);
69  ptr<CscCommand> createCommandMemberToStateTeleport(CscCommandParseContext &parseParams);
70  ptr<CscCommand> createCommandMemberToStateTeleportEulersOnly(CscCommandParseContext &parseParams);
71  ptr<CscCommand> createCommandMemberToStateTeleportStrict(CscCommandParseContext &parseParams);
72  ptr<CscCommand> createCommandEntityToObject(CscCommandParseContext &parseParams);
73  ptr<CscCommand> createCommandUpdateWheelsPower(CscCommandParseContext &parseParams);
74  ptr<CscCommand> createCommandUpdateWheels(CscCommandParseContext &parseParams);
75  ptr<CscCommand> createCommandUpdatePropellers(CscCommandParseContext &parseParams);
76  ptr<CscCommand> createCommandPlayStateOutputs(CscCommandParseContext &parseParams);
77  ptr<CscCommand> createCommandUpdateStateOutputsFromReal(CscCommandParseContext &parseParams);
78  ptr<CscCommand> createCommandUpdateConfigurationPivot(CscCommandParseContext &parseParams);
79  ptr<CscCommand> createCommandEnvironmentObjectUpdate(CscCommandParseContext &parseParams);
80  ptr<CscCommand> createCommandEnvironmentObjectAnalysis(CscCommandParseContext &parseParams);
81  ptr<CscCommand> createCommandUpdateConfigurationMember(CscCommandParseContext &parseParams);
83  VisionDetectParseResult parseVisionDetectCommand(CscCommandParseContext &parseParams);
84  ptr<CscCommand> createCommandVisionDetect(CscCommandParseContext &params);
85  ptr<CscCommand> createCommandSaveConfigurationToModelPivot(CscCommandParseContext &parseParams);
86  ptr<CscCommand> createCommandSaveConfigurationToModelMembers(CscCommandParseContext &parseParams);
87  ptr<CscCommand> createCommandSaveConfigurationToModelParams(CscCommandParseContext &parseParams);
88  ptr<CscCommand> createCommandSaveConfigurationToModelWheel(CscCommandParseContext &parseParams);
89  ptr<CscCommand> createCommandSaveConfigurationToModelPropeller(CscCommandParseContext &parseParams);
90  ptr<CscCommand> createCommandSaveConfigurationToModelTranslation(CscCommandParseContext &parseParams);
91  ptr<CscCommand> createCommandTerrassement(CscCommandParseContext &parseParams);
92  ptr<CscCommand> createCommandTerrassementPickUp(CscCommandParseContext &parseParams);
93  ptr<CscCommand> createCommandTerrassementDropOff(CscCommandParseContext &parseParams);
94  ptr<CscCommand> createCommandLocateTargets(CscCommandParseContext &parseParams);
95  ptr<CscCommand> createCommandDrilling(CscCommandParseContext &parseParams);
96  ptr<CscCommand> createCommandUpdateFloorRotation(CscCommandParseContext &parseParams);
97 
98  ptr<CscCommand> createCommandEntityFollowPath(CscCommandParseContext &parseParams);
99  ptr<CscCommand> createCommandUpdateConfigurationTranslation(CscCommandParseContext &parseParams);
100  ptr<CscCommand> createCommandTellThis(CscCommandParseContext &parseParams);
101  ptr<CscCommand> createCommandFollowTrajectoryAndProject(CscCommandParseContext &parseParams);
102 
103  ptr<CscCommand> createCommandFollowKinematicTrajectory(CscCommandParseContext &parseParams);
104  ptr<CscCommand> createCommandEntityToLocationTag(CscCommandParseContext &parseParams);
105  ptr<CscCommand> createCommandKinematicMovement(CscCommandParseContext &parseParams);
106  ptr<CscCommand> createCommandMultiPodWalk(CscCommandParseContext &parseParams);
107 
108  ptr<CscCommand> createCommandJacobianInverseKinematicMovement(CscCommandParseContext &parseParams);
109 
110  template <class TCommandClass>
111  ptr<CscCommand> createCommandAreaAnalysis(CscCommandParseContext &parseParams) {
112  const vector<string> &arguments = parseParams.arguments;
113 
114  logger->trace("Creating ConscienceEnvironmentInteractionCommandAreaAnalysis from arguments - size=" + to_string(arguments.size()));
115  string parametersString = arguments.at(PARAMETERS_ARGUMENT_INDEX);
116  logger->trace("ParametersString=" + parametersString);
117 
118  vector<string> *parametersTokens = splitString(parametersString, PARAMETERS_ARGUMENT_DELIMITER);
119 
120  int paramIndex = 0;
121 
122  const string entitySerialNumber = parametersTokens->at(paramIndex++);
123  int numberOfPosition = stoi(parametersTokens->at(paramIndex++));
124  vector<const CscPoint3d *> areaVertices = vector<const CscPoint3d *>();
125 
126  for (int i = 0; i < numberOfPosition; i++) {
127  int x = stoi(parametersTokens->at(paramIndex++));
128  int y = stoi(parametersTokens->at(paramIndex++));
129  int z = stoi(parametersTokens->at(paramIndex++));
130  areaVertices.push_back(new CscPoint3d(x, y, z));
131  }
132 
133  int numberOfHoles = stoi(parametersTokens->at(paramIndex++));
134  vector<vector<const CscPoint3d *>> holes = vector<vector<const CscPoint3d *>>();
135 
136  for (int i = 0; i < numberOfHoles; i++) {
137  vector<const CscPoint3d *> hole = vector<const CscPoint3d *>();
138  int numberOfPositionHole = stoi(parametersTokens->at(paramIndex++));
139  for (int j = 0; j < numberOfPositionHole; j++) {
140  int x = stoi(parametersTokens->at(paramIndex++));
141  int y = stoi(parametersTokens->at(paramIndex++));
142  int z = stoi(parametersTokens->at(paramIndex++));
143  hole.push_back(new CscPoint3d(x, y, z));
144  }
145  holes.push_back(hole);
146  }
147  float areaOfPerceptionWidth = stof(parametersTokens->at(paramIndex++));
148  int x = stoi(parametersTokens->at(paramIndex++));
149  int y = stoi(parametersTokens->at(paramIndex++));
150  int z = stoi(parametersTokens->at(paramIndex++));
151  const CscPoint3d *entityPosition = new CscPoint3d(x, y, z);
152 
153  ptr<CscEntityReflexion> entityReflexion = entityReflexions.getBySerialNumber(entitySerialNumber);
154 
155  optional<bool> doNotPlay = {};
156  if (parametersTokens->size() > paramIndex) {
157  if (trim(parametersTokens->at(paramIndex)) != "") {
158  doNotPlay = parametersTokens->at(paramIndex) == "true";
159  }
160  paramIndex++;
161  }
162 
163  delete parametersTokens;
164 
165  return newptr<TCommandClass>(entityReflexion, areaVertices, holes, areaOfPerceptionWidth, entityPosition, doNotPlay);
166  }
167  ptr<CscCommand> createCommandLidarLocalizationControl(CscCommandParseContext &parseParams);
168  ptr<CscCommand> createCommandStopFollowObject(CscCommandParseContext &parseParams);
169 
170  CscArtificialIntelligenceTypes aiBoolToTypes(bool typeGenetic, bool typeKinematic);
171 
172  ptr<CscCommand> doParseFromString(const string &commandString, bool forceAutoParse);
173 };
174 }
175 
176 #endif
nlohmann::to_string
NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL &j)
user-defined to_string function for JSON values
Definition: json.hpp:26470
conscience_core::axiomes::CscPoint3d
The CscPoint3d class represents a point in three-dimensional space. It is primarily used to denote a ...
Definition: Csc3dTypes.h:24
conscience_core::core_objects
Definition: CscEntityReflexion.h:33
CSC_DLL_IMPORTEXPORT
#define CSC_DLL_IMPORTEXPORT
Definition: os.h:34
conscience_core::ai
Definition: alerts.cpp:12
conscience_core::bridging::commands::CscStringCommandParts::commandArguments
vector< string > commandArguments
Definition: CommandParser.h:28
conscience_core::bridging::commands::CscCommandParseContext
Definition: CommandParseContext.h:57
PARAMETERS_ARGUMENT_DELIMITER
#define PARAMETERS_ARGUMENT_DELIMITER
Definition: CommandParseContext.h:37
conscience_core::bridging::commands::CscStringCommandParts
Definition: CommandParser.h:26
conscience_core::bridging::commands::entityReflexions
static ptr< CscEntityReflexions > entityReflexions
Definition: CommandCommons.h:17
conscience_core::bridging::commands::CscStringCommandParts::commandId
CommandTypeId commandId
Definition: CommandParser.h:27
conscience_core::ai::CscEntityReflexions
Definition: CscEntityReflexions.h:27
conscience_core::bridging::commands::CscEnvironmentInteractionCommandParser
Definition: CommandParser.h:32
conscience_utils::splitString
vector< string > * splitString(const string &inputString, const string &delimiter, bool escapeDelimiterWithBackslash)
Definition: conscience_util.cpp:235
conscience_core::bridging::commands::CommandTypeId
string CommandTypeId
Definition: Command.h:29
jwt::base::details::trim
std::string trim(const std::string &base, const std::string &fill)
Definition: base.h:244
InvalidCommandException.h
CscEntityReflexion.h
CscEntityReflexions.h
logger
static std::unique_ptr< CscLogger > logger
Definition: gltfHelpers.cpp:6
conscience_core::knowledge::CscArtificialIntelligenceTypes
uint64_t CscArtificialIntelligenceTypes
Definition: CommandParser.h:21
conscience_core::knowledge
Definition: CscEntityReflexion.h:35
conscience_core::bridging::commands
Definition: cartographyCommands.cpp:4
CommandParseContext.h
PARAMETERS_ARGUMENT_INDEX
#define PARAMETERS_ARGUMENT_INDEX
Definition: CommandParseContext.h:31
CscEntityModelsRepository.h
conscience_core::bridging::ConscienceEncoder
Definition: ConscienceEncoder.h:46
conscience_server::entities::instance
ServerEntities * instance
Definition: ServerEntities.cpp:39
conscience_core::core_objects::entities::CscEntityModelsRepository
Definition: CscEntityModelsRepository.h:27
conscience_utils::logging::CscLogger
Definition: conscience_log.h:121
conscience_core::bridging::commands::CscCommandParseContext::arguments
const vector< string > & arguments
Definition: CommandParseContext.h:60
ptr
std::shared_ptr< T > ptr
Definition: CscCommon.h:29
j
int j
Definition: HybridAStar.cpp:192
conscience_core::bridging::commands::CscEnvironmentInteractionCommandParser::VisionDetectParseResult
Definition: CommandParser.cpp:1504
i
int i
Definition: HybridAStar.cpp:191