AuboCaps  0.5.0
script_writer.h
Go to the documentation of this file.
1 #ifndef AUBO_SCOPE_SCRIPT_WRITER_H
2 #define AUBO_SCOPE_SCRIPT_WRITER_H
3 
4 #include <vector>
5 #include <string>
8 
9 namespace arcs {
10 namespace aubo_scope {
11 ARCS_CLASS_FORWARD(ScriptWriter);
12 
13 /**
14  * This interface provides support for generating Script code.
15  */
17 {
18 public:
21  virtual ~ScriptWriter();
22 
23  void setLable(int lineno, const std::string &comment);
24 
25  /**
26  * Adds a single line of script code using auto-indentation.
27  *
28  * @param script_line single line of script code to append.
29  */
30  void appendLine(const std::string &script_line);
31  void appendVectorDouble(const std::vector<double> &value);
32 
33  /**
34  * Adds script code appending the script code as is without using
35  * auto-indentation.
36  *
37  * @param script script code to append.
38  */
39  void appendRaw(const std::string &script);
40 
41  /**
42  * Generate a string with the full script code.
43  *
44  * @return the resulting script as a string.
45  */
46  std::string generateScript();
47 
48  /**
49  * <p>
50  * Use this method when generating script code for a node that has children
51  * nodes.globalVariable
52  * </p>
53  *
54  * A simple example:
55  * <pre>
56  * {@code
57  * writer.ifCondition(expression)
58  * writer.writeChildren() // let children nodes generate code.
59  * writer.end()
60  * @endcode}
61  * </pre>
62  *
63  * In most cases you prglobalVariableobably only want to call {@link
64  * ScriptWriter#writeChildren()} once, but it is possible to call it
65  * multiple times and thus have children nodes generate their code multiple
66  * times.
67  */
68  void writeChildren();
69 
70  void assign(VariablePtr variable, const std::string &expression);
71 
72  /**
73  * <p>Variable assignment.
74  * Assigns the variable without a local or global qualifier.
75  * See the Script Manual for the scoping rules.</p>
76  * @param variableName name of the variable, not null.
77  * @param expression expression that is assigned to the variable, not null.
78  */
79  void assign(const std::string &variableName,
80  const ExpressionPtr &expression);
81 
82  /**
83  * <p>Variable assignment.</p>
84  * @param variable the variable to assign an expression to, not null.
85  * @param expression expression that is assigned to the variable, not null.
86  */
87  void assign(VariablePtr variable, const ExpressionPtr &expression);
88 
89  /**
90  * Add 1 to the variable value.
91  *
92  * @param variable the variable to increment. Not <code>null</code>.
93  */
94  void incrementVariable(const std::string &variable_name);
95 
96  /**
97  * Add a note.
98  *
99  * @param expression the note expression.
100  */
101  void note(const std::string &expression);
102 
103  /**
104  * Sleep for a number of seconds.
105  *
106  * @param seconds amount of time to sleep in seconds.
107  */
108  void sleep(double seconds);
109 
110  /**
111  * Uses up the remaining "physical" time a thread has in the current frame.
112  */
113  void sync();
114 
115  /**
116  *
117  * @param name Define a function of name name.
118  */
119  void defineFunction(const std::string &func_name);
120  void anonyFunction(const std::string &func_name);
121 
122  /**
123  * Return from method.
124  */
125  void returnMethod();
126 
127  /**
128  * Insert an end.
129  */
130  void end();
131 
132  /**
133  * Insert an empty line.
134  */
135  void lineFeed();
136 
137  /**
138  * <p>
139  * Sets the mass and Center of Gravity (CoG) of the payload.
140  * </p>
141  *
142  * This function must be called, when the payload weight or weigh
143  * distribution changes significantly, i.e when the robot arm picks up or
144  * puts down a heavy workpiece.
145  *
146  * @param payloadMass in kilograms
147  * @param centerOfGravityX displacement from the tool-mount in meters.
148  * @param centerOfGravityY displacement from the tool-mount in meters.
149  * @param centerOfGravityZ displacement from the tool-mount in meters.
150  */
151  void setPayload(double mass, double x, double y, double z);
152 
153  /**
154  * <p>
155  * Set the Tool Center Point (TCP).
156  * </p>
157  *
158  * Sets the transformation from the tool output flange coordinate system to
159  * the TCP as a pose.
160  *
161  * @param x Position part.
162  * @param y Position part.
163  * @param z Position part.
164  * @param rx Rotation part.
165  * @param ry Rotation part.
166  * @param rz Rotation part.
167  */
168  void setTcp(const std::vector<double> &pose);
169 
170  /**
171  * Start an if-conditional.
172  *
173  * @param expression the expression of the if-sentence. Not
174  * <code>null</code>.
175  */
176  void ifCondition(const ExpressionPtr &expression);
177 
178  /**
179  * Start a negated if-conditional
180  *
181  * @param expression the expression of the negated if-sentence.
182  */
183  void ifNotCondition(const ExpressionPtr &expression);
184 
185  /**
186  * Adds an else-if branch.
187  *
188  * @param expression the expression of the "else-if"-sentence.
189  */
190  void elseIfCondition(const ExpressionPtr &expression);
191 
192  /**
193  * Adds an else branch.
194  *
195  */
196  void elseCondition();
197 
198  /**
199  * Starts a for-loop with tow loop invariants.
200  *
201  * @param count the loop counts.
202  * @param step the loop step.
203  */
204  void forCondition(int count, int step);
205 
206  /**
207  * Starts a while true loop.
208  *
209  */
210  void whileTrue();
211 
212  /**
213  * Starts a while-loop with a loop invariant.
214  *
215  * @param expression the loop invariant.
216  */
217  void whileCondition(const ExpressionPtr &expression);
218 
219  /**
220  * Starts a while-loop with a negated loop invariant.
221  *
222  * @param expression the loop invariant that will be negated.
223  */
224  void whileNot(const ExpressionPtr &expression);
225 
226  /**
227  * Start a thread definition with a given thread name.
228  *
229  * @param threadName the name of the new thread.
230  * @param loop_or_not the new thread loops or not.
231  */
232  void defineThread(const std::string &thread_name, bool loop_or_not);
233 
234  /**
235  * Start a previously defined thread.
236  *
237  * @param threadName The name of the thread that will be started.
238  */
239  void runThread(const std::string &thread_name);
240 
241  /**
242  * @brief killThread
243  * @param thread_name
244  */
245  void killThread(const std::string &thread_name);
246 
247  /**
248  * <p>
249  * Returns a registered variable name that can be used in a script.
250  * </p>
251  *
252  * <p>
253  * A variable is registered if it has been stored in a {@link DataModel}
254  * instance or used for the configuration of a built-in AuboScope program
255  * node.
256  * </p>
257  *
258  * <b>Please note:</b> The name of a variable in the script can be different
259  * from the value of {@link Variable#getDisplayName()}. You should not use
260  * the value of {@link Variable#getDisplayName()} in a script.
261  *
262  * @param variable a registered Variable. Not <code>null</code>.
263  * @return variable name that can be used in a script.
264  * @exception IllegalArgumentException if the <code>variable</code> was not
265  * registered in the data model or used for the configuration of a built-in
266  * AuboScope program node.
267  * @exception ClassCastException if the <code>variable</code> was not
268  * created by
269  * {@link domain/variable/VariableFactory}.
270  *
271  */
272  std::string getResolvedVariable(const std::string &variable_name);
273 
274  void increaseIndent();
275  void decreaseIndent();
276 
277 private:
278  friend class DataSwitch;
279  ScriptWriter();
280  void *d_{ nullptr };
281 };
282 
283 } // namespace aubo_scope
284 } // namespace arcs
285 
286 #endif // AUBO_SCOPE_SCRIPT_WRITER_H
ARCS_CLASS_FORWARD(GripForceCapability)
This interface provides support for generating Script code.
Definition: script_writer.h:16
#define ARCS_ABI_EXPORT
Definition: class_forward.h:16