The method could be particularly advantageous in areas where safety of using robotics is a concern, for example, in driverless cars, researchers said.
It reduces human error and therefore many of the bugs that can occur in programming, making it more user-friendly and reliable than previous techniques, they said.
Researchers from the University of Sheffield in the UK applied an automated programming method previously used in manufacturing to experiments using up to 600 of their 900-strong robot swarm, one of the largest in the world.
Previous research has used 'trial and error' methods to automatically programme groups of robots, which can result in unpredictable, and undesirable, behaviour.
Also Read
Moreover, the resulting source code is time-consuming to maintain, which makes it difficult to use in the real-world.
The supervisory control theory used for the first time with a swarm of robots reduces the need for human input and therefore, error, researchers said.
They used a graphical tool to define the tasks they wanted the robots to achieve, a machine then automatically programmed and translated this to the robots.
The robots use their own alphabet to construct words, with the 'letters' of these words relating to what the robots perceive and to the actions they choose to perform.
The supervisory control theory helps the robots to choose only those actions that eventually result in valid 'words'. Hence, the behaviour of the robots is guaranteed to meet the specification.
"We are increasingly reliant on software and technology, so machines that can programme themselves and yet behave in predictable ways within parameters set by humans, are less error-prone and therefore safer and more reliable," researchers said.
This could be used in a situation where a team is needed to tackle a problem and each individual robot is capable of contributing a particular element, which could be hugely beneficial in a range of contexts - from manufacturing to agricultural environments, researchers said.
The research was published in the Swarm Intelligence journal.