Network Behavior

Building a 'behavior' in the Juice universe basically amounts to assigning motion sources to joints. From the computer's point of view, the clockwork behavior and network behavior features are identical in the sense that all they do is tell the simulation engine which joints should be affected by which motion sources. From the user's point of view, you might think of a clockwork behavior as a table of numbers, and a network behavior as a pie graph. It's the same data, just a different way of looking at the numbers.

In the clockwork behavior editor, you need to think about the model's movements in terms of numbers, and lots of them. The worst part is keeping the phase relationships consistent. It's a little bit difficult to visualize that the left hip is 180 degrees out of phase with the right hip, and the left knee is 260 degrees behind the left hip... and what's the phase of the right knee, relative to the left hip? That's not hard to figure, but now imagine you're dealing with a six-legged critter in which each hip is 240 degrees ahead of the hip behind it.

I thought it would be much better if the behavior could be envisioned as a network of motion sources, simple mathematical operations, and joints. You have a motion source and a bunch of joints, and you plug them together with addition operations in between to get the phases you need. That's pretty much how I picture things in my head, so I gave Juice a user interface that works the same way...

What is a "directed graph?"

If you already know the answer to this question, you're welcome to skip to the next section.

Sometimes "graph" refers to a plane with Cartesian coordinates, suitable for illustrating simple mathematical functions like Y = mX + b. But that's not the case here. Here, a graph is a bunch of dots connected with a bunch of lines. Graphs like these happen to be useful for everything from children's coloring books to delivery van route planning to compiler design. Being so useful, there's a whole branch of mathematics devoted to the study of graphs, their properties, and their uses. In mathematical parlance, the dots are called "nodes" and the lines are called "edges." I'm a geek (did I mention that? did I need to?), so I use the node-edge terminology myself.

What are the Network Behavior graphs for?

These graphs describe the relationships between motion sources (such as the main engine, the joystick, or the orientation of a body) and the motors that move the model's joints. Designing a behavior is a matter of connecting motion sources to joints, with simple mathematical operations in between to adjust things like phase and range of motion.

What are the nodes and edges in the Network Behavior graphs?

Nodes represent motion sources (which produce numbers, mathematical functions (which alter numbers), or joints (which accept numbers, and use the numbers to set the angle of a joint in the simulation). Edges deliver numbers from one node to another. Each edge gets a numbers from a 'source node' and delivers that number to a 'destination node.'

Here's a simple graph that would allow you to recreate that famous scene from The Exorcist:

Or, if you'd like to model something a bit more family-friendly:

This one introduces the "wave" node, which turns the continuous spinning motion of the main engine into a back-and-forth motion. In this example, the kid's wrist will wave back and forth, moving 45 degrees in either direction. More about the other numbers later...

As a network behavior creator, you have six types of nodes at your disposal:

Motion Source
This node does not accept any input from other nodes, its state always comes from a motion source. You may use as many motion sources as you wish (this is a bit of an advantage of the clockwork behavior method), and each different motion source node may represent the main engine, a joystick axis, or the rotation of a beam.

The output of the main engine is expressed in degrees - it climbs from 0 to 360, then starts over at 0 and climbs again. The output of the joystick varies from -1 to +1. The rotation of a body is expressed in degrees, and varies from -90 to +90. This might sound complicated, but it's fairly intuitive if you just remember that joysticks need to be multiplied by some number to get a result in degrees.

Constant
Like motion sources, constants do not accept input from other nodes. Unlike motion sources, the value of a constant never changes. You specify the value as you design the behavior, and it keeps that value until you explicitly change it.
Arithmetic
Arithmetic nodes add up all of their inputs to produce a single number. Then the node performs a couple of simple mathematical operations to get a final result. That result is then made available for edges to deliver to other nodes.
Multiplier
Multiplier nodes do not add up all of their inputs - instead they multiply each input with the next. The product of all of these multiplications is then made available for edges to deliver to other nodes.
Wave Function
Wave function nodes add up all of their inputs, then use something like a sine operation to produce an output. With the "ramp duration" parameter, you can vary the wave function from a true sine wave (100%) all the way to a square wave (%0). At 50% you get a function just like the 'step' function in a clockwork behavior (this is idea for knee joints in most walking robots). The range and offset of the wave function can be set in degrees, so the output is suitable for connection directly to a motor node.
Motor
Motor nodes add up all of their inputs, then attempt to move a joint in the model to move to the angle indicated by the sum. I say 'attempt to move' because it will actually move to the desired position only if the joint itself has enough force available.

How to use network behaviors?

First, pick "Add Network Behavior" from the Edit menu, and click on the new behavior in the Motion window. After selecting the network in Motion window, you'll be able to create nodes by clicking on the "Create ..." items in the property view. (This will probably change in the near future, I realize that it's kind of awkward.)

You can drag the nodes around with the left mouse button. Once a node has been selected, you can edit its properties in the Properties window as you have come to expect.

To connect two nodes with an edge, right-click on the source node, drag the mouse to the destination node, and release the right button. When you release the right button, a new edge is created. Note that Motion Source and Constant nodes do not accept input from other nodes - if you try to use them as edge destinations, no edge will be created.

You can drag the entire graph around by clicking the left button in the background of the graph (not on a node or edge). If you hold the button down, the entire graph moves with the mouse.

What might a behavior network look like?

Following is the tripod gait from SimpleAnt.jm:

I'll explain later.

How are the behavior networks implemented?

Before simulation begins (and any time you add or remove an edge during simulation), the graph is 'compiled' into a series of instructions, a script of sorts. Each instruction corresponds to a node or edge in the graph, and the order of their execution depends on the arrangement of the graph.

With each frame of the simulation, the script is executed. At the beginning of the script, the motion source and constant nodes make their values available; then the edges connected to those nodes propogate those values to other nodes, and so on. When the script has finished, the joint nodes apply the appropriate forces to the joints in the model, the physics library moves all of the beams as appropriate, the 3D library renders the scene, and the cycle repeats.

The script's instructions are ordered such that each node carries out its function (be it arithmetic or wave generation or whatever) when all of its incoming edges have delivered their input. Due to this constraint, any cycles in the graph will not be executed. Consider this cyclic arrangement of nodes: A -> B -> C -> A. These nodes will never execute, because A's input from the C node will never arrive, because C depends on B, and B depends on A, which depends on C... and so on. This cycle of dependencies will never be satisfied, so none of them will appear in the script.


c o n t a c t   m e @ w h a t e v e r . n e t

Last updated Apr 23

To link directly to this page:
http://www.natew.com/juice/frames.cgi/help/html.NetworkBehavior