= Code Python Players =
rUNSWift high level behaviours are scripted in Python and located in <nowiki>robot7/PyCode</nowiki>
== Important files ==
* Behaviou.py is the file referenced directly by {{{PyEmbed.cc}}}, which calls Behaviou.processFrame. See CodeControlFlow.?BR
* Player.py loads a player (set by [wiki:spip spip]) and calls {{{decideNextAction}}}?BR
* Global.py is used for communication between C++ and Python - we use shared memory in the form of globals?BR
* Constant.py holds constants?BR
* Reload.py is used to reload uploaded files dynamically. It's generated by SimpleRoboCommander.?BR
* !VisionLink.py contains stubs for talking with C++ code?BR
* !HelpMath
* !HelpTrack
* Help...
* !WalkAction
* !HeadAction
* ...Action
== Structure of behaviours ==
To promote code reuse and make writing of new behaviours easier we have a hierarchical structure for behaviours. The structure is somewhat reminiscent of a three-layer agent architecture but the boundaries will doubtless be blurred. Ideally each layer accepts commands from the next higher layer, and executes commands on and gets feedback from the next lower layer.
=== Atomic actions ===
The Python behaviours communicate with the actuators by setting atomic actions to be performed. Atomic actions are implemented in C++. Atomic actions include walking steps, kicks and head movements and are actions that cannot easily be broken into smaller parts, and usually must run to completion.
=== Actions ===
Actions are very similar to atomic actions and will often have a one-to-one correspondance, but actions are a Python behaviour concept only. Actions are short, simple procedures with no feedback (the lowest layer of a three layer architecture) and may include simple functions to abstract away details of actuator positions. <nowiki>Examples include walk actions (normal walk, elliptical walk, stop, ...), kicks, open mouth, grab action.</nowiki>
Actions may be found under {{{PyCode/actions}}} with mulitple related actions grouped into a few files. The interface to an action is the {{{performX(...)}}} method, where {{{X}}} is a descriptive name of the action. The method may take optional parameters, but as few as possible, and all must have a default value. For example !WalkAction.py might have methods {{{performNormalWalk(forward = MAX, side = 0, turn = 0)}}} and {{{performStop()}}}
=== Skills ===
A skill is a more complex procedure that may be reactive to the robot's environment, but useful in many different roles. Skills are similar to the middle layer of a three layer architecture, with tight feedback loops. Skills might include find ball, track ball/object, walk to a point, get behind ball, bird of prey, grab ball, aim a kick, dribble, pass, receive, block... Skills may include other skills in a recursive fashion. For example grabbing might require that the ball is first tracked and approached, both skills in their own right.
Note that grab appeared both in skills and actions. The grab action refers simply to moving the head and paws to the position that holds the ball. The grab skill includes approaching the ball to just the right distance and then executing the grab action. The skill has feedback (vision), the action doesn't.
Skills may be found under {{{PyCode/skills}}} with multiple relates skills grouped into a few files. The interface to a skill is the {{{performX(...)}}} method, where <code>X</code> is the name of the skill. The method may take optional parameters, but as few as possible, and all must have a default value.
=== Roles ===
A role is a continuous behaviour that incorporates planning to look ahead and uses skills to achieve some goal. Roles are similar to the highest layer in a three layer architecture. Roles for a forward might include striker, winger, supporter or defender. A player will adopt different roles throughout the game depending on the game state.
Roles are found in individual files directly under !PyCode. The interface to a role is the {{{decideNextAction()}}} method, which takes no parameters.
=== Behaviours ===
Top level behavious (currently forward and goalie) serve mainly to communicate tactics among the dogs and chose an appropriate role.
Top level behaviours are found in individual files directly under !PyCode and contain the modules that should be set with [wiki:spip spip]. The interface to a behaviour is the {{{decideNextAction()}}} method, which takes no parameters.
== Tactics ==
The more abstract concept of a tactic is shared among multiple dogs and not expressible in a Python file. See StrategyAndTactics.