Controlling Multiple Drones With Clojure and Goals and Beliefs
How to Control Multiple Drones with Clojure
The clj-drone library now has multi-drone support! You can now send multiple drones commands, receive their navigation data, and even have them perform their actions autonomously with goals and beliefs.
It takes a bit of extra setup to control more than one drone. We need to assign them each an ip and get them talking as an adhoc network. Jim Weirich creating a neat little script to run on the drone to do just this. Here are the instructions:
Change first drone to adhoc network
Connect your computer to the first drone’s network.
1
|
|
`
Create the following file as adhoc.sh. This shell script will temporarily change the network to an adhoc network named “multidrone_ah” and assign it a static ip of 192.168.1.100. The next time you reboot your drone, things will be back to normal.
1 2 3 4 5 6 7 8 |
|
`
Run the script.
Change the second drone to the adhoc network
Connect your computer to the second drone’s network.
1
|
|
`
1 2 3 4 5 6 7 8 |
|
`
Run the script.
On your laptop
- Connect to the adhoc network that the drones are on “multidrone_ah”
- Change your computer to a static ip on the network (from network preferences on mac) something like 192.168.1.101
Now you are ready to run the program. Here is a small example of sending simple commands:
1 2 3 4 5 6 7 |
|
`
Bring on Multiple Drones interacting with Goals and Beliefs
The clj-drone library implements goals and beliefs from John McCarthy’s work. The way this works is that the navigation data being constantly sent to our computer for processing. Everytime we get a navigation packet that ends up looking something like this, (but with lots more data):
1
|
|
`
We then define a belief-action using this data.
1 2 3 4 |
|
`
The def-belief-action macro takes:
- Name of the belief action
- A readable sentence that expresses the belief. (This is later logged, so that we know what the drone believes at all times.)
- A predicate that takes in the navigation data as a parameter. When it evaluates to true, then the belief is said to be “held”.
- A function to execute when the belief is held
The beliefs are then combined to form goals.
1 2 3 4 |
|
`
The def-goal macro takes:
- The name of the goal
- A readable sentence that expresses the goal. (This is later logged, so that we can know when it achieves a goal.)
- A predicate that takes in the navigation data as a parameter. When it evaluates to true, the goal is said to be achieved. It will no longer evaluate or hold any of the belief actions associated with that goal.
Finally, we can set a list of goals for a drone to achieve:
1 2 |
|
This sets the goal list for a drone. It will take-off, look around for the other drone and wave, (do a dance), once it sees it. Finally, after both drones have spotted each other and waved, they will both land.
Video or It Didn’t Happen
Here is a video of both drones. They will take off, look around for each other and wave when they spot each other. They will land when the have both waved. They are operating solely on goals and beliefs with their navigation data.
The code running the video above can be found in the examples of the clj-drone.
Happy Hacking!