AuboStudio SDK  0.6.3
script_writer.h
浏览该文件的文档.
1#ifndef AUBO_SCOPE_SCRIPT_WRITER_H
2#define AUBO_SCOPE_SCRIPT_WRITER_H
3
4#include <vector>
5#include <string>
8
9namespace arcs {
10namespace aubo_scope {
12
13/**
14 * This interface provides support for generating Script code.
15 */
17{
18public:
21 virtual ~ScriptWriter();
22
23 void setLabel(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 */
69
70 void assign(VariablePtr variable, const std::string &expression,
71 bool sync = false);
72
73 /**
74 * <p>Variable assignment.
75 * Assigns the variable without a local or global qualifier.
76 * See the Script Manual for the scoping rules.</p>
77 * @param variableName name of the variable, not null.
78 * @param expression expression that is assigned to the variable, not null.
79 */
80 void assign(const std::string &variableName,
81 const ExpressionPtr &expression, bool sync = false);
82
83 /**
84 * <p>Variable assignment.</p>
85 * @param variable the variable to assign an expression to, not null.
86 * @param expression expression that is assigned to the variable, not null.
87 */
88 void assign(VariablePtr variable, const ExpressionPtr &expression,
89 bool sync = false);
90
91 /**
92 * Add 1 to the variable value.
93 *
94 * @param variable the variable to increment. Not <code>null</code>.
95 */
96 void incrementVariable(const std::string &variable_name);
97
98 /**
99 * Add a note.
100 *
101 * @param expression the note expression.
102 */
103 void note(const std::string &expression);
104
105 /**
106 * Sleep for a number of seconds.
107 *
108 * @param seconds amount of time to sleep in seconds.
109 */
110 void sleep(double seconds);
111
112 /**
113 * Uses up the remaining "physical" time a thread has in the current frame.
114 */
115 void sync();
116
117 /**
118 *
119 * @param name Define a function of name name.
120 */
121 void defineFunction(const std::string &func_name);
122 void anonyFunction(const std::string &func_name);
123
124 void setRobotIndex(int robot_index);
125
126 /**
127 * Return from method.
128 */
130
131 /**
132 * Insert an end.
133 */
134 void end();
135
136 /**
137 * Insert an empty line.
138 */
139 void lineFeed();
140
141 /**
142 * <p>
143 * Sets the mass and Center of Gravity (CoG) of the payload.
144 * </p>
145 *
146 * This function must be called, when the payload weight or weigh
147 * distribution changes significantly, i.e when the robot arm picks up or
148 * puts down a heavy workpiece.
149 *
150 * @param payloadMass in kilograms
151 * @param centerOfGravityX displacement from the tool-mount in meters.
152 * @param centerOfGravityY displacement from the tool-mount in meters.
153 * @param centerOfGravityZ displacement from the tool-mount in meters.
154 */
155 void setPayload(double mass, double x, double y, double z);
156
157 /**
158 * <p>
159 * Set the Tool Center Point (TCP).
160 * </p>
161 *
162 * Sets the transformation from the tool output flange coordinate system to
163 * the TCP as a pose.
164 *
165 * @param x Position part.
166 * @param y Position part.
167 * @param z Position part.
168 * @param rx Rotation part.
169 * @param ry Rotation part.
170 * @param rz Rotation part.
171 */
172 void setTcp(const std::vector<double> &pose);
173
174 /**
175 * Start an if-conditional.
176 *
177 * @param expression the expression of the if-sentence. Not
178 * <code>null</code>.
179 */
180 void ifCondition(const ExpressionPtr &expression);
181
182 /**
183 * Start a negated if-conditional
184 *
185 * @param expression the expression of the negated if-sentence.
186 */
187 void ifNotCondition(const ExpressionPtr &expression);
188
189 /**
190 * Adds an else-if branch.
191 *
192 * @param expression the expression of the "else-if"-sentence.
193 */
194 void elseIfCondition(const ExpressionPtr &expression);
195
196 /**
197 * Adds an else branch.
198 *
199 */
201
202 /**
203 * Starts a for-loop with tow loop invariants.
204 *
205 * @param count the loop counts.
206 * @param step the loop step.
207 */
208 void forCondition(int count, int step);
209
210 /**
211 * Starts a while true loop.
212 *
213 */
214 void whileTrue();
215
216 /**
217 * Starts a while-loop with a loop invariant.
218 *
219 * @param expression the loop invariant.
220 */
221 void whileCondition(const ExpressionPtr &expression);
222
223 /**
224 * Starts a while-loop with a negated loop invariant.
225 *
226 * @param expression the loop invariant that will be negated.
227 */
228 void whileNot(const ExpressionPtr &expression);
229
230 /**
231 * Start a thread definition with a given thread name.
232 *
233 * @param threadName the name of the new thread.
234 * @param loop_or_not the new thread loops or not.
235 */
236 void defineThread(const std::string &thread_name, bool loop_or_not);
237
238 /**
239 * Start a previously defined thread.
240 *
241 * @param threadName The name of the thread that will be started.
242 */
243 void runThread(const std::string &thread_name);
244
245 /**
246 * @brief killThread
247 * @param thread_name
248 */
249 void killThread(const std::string &thread_name);
250
251 /**
252 * <p>
253 * Returns a registered variable name that can be used in a script.
254 * </p>
255 *
256 * <p>
257 * A variable is registered if it has been stored in a {@link DataModel}
258 * instance or used for the configuration of a built-in AuboScope program
259 * node.
260 * </p>
261 *
262 * <b>Please note:</b> The name of a variable in the script can be different
263 * from the value of {@link Variable#getDisplayName()}. You should not use
264 * the value of {@link Variable#getDisplayName()} in a script.
265 *
266 * @param variable a registered Variable. Not <code>null</code>.
267 * @return variable name that can be used in a script.
268 * @exception IllegalArgumentException if the <code>variable</code> was not
269 * registered in the data model or used for the configuration of a built-in
270 * AuboScope program node.
271 * @exception ClassCastException if the <code>variable</code> was not
272 * created by
273 * {@link domain/variable/VariableFactory}.
274 *
275 */
276 std::string getResolvedVariable(const std::string &variable_name);
277
280
281private:
282 friend class DataSwitch;
284 void *d_{ nullptr };
285};
286
287} // namespace aubo_scope
288} // namespace arcs
289
290#endif // AUBO_SCOPE_SCRIPT_WRITER_H
#define ARCS_ABI_EXPORT
#define ARCS_CLASS_FORWARD(C)
Macro that forward declares a class and defines the respective smartpointers through ARCS_DECLARE_PTR...
This interface provides support for generating Script code.
void setLabel(int lineno, const std::string &comment)
ScriptWriter(ScriptWriter &&f)
std::string generateScript()
Generate a string with the full script code.
void anonyFunction(const std::string &func_name)
void sync()
Uses up the remaining "physical" time a thread has in the current frame.
void whileTrue()
Starts a while true loop.
void sleep(double seconds)
Sleep for a number of seconds.
void killThread(const std::string &thread_name)
killThread
void appendLine(const std::string &script_line)
Adds a single line of script code using auto-indentation.
void ifNotCondition(const ExpressionPtr &expression)
Start a negated if-conditional
void assign(VariablePtr variable, const ExpressionPtr &expression, bool sync=false)
void incrementVariable(const std::string &variable_name)
Add 1 to the variable value.
void defineFunction(const std::string &func_name)
void setPayload(double mass, double x, double y, double z)
void forCondition(int count, int step)
Starts a for-loop with tow loop invariants.
void note(const std::string &expression)
Add a note.
void assign(const std::string &variableName, const ExpressionPtr &expression, bool sync=false)
void end()
Insert an end.
void runThread(const std::string &thread_name)
Start a previously defined thread.
void elseCondition()
Adds an else branch.
void whileCondition(const ExpressionPtr &expression)
Starts a while-loop with a loop invariant.
void appendRaw(const std::string &script)
Adds script code appending the script code as is without using auto-indentation.
void setTcp(const std::vector< double > &pose)
void appendVectorDouble(const std::vector< double > &value)
void assign(VariablePtr variable, const std::string &expression, bool sync=false)
void elseIfCondition(const ExpressionPtr &expression)
Adds an else-if branch.
void lineFeed()
Insert an empty line.
void returnMethod()
Return from method.
std::string getResolvedVariable(const std::string &variable_name)
void ifCondition(const ExpressionPtr &expression)
Start an if-conditional.
void defineThread(const std::string &thread_name, bool loop_or_not)
Start a thread definition with a given thread name.
void setRobotIndex(int robot_index)
void whileNot(const ExpressionPtr &expression)
Starts a while-loop with a negated loop invariant.