-
Notifications
You must be signed in to change notification settings - Fork 14
/
README
702 lines (569 loc) · 19.3 KB
/
README
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
QiCore README
=============
This lib is a fork of the "frameManager", it aims to execute behaviors that
was previous executed with the frameManager but with much more flexibility.
At the moment, QiCore is only a compatibility layer, but it aims to become
the new execution core of behaviors.
QiCore and the frameManager are independant, meaning that you can execute behaviors
with both of us.
Getting Started:
----------------
Let's suppose you want to execute a behavior stored in a xar file.
First of all, correctly set your PYTHONPATH to collect all python modules needed.
1/ Convert the behavior:
python2 xar_converter.py path/to/behavior/behavior.xar output_folder/
This step will give you a folder with all objects needed by the behavior and
a main.py, entry point of the behavior.
2/ Execute the behavior:
python2 output_folder/main.py IP PORT
Where IP and PORT are the ip and port of the naoqi you want to connect.
The part to understand in the execution process is that the behavior is executed
on the machine that lunch the behavior with the python interpreter but the result
of the behavior is visible on the naoqi you are connected to.
In other words, commands are send to the distant naoqi at the right time, but this
distant naoqi does not know anything about the behavior.
To execute behaviors the same way that frameManager does, you probably want
to copy libQicore to the robot and then execute the following command on the robot:
python2 output_folder/main.py 127.0.0.1 9559
Sub-Projects:
-------------
QiCore can be splitted in different entities:
- The converter
It converts a xar file (v3) to a new format, discussed later.
- The core with C++ Objects that executes a behavior
Composed with Timeline, StateMachine, Box, Transition
- The object factory
Load python objects at run-time and connect them
- The qicore_legacy
Provide the support of functions provided previously by ALBehavior
Status:
-------
- Converter:
Subject to a lot of testing, it converts successfully all tested behaviors.
May be an effort can be put in printing nice error if file is incorrect.
- Core:
StateMachine: used to replace behaviorKeyFrames, behaviorLayers
Timeline: a lot of code comes from the legacy timeline, but this
object handles only actuatorCurves. Threading model has been rebuilt.
Box: Represents a legacy box, a box is also a state in the stateMachine
Transition: Represents a transitions between two boxes
The main differences in objects representations with the frameManager is
that what is called Timeline in the frameManager is splitted into :
Timeline and StateMachine in QiCore. Also the Timeline in QiCore is a lot
simpler, and handles much less work.
- Object Factory:
At the moment, only load python objects.
- QiCore Legacy:
Provide the same level of functionnalities than ALBehavior.
Differences : qicore_legacy does not provide resource management at the
moment. Objects are not ALModules for the moment.
Benefits over frameManager:
---------------------------
- Interactions between C++ and Python:
In the frameManager, interactions between C++ and Python are not very clear,
some of the work are done in python, but connections between boxes are done
in C++. C++ code calls python that will call C++ again.
With QiCore, the behavior is written in Python, this Python code plays with
C++ objects transparently (Swig is used for the binding).
Sometimes C++ has to hold a callback in the Python world, but there is an
effort to minimize the number of callbacks. Callbacks are listed later.
- ALBehavior, ALPythonBridge, ALMemory
frameManager required all these objects to work. Signals between boxes are
done by ALMemory, it is a bottleneck because ALMemory is a centralized
sytem. All the Python code is executed in a special C++ Thread with an
embedded Python interpreter.
With QiCore, interactions between boxes are done by qi::Signal, so boxes can
interacts with each others without the help of a central module.
Python code can be executed directly by any stand alone python interpreter.
- Timeline concept and StateMachine
The timeline concept was a bit messy and unintuitive with the frameManager.
A lot of people was using the timeline of the frameManager as a StateMachine.
QiCore provides a Timeline that executes only actuatorCurves and a StateMachine
- Code generation
FrameManager generates a lot of code with each boxes, and debugging generated
code is awful.
QiCore aims to generate a mimum of code, and leave the original code almost
untouched, code needed by the boxes are added at run-time, transparently.
- Play with C++ Objects
FrameManager does not provide an API to play with Timeline and others objects
QiCore provides an API to interact with objects in behaviors
- Maintain the code
All concepts in the frameManager are intertwined, so the code is hard to
maintain and understand.
QiCore wants to provide clean concepts, easy to unterstand.
- New format
Format supported by the frameManager include embedded python code.
QiCore provides a new format with python code stored as .py and meta informations
stored in xml files. Objects are splitted in different files.
- Stand alone
FrameManager can not produce a stand alone python file that can be executed
With QiCore you can simply execute a behavior with the following command:
python2 behavior/main.py IP PORT
That means you can execute a behavior on a desktop computer and send commands
to a robot.
We can also imagine that a robot send a behavior to another robot or a desktop
computer can execute the same behavior on multiple robots.
To do:
------
- Catch SIGINT and send a on_stop signal to all boxes to quit elegantly.
- At the moment objects does not need to be in globals, may be change that.
- Path to file needed by the behaviors are incorrect, for example if you want
to play a sound on a robot.
- All functions that handles resources just do nothing (qicore_legacy.py,
waitForResources, ...)
- Naoqi is still needed to create proxies on services, but it is possible
to replace ALProxy in naoqi by some qimessaging binding
- Boxes uses qi::signal, but are not naoqi2 objects
- Timeline tests are not usable, fix it
- Improve the ALMemoryWatcher and replace the polling thread by a
subscribeToEvent
- Fix the "from naoqi import *" in py files
- Cleaner XML generation in converter/file_writer.py
- Swig detects a leak with boost::shared_ptr<ALBroker>, fix it.
This leaks only happends when creating a timeline
- There is a mix between the new API and the old API, an effort can be put
to use a minimum of the old API.
- The goTo in the stateMachine can be faster if we store labels in a map, instead
of going though each box.
- The goTo in StateMachine and Timeline is a bit messy, it is the StateMachine
that handles the goto, and then we handle the timeline. May be it will be
cleaner to let the Timeline handle the goTo and contact the StateMachine if
we need to change the state
- To be able to control the StateMachine or the Timeline of a parent, each box
have a pointer to its parent. But this pointer can be replaced by a signal.
- A lot of fixes to execute behaviors exactly as frameManager
To know:
--------
- The StateMachine execute transitions in a thread, transitions are queued are
performed in order of arrival (FIFO)
- Callbacks:
* When changing states the the StateMachine will call the load callback on the
next state, the unload callback on the previous state, and call the
onNewState callback to trigger IO between boxes.
* When the timeline has reached the last frame, it calls a python callback
to trigger onStopped Outputs
- If you want to convert a crg file to the new format you can do the following:
ar vx my_behavior.crg && tar vxf data.tar.gz
to extract the .xar file and then convert it.
- Functions generated by the frameManager are added at run time and generated
in function_generator.py
- The code that converts a old-style Timeline in a StateMachine is in the converter,
in the file converter/new_format_generator.py
- To be able to reproduce the goTo of the old-style Timeline, the StateMachine
uses two things: labels, that allows to a state associated with the label and
provides an interval that belongs the state, this is useful when the user
want to jump to a frame.
- Connections between boxes are done when loading the state associated and
destroyed when leaving the state
- The Timeline have flags to trigger each state of the StateMachine at the
right time. A flag is the association of a state name and the frame you want
to trigger the transition. The only exception is the first frame, there is
no flag for it, cause it is the initial state and the state is entered by
calling run on the stateMachine
Hacks:
------
- There is a ref couting on load/unload boxes to prevent multiple loads, indeed
when converting an old-style timeline to a stateMachine some objects are duplicated
but you do not want to load them multiple times
- The same ref couting mechanism is present with connection between boxes for the
same reasons.
- onLoad signal seems like a hack in the frameManager, this signal is triggerd each time
we enter in a new keyframe. In the StateMachine this signal has to be triggered
when entering a new state but this signal must not trigger boxes already activated.
So every time the onLoad signal is triggerd, this signal is replaced by a new one
with no connections. The previous onLoad is then stored because we do not want
Xar format documentation:
-------------------------
A Xar file is an xml file that describes a behavior
Elements:
- Box
- Diagram
- Timeline
- BehaviorLayer
- BehaviorKeyFrame
- Script
- Content
- Input
- Output
- Parameter
- Resource
- ActuatorList
- ActuatorCurve
- Key
- Link
- Bitmap
Box:
Attributes:
- name: name of the box
- robot: robot targeted by the behavior
- id: id of the box
- tooltip: hint about how to use the box
- bitmap_expanded: FIXME
- plugin: FIXME
- x: x coordinate of the box
- y: y coordinate of the box
Inner-Elements:
- bitmap
- script
- Input
- Output
- Parameters
- Timeline
- Resources
Bitmap:
Content:
- Path to the bitmap file
Script:
Attributes:
- Language:
- 0 -> C++
- 1 -> URBI
- 2 -> Ruby
- 3 -> Dynamic Librabry
- 4 -> Python
- 5 -> QiChat
- 6 -> No Script
Content:
- Content Beacon
Content:
Content:
- The script it-self.
Input:
Attributes:
- name : Name of the input
- type:
- 0 -> Dynamic
- 1 -> Bang
- 2 -> Number
- 3 -> String
- 4 -> Bitmap
- 5 -> Sound
- type_size: size of the type
- nature:
- 0 -> onLoad
- 1 -> unDef
- 2 -> onStart
- 3 -> onStop
- 4 -> STMValue
- stm_value_name : value associated in ALMemory
- inner :
- tooltip : tip for the user
- id : identifier for the IO Port (local to the box)
Output:
Attributes:
- name : Name of the input
- type:
- 0 -> Dynamic
- 1 -> Bang
- 2 -> Number
- 3 -> String
- 4 -> Bitmap
- 5 -> Sound
- type_size: size of the type
- nature:
- 0 -> unDef
- 1 -> Stopped
- 2 -> Punctual
- 3 -> Recurrent
- inner :
- tooltip : tip for the user
- id : identifier for the IO Port (local to the box)
Parameter:
Attributes:
- name: name of the parameter
- inherits_from_parent:
- 0 -> parameter is not inherited
- 1 -> inherited parameter
- content_type:
- 0 -> Bool
- 1 -> Int
- 2 -> Double
- 3 -> String
- 4 -> Resource
- value: value of the parameter
- default_value: default value taken by the parameter
- min : min value for the parameter
- max : max value for the parameter
- tooltip : hint for the user
- id : identifier for the parameter (local to the box)
- custom_choice : FIXME
Timeline:
Attributes:
- enable:
- 0 -> disabled
- 1 -> enabled
- name: timeline name
- fps : Frames per seconds
- resource_acquisition:
- 0 -> Passive
- 1 -> Waiting
- 2 -> Aggresive
- size: FIXME
- start_frame: first frame
- end_frame: last frame
- scale : FIXME
Inner-Elements:
- BehaviorLayer
- ActuatorList
- watches : FIXME
BehaviorLayer:
Attributes:
- name : name of the behaviorLayer
- mute : FIXME
Inner-Elements:
- BehaviorKeyFrame
BehaviorKeyFrame:
Attributes:
- name : name of the keyframe
- index : frame associated with the keyframe
Inner-Elements:
- Diagram
Diagram:
Attributes:
- scale : FIXME
Inner-Elements:
- Box
- Link
Link:
Attributes:
- inputowner : id of the box local to the diagram, 0 means the
parent box
- outputower : same as previous
- indexofinput : id of the input (local to the box)
- indexofoutput : id of the output (local to the box)
ActuatorList:
Attirbutes:
- model : FIXME
Inner-Elements:
- ActuatorCurve
ActuatorCurve:
Attributes:
- name : name of the actuatorCurve
- actuator : Resource concerned by the actuatorCurve
- recordable : FIXME
- mute : FIXME
- unit : FIXME
Inner-Elements:
- Key
Key:
Attributes:
- frame : frame concerned by the parent ActuatorCurve
- value
Resource:
Attributes:
- name : name of the resource
- type :
- 0 -> Lock
- 1 -> Stop_on_demand
- 2 -> Pause_on_demand
- 3 -> Callback_on_demand
- timeout
Elements Hierarchy:
<Box>
<bitmap> </bitmap>
<script>
<content> </content>
</script>
<Input />
...
<Input />
<Output />
...
<Output />
<Parameter />
...
<Parameter />
<Timeline>
<BehaviorLayer>
<BehaviorKeyFrame>
<Diagram>
<Box>
</Box>
....
<Box>
</Box>
</Diagram>
</BehaviorKeyFrame>
<BehaviorKeyFrame>
... (same as previous)
</BehaviorKeyFrame>
</BehaviorLayer>
<BehaviorLayer>
... (same as previous)
</BehaviorLayer>
<ActuatorList>
<ActuatorCurve>
<Key />
...
<Key />
</ActuatorCurve>
<ActuatorCurve>
... (same as previous)
</ActuatorCurve>
</ActuatorList>
</Timeline>
<Resource />
...
<Resource />
</Box>
New format documentation:
-------------------------
This new format is not a definitive format, but is more like a test on how
to create a format more human readable and easy to edit. It aims to be compatible
with the previous xar format.
There is two kind of files:
- .xml files -> contains meta informations about the object
- .py files -> contains the Python code of the object
All these files are stored in the same directory
Each object is made of one py file and on xml file. Let's say I have an object
called foo, its reprensentation is:
- l0_foo.xml
- l0_foo.py
Naming convention:
The previous format does not provide an unique name to each object, so we have
to handle it. The naming convention is pretty simple:
=> l + 'level of the object in previous format' + _ + 'name of the object'
Let's say I have on object foo on level 42 (so in level 42 in the hierarchy of the
xar format), the object will be named:
- l42_foo.xml
- l42_foo.py
Name collisions:
If two objects have the same name, the converter will add a unique number to each object.
Let's say I have two objects foo, the converter will give:
- l1_foo.xml
- l1_foo.py
- l1_foo_1.xml
- l1_foo_1.py
Main:
There is one special file : main.py
This file does not represents an object but it is the file to execute when
you want to play the behavior
StateMachine and Timeline:
Each object can have a state_machine and a timeline associated. In this case
this object take the name of the owner and appending "state_machine" or
"timeline".
Let's say I have a root box with a stateMachine and a timeline, this will give
me:
- l0_root.py
- l0_root.xml
- l0_root_state_machine.xml
- l0_root_timeline.xml
Note that StateMachine and Timeline have no .py associated, there is no code
that comes with these objects.
States:
A state machine a different state associated with it, the naming convention is
the following, let's say I have a root box with a stateMachine and three states.
- l0_root.py
- l0_root.xml
- l0_root_state_machine.xml
- l0_root_state_0.xml
- l0_root_state_1.xml
- l0_root_state_2.xml
Note that a state has no .py associated either.
The loader will load only file needed in the behavior (i.e. presents
in the objects graph) and will leaves the others alone.
If an object that is not connected to others in present in the directory,
it will not be loaded.
XML files:
Elements:
- Box
- Timeline
- Input
- Output
- Parameter
- Resource
- ActuatorList
- ActuatorCurve
- Key
- Link
- StateMachine
- State
Box:
Attributes:
- name: name of the box
- robot: robot targeted by the behavior
- id: id of the box
- tooltip: hint about how to use the box
- bitmap_expanded: FIXME
- plugin: FIXME
- x: x coordinate of the box
- y: y coordinate of the box
- bitmap
Input:
-> Same has the xar format
Output:
-> Same has the xar format
Parameter:
-> Same has the xar format
Timeline:
Attributes:
- enable:
- 0 -> disabled
- 1 -> enabled
- name: timeline name
- fps : Frames per seconds
- resource_acquisition:
- 0 -> Passive
- 1 -> Waiting
- 2 -> Aggresive
- size: FIXME
- start_frame: first frame
- end_frame: last frame
- scale : FIXME
Inner-Elements:
- ActuatorList
- watches : FIXME
ActuatorList:
-> Same has the xar format
ActuatorCurve:
-> Same has the xar format
Key:
-> Same has the xar format
Resource:
-> Same has the xar format
StateMachine:
Attributes:
- State : state in this stateMachine
- InitialState : initial state in the stateMachine
- FinalState : final state in the stateMachine
- Transition : a transition between two states
State (in the stateMachine file):
Attributes:
- Name : name of the state
InitialState
Attributes:
- Name : name of the state
FinalState
Attributes:
- Name : name of the state
Transition
Attributes:
- From : name of the from state
- To : name of the to state
State (in its own file):
Attributes:
- Object : object in the state
- Interval : begin and end frame of the state
- Label : name associated to state
- Link : a connection between two objects
Object:
Attributes:
- Name : name of the object
Interval:
Attributes:
- begin : first frame in the state
- end : last frame in the state
Label:
Attributes:
- Name : name associated with the state
Link:
Attributes:
- inputowner : name of the input object
- outputower : name of the output object
- indexofinput : name of the input
- indexofoutput : name of the output
Objects in their own .xml files:
- Box
- StateMachine
- State
- Timeline