I'm trying to write a script to control a worker drone. This drone will interact with plants on specific coordinates that are being fed to him by mainframe via wireless modem. I've planned to have those commands:
1. Add/remove new coordinates.
2. Print out all registered coordinates.
3. Finish the job, return to charger and wait for further commands.
4. ...
The initial solution included using two threads: a worker thread that executes requested and routine actions and a controller thread that listens for new modem messages, updates drone status and generates responses for the mainframe. The problem is - drones have no access to Thread API. I believe there should be a simple solution for this task but I don't see any suitable way to provide such level of responsiveness without proper threading.
Rough example for drone :
...
thread.waitForAny({
thread.create(function()-- Workerwhiletruedoif state =="work"thenfor _, pos in pairs(locations)do
moveto(pos)
dostuff()if state ~="work"thenbreakendendelseif state =="stop"then
sleep(5)endendend),
thread.create(function()-- Controllerwhiletruedolocal message = table.pack(computer.pullSignal())if message[1]=="modem_message"thenlocal command = serialization.deserialize(message[5])if command.text =="stop"then
state ="stop"elseif command.text =="resume"then
state ="work"endend}})
I am sure somebody already did this kind of stuff on their server, I just can't come up with anything effective and simple without surpassing the 4KiB threshold. Do you have any suggestions?
Multithreading in drones
in Programming
Posted
I'm trying to write a script to control a worker drone. This drone will interact with plants on specific coordinates that are being fed to him by mainframe via wireless modem. I've planned to have those commands:
1. Add/remove new coordinates.
2. Print out all registered coordinates.
3. Finish the job, return to charger and wait for further commands.
4. ...
The initial solution included using two threads: a worker thread that executes requested and routine actions and a controller thread that listens for new modem messages, updates drone status and generates responses for the mainframe. The problem is - drones have no access to Thread API. I believe there should be a simple solution for this task but I don't see any suitable way to provide such level of responsiveness without proper threading.
Rough example for drone :
I am sure somebody already did this kind of stuff on their server, I just can't come up with anything effective and simple without surpassing the 4KiB threshold. Do you have any suggestions?