This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Buho's profile picture

Tips for writing a decentralized, self-knit swarm

Started by Buho, 17 January 2014 - 07:08 AM
Buho #1
Posted 17 January 2014 - 08:08 AM
Hey all.

I'm trying to write a "megaturtle" program, where 64 wireless mining turtles in a 4x4x4 pattern move together as one unit, the facing side digs, and advanced inventory management (using inner turtles for extra storage). Ideally, I'd like to have them simply run off of the startup program and listen to the rednet for instructions from a controller computer, or perhaps entering in commands from one of the turtles in the swarm and the command is then retransmitted to the rest. A "turnRight" would turn all the turtles but the "digging" turtles would change.

One brain-warping experience I'm having is the single startup program I'm writing will be run simultaneously by all turtles, including the one sending messages and (conceptually) receiving the same message simultaneously.

Right now I'm trying to get all the turtles to register themselves in the configuration so they know what part of the cube they are in and what direction they are facing). I'm realizing, I think, that I need a very robust messaging system that can receive, process, and relay rednet messages without overloading the "airspace" (e.g., preventing infinite loops of relayed messages).

I've never written anything like this before. Any suggestions or tips or URLs to helpful theory?
Moody #2
Posted 17 January 2014 - 12:08 PM
Hey!
That depends on what you wanna do with your network.
First thing what you wanna do is probably creating a network that does not rely on a master server.
There are several ways to do this and if you want to stick with the most used ones, you should look into meshed networking
(There is also a cc api here on the forums http://www.computercraft.info/forums2/index.php?/topic/14794-somewhat-common-routing-framework-v31-mesh-networking-protocol-thing/ )
For Storage, you can look up SAN ( http://en.wikipedia.org/wiki/Storage_area_network - the first pdf is rather indepth and i suggest this for implementations sake)
To get them working on a subject without a master can be quite tricky. I would suggest you use ANN methods ( http://en.wikipedia.org/wiki/Artificial_neural_network ) and conventional methods (for better performance). eg use LVQ or SOM - or even (Growing)NeuralGasses).
There are most definitly other implementations (like "Smart Agents"-style stuff) but im not to familiar with them.
I have to admit, getting into this is rather difficult - that is if you dont want to have a master server.

If you dont mind to have a master, it shouldnt be too hard (in principle :P/>). There is already an api ( http://www.computercraft.info/forums2/index.php?/topic/13170-swarm-api/ ) so maybe you can take some inspiration from there ;)/>
Buho #3
Posted 17 January 2014 - 12:51 PM
Awesome! Thanks, Moody! This is a lot to dig into. Yeah, I'm itching for the challenge of a decentralized network and your links will help me dive right in!
Bomb Bloke #4
Posted 17 January 2014 - 08:51 PM
The way I would do it would involve having the turtles form an initial cube in an order based on each turtle's ID. Each turtle would boot and perform a GPS lookup. It'd then add its ID to a new table, broadcast that table and then sit and wait for messages from other turtles doing the same.

Every few seconds the turtle would repeat its transmission. When receiving transmissions from other such turtles, it'd merge their tables with its own. Once it had a full table it'd transmit it one more time (to ensure every other turtle had access to a full copy).

The turtles would then move into formation in order of ID, each broadcasting when it's in place to signal the next to move.

When an order is given, this is also transmitted on a single channel which all turtles listen to. In the event that it's something simple, like a dig or turn operation, the relevant turtles simply perform it and that's that.

For movement, however, I'd take advantage of redstone signals. Have each turtle constantly transmit one out of its front, back, top and base. When given a command to move, each turtle does so as soon as it no longer detects a redstone signal from the direction in which it's supposed to go. This should keep the timing of actions very simple (and you could also use it to very quickly determine which turtles are supposed to be digging/placing/whatever, too…).

I'm not sure under what circumstances you'd want to "relay" anything.