Projects: Magnetic Control Architecture Project

Magnetic Control Architecture Project: The Simulation pt. I

Simulating microbot control with magnetic fields

Nicholas Roy
4 min readFeb 2, 2023

Note: If you haven’t seen my introduction to the project, you can read that here. It will give an outline to the motivations and the goals of the project. Also, all code can be found on GitHub.

What the goal was:

As I mentioned in my introduction, step one to this project is to create a simulation, where a user defined vector field can control agents that represent microbots. To begin with, as will be seen in this article, I decided to get a proof of concept — where there is one vector-valued function that controls the vector field in the entire space, and particles can move in that vector field. In part II, which I will write about in the next article, I will try to make it modular — allowing different vector fields to be represented in different regions. That is what will eventually be used in the Genetic Algorithms that find a real life electromagnetic configuration that achieves an associated magnetic field.

On my GitHub there are two programs associated with this article. One called magneticFields which was the draft of (and a 2D version of) magneticFields3D — the focus of this article.

Explanation of the program

If you wish to run the code linked above, you can download NetLogo here.

In NetLogo, you model agents (entities that can interact with their environment, usually trying to achieve a goal) and their environment. It is modelled completely discretely, with the environment split up into squares (in 2D) or cubes (in 3D) and time being separated into discrete ticks.

For this particular task, I elected to store vector field information in the individual patches, but to display them (to help when finding what field you want for real) I needed an agent type that I called vectors. I also used a distinct agent type, bots to model the microbots.

While NetLogo uses a Cartesian Coordinate System, agents are oriented using a Spherical Coordinate System. This meant, that while I could take in the vector function in cartesian terms (which is very convenient), the vectors in the vector field had to be converted into spherical coordinates which can be done with the following equations:

This screenshot was taken from this website:

In NetLogo terms, θ represents the key word heading (angle between vector projected on x-y plane and the vector [0,1,0]), and φ represents the key word pitch (angle between the vector and its projection on the x-y plane). r is simply the strength of the vector, and in my program (as well as most vector field representations) was represented by colour.

Because vector functions can also change over time, and I wanted to have that functionality, I calculated the vectors in the go function which runs once per tick, based on a user input. If the user has selected a “show-vectors?” box, I also needed to create agents to represent them and have them get the information required to draw the vectors from the patches they were on. For this I needed some global variables to transfer information between agents and patches of different types. For this I simply had the vectors ask the patch they were on what the vector was, and made them point in that direction and move forward one place. To represent their amplitude, I used colour. To find what colour to use, I scaled their amplitudes between 0 and 250, and different colours for different ranges. From low amplitude to high amplitude the colours went: (yellow, green, blue, magenta, red). Below is a demonstration:

A screenshot of the vectors of the vector-valued function f(x,y,z) = [-x,-y,-z]. You can see that all vectors point to the centre as would be expected. The red are the strongest vectors, the yellow are the weakest. The blue cube is a bot agent.

Finally, I needed to make the agents simulating microbots, called bots, move according to the vector field. To do this, I simply had the bots ask the patch they were on what direction the vector was in, and made them face that direction. I then had them go forward scaled based on the vectors amplitude. A demonstration of this can be seen in the gif below (This is of the same vector field as the screenshot above):

Looking Forward

As I mentioned before, in the next article I will make the vector field “modular”. That is to say, it should be possible to use different vector — valued functions to model different regions of the space. That is what I will eventually put into the Genetic Algorithms to find an electromagnetic configuration that generates a magnetic field as close as possible to the desired vector field.

--

--

Nicholas Roy

I am a third year BSc Artificial Intelligence student at the University of Groningen. I am primarily interested in the use of microbots/nanobots in medicine.