Repository navigation
Architecture
Octopus Controller is built around a separation between intention, local control and coordination.
The central controller can tell an arm what it should try to achieve, but it does not calculate the angles of every joint or prescribe a complete movement. Each arm retains its own state and uses local rules to work towards its objective. Sensing, obstacle avoidance, hazard response and grasping can all modify what happens along the way.
A further layer becomes important when those local responses can no longer coexist comfortably. Hazard reports can escalate, different arms can compete for the same resource, and safety may need to override an existing task. Conflict resolution therefore operates above the local movement rules without replacing them.
The architecture can be thought of as a progression:
central intention
↓
individual arm
↓
local movement and sensing
↓
environmental response
↓
significant information reported upwards
↓
arbitration when priorities conflict
↓
revised arm behaviour
This separation is fundamental to the project.
It allows the simulator to explore how much useful behaviour can arise within the arms themselves, while still providing somewhere for genuinely shared problems to be resolved.
The desktop application uses Python and Pygame Community Edition. The simulation itself is kept separate from the graphical interface, and the browser-based Octopus Explorer implements the same underlying behaviours in JavaScript.
At the highest level, the simulator follows this flow:
flowchart TD
Input[User or scenario assigns objectives] --> Central[Central Controller]
Central --> Arm[Individual Arm Controller]
Arm --> Reach[Local Reach Controller]
Arm --> Sense[Local Sensing]
Arm --> Grip[Grasping and Carrying]
Reach --> Segments[Neighbour-to-neighbour movement rules]
Reach --> Obstacles[Obstacle steering and safety checks]
Reach --> Hazards[Hazard response]
Sense --> Signals[Hazard reporting and escalation]
Hazards --> Signals
Signals --> Arbitration[Conflict Resolution]
Arm --> Arbitration
Arbitration --> Arm
Arm --> State[Current arm and object state]
State --> View[Desktop or Web Presentation]
The diagram shows responsibility and information flow, rather than a literal sequence of module imports.
The important distinction is that the central controller does not reach down into an arm and calculate its joints. It supplies objectives and receives significant information. The detailed movement remains the responsibility of the arm and its local controllers.
All eight arms currently run within one simulation process and are updated in a stable order. Their independence comes from maintaining separate state and applying local rules, not from running on separate processors or threads.
The architecture can be understood at several levels.
| Level | Main responsibility |
|---|---|
| Application | Runs the simulation, accepts input and presents the current state |
| Central controller | Assigns objectives, coordinates shared concerns and receives significant reports |
| Individual arm | Maintains its task, sensing, grasping and local behavioural state |
| Reach controller | Turns an objective into constrained local movement |
| Individual segments | Exchange neighbouring movement requests and obey joint limits |
| Hazard signalling | Decides when local hazard information matters beyond the arm |
| Conflict resolution | Arbitrates incompatible priorities and shared-resource claims |
| Presentation | Displays state without determining simulation behaviour |
Keeping those responsibilities separate makes the behaviour easier to reason about.
A change to obstacle steering, for example, should not require the rendering code to understand collision geometry. Likewise, changing how conflicts are resolved should not require the low-level segment controller to know why a particular objective has priority.
The central controller is responsible for the things that genuinely need a shared view of the simulated animal.
It knows that there are eight arms, routes assignments to them and advances them through the same simulation time. It also deals with concerns that cannot safely be left to each arm in isolation, such as exclusive ownership of captured food and arbitration when several arms or behaviours make incompatible demands.
What it does not do is equally important.
It does not calculate a complete arm pose.
An instruction such as:
Arm 3:
reach this position
describes an objective rather than a movement program.
The arm decides how to attempt it.
This distinction between assigning an intention and working out the movement is the central architectural idea behind Octopus Controller.
Every arm maintains its own activity, geometry, local movement requests, contact observations and grasping state.
An arm may therefore be:
- reaching towards a destination;
- responding to an obstacle;
- recoiling from a hazard;
- making contact with food;
- establishing a grasp;
- carrying an object;
- yielding to another arm;
- withdrawing from danger;
- or remaining idle.
Other arms can simultaneously be doing something entirely different.
The arms inhabit a shared environment, but they do not share one global movement state.
That allows the simulator to explore the idea that coordinated whole-animal behaviour does not necessarily require every component to be centrally micromanaged.
A reach begins with an external destination, but that destination is not broadcast independently to every joint.
Instead, the target is supplied to the final segment at the tip.
That segment asks where its attachment point would need to move in order to improve its own position. The resulting request is passed to the neighbouring segment closer to the body, which performs the same kind of local reasoning.
Information therefore travels progressively along the arm:
external target
↓
tip segment
↓
requested attachment position
↓
next segment
↓
requested attachment position
↓
...
↓
base-side segment
The arm's final shape emerges from these repeated neighbour-to-neighbour exchanges together with segment lengths, bend limits and turning-speed limits.
The central controller specifies where the arm should ultimately reach.
The local controller works out which constrained adjustments might move it in that direction.
Movement becomes more interesting once the arm can respond to what it encounters.
Each segment has a small local sensing region. These sensors report immediate contact with objects in the current pose rather than detecting food or hazards globally on behalf of the whole animal.
That distinction matters.
A segment touching something has acquired local information. It has not automatically created a new objective.
Food contact may contribute towards establishing a grasp. Nearby obstacles may alter local movement. Hazards may provoke avoidance or recoil.
Most of those responses can happen without the central controller changing the arm's original task.
This creates another useful architectural separation:
Sensing something is not the same as deciding that it should become the new goal
Obstacles are physical constraints.
Local steering attempts to redirect movement around them, but a second geometric safety check decides whether the proposed movement can actually be accepted.
These two mechanisms have different jobs:
local steering
→ proposes a useful detour
movement safety
→ decides whether the proposed motion is allowed
The safety check examines more than the final pose because a segment could cross an obstacle while moving between two apparently clear positions.
The calculation is deliberately conservative. If the controller cannot be sufficiently confident that the whole movement clears the obstacle, the proposed pose is rejected and the arm remains where it was for that update.
This means the architecture favours a temporarily blocked arm over one that is allowed to pass through solid geometry.
Hazards represent a different problem.
They do not make a part of the environment physically inaccessible. An arm could enter a hazardous region, but local control should prefer not to.
Hazard response therefore introduces an aversive influence:
target
→ move towards this
hazard
→ move away from this
A mild encounter may simply redirect movement.
A stronger encounter can produce an explicit recoil before avoidance continues.
After leaving sensing range, the response does not necessarily disappear immediately. A brief reassessment period gives the arm time to establish that the hazard has genuinely been cleared rather than switching rapidly between reaching and avoidance at the edge of the detection boundary.
Hazard movement remains local for as long as possible.
That raises the next architectural question:
When does local information become important enough to involve the wider controller?
Hazard movement and hazard reporting are deliberately separate.
An arm can respond to a hazard without necessarily informing central control.
Conceptually:
mild encounter
→ handle locally
significant encounter
→ respond locally
→ report upwards
serious encounter
→ request withdrawal
critical danger
→ may affect all arms
Detection and exposure are also distinct.
An arm can become aware of a hazard while it is still outside the actual hazardous region and begin avoiding it before entry. Exposure is recorded only when part of the arm penetrates that region.
Sustained exposure can itself become significant. A hazard that was initially manageable may warrant escalation if the arm remains exposed for long enough.
Once a significant report has been raised, it is not forgotten immediately after a single clear update. The report remains active until the arm has stayed clear long enough for the encounter to be considered resolved.
This keeps transient changes in sensing from repeatedly creating and cancelling central priorities.
Escalation introduces information that may compete with existing intentions.
An arm may be trying to reach food while hazard avoidance tells it to move away. One arm may be holding an object while another reports critical danger. Several arms may attempt to claim the same resource.
At that point the problem is no longer simply:
How should this arm carry out its objective?
It becomes:
Which objective or response should take priority?
Conflict resolution is therefore a separate architectural layer.
It receives concise intentions and reports, not joint geometry.
The resolver does not calculate how an arm should bend or how it should retreat. It decides which broad action currently wins, then returns that decision to the arm's existing control mechanisms.
The current implementation uses deliberately simple fixed priorities.
Broadly:
critical withdrawal
↓
local safety / hazard avoidance
↓
valid existing ownership or grip
↓
assigned task
↓
incidental opportunity
The purpose is transparency rather than sophisticated planning.
The simulator should make it possible to understand why one behaviour won.
Food introduces another kind of conflict because several arms share one environment.
Once an arm owns a captured object, another arm cannot capture it simultaneously.
When several arms compete for an unowned resource, deterministic rules choose a winner. Existing ownership takes precedence, followed by an eligible previous winner and finally stable arm ordering.
A losing arm yields, but yielding does not necessarily erase its underlying task.
If the resource later becomes available again, the arm may once more become eligible.
Safety also remains active while an arm is yielding. Arbitration over food does not prevent the arm from responding to hazards.
This is important because resource arbitration and environmental safety operate at different levels of priority.
The controller also distinguishes between an arm explicitly assigned to a particular food object and an arm merely reaching towards a coordinate.
An explicit food assignment remains tied to that object. Encountering another item on the way does not silently replace the task.
A coordinate-only reach can remain more opportunistic and may grasp suitable food encountered there.
This distinction supports a broader principle of the architecture:
Local discovery can influence behaviour without automatically replacing an explicit intention
Grasping begins locally.
Two neighbouring segments must remain in contact with the same available food object for the required interval. During that time the arm holds its pose.
If the contact persists, a grip is established.
The resulting attachment is deliberately simple: the food is treated as rigidly connected to the arm rather than modelling sucker forces, friction or deformable wrapping.
Once food is attached, a carrying objective refers to the centre of the food object rather than merely the arm tip.
The reach machinery still performs the movement, but the effective question changes from:
move the tip here
to:
move the held object here
The carried object also has to clear obstacles. A movement that is safe for the arm itself may still be rejected if the payload would collide.
A withdrawal decision does not replace the entire movement system with a special animation.
Instead, it supplies a temporary destination near the arm's attachment to the body and lets the normal constrained movement machinery attempt to reach it.
If an arm is holding food and withdrawal takes priority, the grip may first be released.
Critical danger can broadcast withdrawal to all eight arms.
Even then, the instruction remains an intention rather than a guarantee.
An obstacle may prevent one or more arms from retreating successfully. In that case the controller can attempt smaller safe subsets of the proposed joint movements, allowing parts of the arm to escape while others remain constrained.
“Whole-animal withdrawal” therefore means that all arms receive the withdrawal priority. The simulated body itself remains fixed.
The complete update cycle can be understood conceptually as:
advance shared simulation time
↓
refresh local sensing
↓
process hazard reports
↓
collect arm intentions
↓
resolve conflicts
↓
apply resulting objectives
↓
update each arm's local behaviour
↓
process grasping and carrying
↓
refresh observations from final scene
The stable update order makes experiments reproducible.
It also means that changes made by one arm can become visible to another later in the same simulation step. If an earlier arm moves a food object, for example, a later arm encounters that object's updated position.
The final sensing refresh ensures that the observations shown to the user correspond to the resulting scene rather than an intermediate state.
The model advances using fixed simulation steps.
This is important because many behaviours depend on simulated duration:
- neighbour requests moving along an arm;
- grasp dwell time;
- recoil duration;
- sustained hazard exposure;
- clearance intervals.
Playback can be made visually faster without making each individual solver step larger.
This preserves the order and behaviour of the underlying rules while changing how quickly the experiment is watched.
Pausing stops normal simulation advancement. Scene changes can still refresh sensing so that the displayed contacts remain meaningful, but timers and movement do not advance simply because the user edits the scene while paused.
The graphical layers read the simulation state; they do not decide it.
The desktop application and browser explorer can display:
- arm objectives;
- contact observations;
- grasp ownership;
- hazard reports;
- conflict outcomes;
- movement restrictions;
- significant events.
But drawing those states does not alter the arm's geometry, select a winner or assign a task.
This separation is deliberate.
It allows the same underlying model behaviour to be presented differently on desktop and web without creating different simulations.
The two interfaces need not look identical to remain behaviourally equivalent.
The implementation reflects the conceptual divisions above.
| Area | Principal responsibility |
|---|---|
| Application | Input, fixed-step execution and presentation lifecycle |
| Central coordination | Eight-arm organisation, assignments, ownership and shared time |
| Arm control | Per-arm activity, contact, grasping, carrying and withdrawal |
| Local movement | Connected arm geometry and neighbour-to-neighbour requests |
| Sensing | Environment objects and local contact observations |
| Obstacles | Steering and conservative movement-safety checks |
| Hazards | Local aversion, recoil, exposure and reassessment |
| Escalation | Reporting local hazard information beyond the arm |
| Conflict resolution | Priority arbitration and competing-resource decisions |
| Presentation | Desktop and browser rendering and event history |
| Scenarios | Reproducible starting conditions and policy settings |
The exact modules are less important than the ownership rule behind them:
Behaviour belongs to the layer that has the information and responsibility required to make that decision
A segment controller should not know about the whole scene.
The conflict resolver should not calculate joint angles.
The renderer should not change simulation state.
Keeping those boundaries clear makes the model easier to extend and, just as importantly, easier to explain.
The Python application and JavaScript explorer implement corresponding simulation layers.
Both contain equivalents of:
- local arm movement;
- sensing;
- obstacle handling;
- hazard response;
- escalation;
- arbitration;
- grasping and carrying.
The interfaces differ in presentation, but shared behaviours are tested against one another.
The goal is not pixel-for-pixel visual identity.
It is that the same experimental conditions should lead to equivalent underlying model behaviour.
New behaviour should generally be added at the level that conceptually owns it.
For example:
| Change | Appropriate layer |
|---|---|
| Different joint movement rule | Local segment / reach control |
| New obstacle response | Obstacle handling |
| New hazard behaviour | Hazard response |
| Different escalation policy | Hazard signalling |
| New arbitration rule | Conflict resolution |
| Cooperative grasping | Arm and shared coordination layers |
| New visual diagnostic | Presentation |
| New experiment | Scenario definition |
This keeps new features from leaking unrelated responsibilities across the system.
A more sophisticated conflict policy, for instance, should not require rewriting the joint solver. Likewise, a new diagnostic display should be able to inspect state without changing the outcome it is displaying.
The architecture is designed to explore distributed control, not to reconstruct an octopus nervous system.
The model therefore makes deliberate simplifications.
The body remains fixed. Arms consist of fixed-length connected segments rather than deformable muscular hydrostats. Obstacles are simplified geometry. Grasping uses a rigid attachment rather than sucker mechanics. Hazard severity is a computational signal rather than a model of pain or subjective experience.
The conflict resolver uses explicit priorities rather than learned biological decision-making, and the arms do not currently cooperate in the rich ways available to a living octopus.
Those limitations are part of the design rather than shortcomings being hidden by the interface.
They keep the architecture inspectable enough to ask the project's central questions:
How much useful behaviour can emerge from local control?
and, when local control is no longer sufficient:
What information needs to travel back upwards, and where should competing intentions finally be resolved?
The discussion above describes the simulator in terms of responsibilities rather than source files. For readers who want to follow those responsibilities into the implementation, the main architectural areas map onto the codebase as follows:
| Architectural area | Main implementation | Role in the system |
|---|---|---|
| Application and user interaction | app.py |
Runs the desktop application, handles input, advances fixed simulation steps and coordinates presentation |
| Central controller |
organism.py — CentralController
|
Coordinates the eight arms, routes assignments, maintains shared simulation time and manages shared concerns such as ownership |
| Individual arm control |
organism.py — ControlledArm
|
Maintains one arm's task, sensing, grasping, carrying, yielding and withdrawal behaviour |
| Arm geometry and reach control |
model.py — Arm, ReachController
|
Represents the connected arm and coordinates the local movement process used to pursue an objective |
| Neighbour-to-neighbour segment control | segment_control.py |
Constructs local movement requests, applies bend constraints and calculates gradual joint turns |
| Shared geometry | geometry.py |
Provides the geometric calculations used by movement, sensing, avoidance and grasping |
| Environment and local sensing | sensing.py |
Represents food, obstacles and hazards and determines which arm segments are in contact with them |
| Obstacle steering and movement safety | avoidance.py |
Redirects local requests around obstacles and checks whether proposed arm movements remain clear of solid geometry |
| Grasping and carrying | grasping.py |
Identifies valid grasps, represents attached food and checks whether carried objects can move safely |
| Local hazard response | hazards.py |
Maintains hazard detection, recoil, avoidance, exposure and reassessment behaviour within an arm |
| Hazard escalation | escalation.py |
Determines when local hazard information should be reported beyond the arm and when withdrawal should be requested |
| Conflict resolution | conflicts.py |
Arbitrates competing intentions, safety priorities and claims to shared resources |
| Scenarios | scenario.py |
Defines reproducible starting conditions, environmental objects and relevant policy settings |
| Significant-event history | activity.py |
Records presentation-level events such as captures, releases, escalation and arbitration outcomes |
| Desktop presentation | view.py |
Draws the scene, arm state and diagnostic information without changing simulation behaviour |
| Browser implementation | explorer/js/ |
Mirrors the principal simulation layers in JavaScript for the interactive Octopus Explorer |
The boundaries are not intended to imply that each behaviour belongs to only one file. Several features cross layers — grasping, for example, depends on sensing, arm state and geometry — but each area has a clear owner for the decisions that define its behaviour.