{'fraction_non_alphanumeric': 0.03113375985716411, 'fraction_numerical': 0.005579526856122601, 'mean_word_length': 4.488975091874234, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 2, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Synchronous Robotic Framework

We present a synchronous robotic testbed called SyROF that allows fast implementation of robotic swarms. Our main goal is to lower the entry barriers to cooperative-robot systems for undergraduate and graduate students. The testbed provides a high-level programming environment that allows the implementation of Timed Input/Output Automata (TIOA). SyROF offers the following unique characteristics: 1) a transparent mechanism to synchronize robot maneuvers, 2) a membership service with a failure detector, and 3) a transparent service to provide common knowledge in every round. These characteristics are fundamental to simplifying the implementation of robotic swarms. The software is organized in five layers: The lower layer consists of a real-time publish-subscribe system that allows efficient communication between tasks. The next layer is an implementation of a Kalman filter to estimate the position, orientation, and speed of the robot. The third layer consists of a synchronizer that synchronously executes the robot maneuvers, provides common knowledge to all the active participants, and handles failures. The fifth layer consists of the programming environment.


Introduction
In natural disasters, the response time for the search-and-rescue team is a critical factor to minimize the casualties. A swarm of robots, e.g. drones can be used to concurrently sweep the region to minimize the response time without risk to the search-and-rescue team [12]. Some researchers have followed a centralized approach where the robots are supervised and operated from a central control [5], [2]. However, these solutions are not scalable and are prone to failure. More robust solutions focus on fully autonomous systems, where the robots self-coordinate their actions without the help of preexisting infrastructure [1]. However, the implementation of these systems requires an interdisciplinary team with expertise in robotics, distributed systems, wireless sensor networks, etc, making the systems accessible only for experienced research teams. In this paper we present a testbed, called Synchronous Robotic Framework (SyROF), that gives access to undergraduate computer science/engineer at California State University Long Beach to rapidly implement and demonstrate robotic swarms. In essence, SyROF provides the look-compute-move model proposed by Suzuki and Yamashita in their seminar paper [14]. In our framework, robots broadcast their state infinitely often. Then, every participant robot obtains the state of every other active robot using a membership service, which can be used to compute its next movement. In the look-compute-move model, we can distinguish two main variants: 1) the fully synchronous FSYNC, where all robots start the cycles at the same time [6], and 2) the asynchronous ASYNC, where no assumption is made about the cycles. We choose to implement FSYNC to reduce the complexity of implementing cooperative algorithms. The power of the model has been shown in [3], [18], [17]. However, SyROF can also be used to implement the asynchronous variant. We implement a synchronizer to execute the synchronized cycle. In FSYNC every robot has common knowledge, i.e., every robot knows that every other robot knows, and so on, the state of the participant robots. Thus, the output of any deterministic function is identical in all robots. However, their output can be conflicting if robots do not attain common knowledge. We consider wireless networks where messages can be dropped at any time which makes it impossible to attain common knowledge deterministically. To overcome the impossibility, we consider the stream consensus protocol proposed by Morales-Ponce et al., [8] that guarantees common knowledge at almost every time with period of disagreement of bounded length.
In this paper we describe the design of SyROF testbed that consists of multiple assorted mobile robots including omnidirectional robots, drones and rovers. Each robot is equipped with a microprocessor, a gyroscope/accelerometer sensor, a flow sensor, a GPS like sensor and a Bluetooth chip. We design and implement a real-time publishsubscribe system as a base system. Then we design and implement a Kalman filter to compute the state of the robot that reduces the noise of the sensory data. Then we implement a synchronizer to synchronize the task of the robots. On top of the synchronizer, we implement a programing interface, called virtual machine, that allows implementing Timed Input/Output Automata. The main software architecture is shown in Figure 1. Our design allows adding external sensors such as small computers for more complex applications.  The paper is organized as follows: in Section 2, we present the architecture of the robots. The formal requirements of the system are then presented in Section 3, fol-lowed by the related work in Section 4. We present the design for the real-time publishsubscribe system in Section 5, then we present the design of the Kalman filter in Section 6 and the membership service and synchronizer in Section 7. The programming interface is presented in Section 8. Finally, we conclude the paper in Section 9.

Robot Architecture
We design the main components of the system to be compatible with different robotic models. Currently, we have built the testbed with omnidirectional robots that are able to move in any direction without rotations. However, the components and software were designed to support different robot models, such as rovers that can rotate and move forward and backward, non-holonomic mobile robots, drones, etc.
The main components of SyROF are implemented in a Cortex M4 with a real rime operating system. In particular, we use Teensy 3.2 and FreeRTOS for the omnidirectional robots that allows executing tasks in bounded time. SyROF uses different sensors to compute the robot's state. Namely, an MPU-9265 (Inertial Measurement Unit or IMU) to obtain the robot's orientation, a PMW390 (optical flow sensor) to compute the distance traversed by the robots, an NRF51822 (bluetooth module) to communicate and a DWM1000 (an ultra-wide band sensor) to compute the robot's absolute position. SyROF also controls all the actuators. To simplify the connections, we design a printed circuit board (PCB) depicted in Figure 2. Many robotic applications can be enhanced with the use of computer vision and machine learning algorithms. However, these algorithms require more computational power. Hence, we design the system to be highly configurable to include different sensors and actuators including external small computers. Throughout the paper we assume that robots are in communication range and that the clock drift of the process is bounded by a constant.

Requirements
In this section, we list the main functional requirements of SyROF.
-Provide a membership service. In robotic swarms, every robot needs to be aware of every other robot that is participating in the system. This requirement adds dynamism to the system by allowing robots to join and leave at any time.
-Synchronize robotic primitives. The time to complete a maneuver (or primitive) is non-deterministic due to inaccuracies in the actuators and sensors, battery levels, etc. Robots should synchronize primitives to provide the look-compute-move FSYNC model. -Provide common knowledge infinitely often, even with communication faults. Common knowledge is attained when every robot knows the state of all participant robots. If all robots communicate successfully, they must switch to cooperative mode and provide their state including position, speed, intentions, etc., to every other robot. If any robot does not receive the message of at least one robot, all robots must switch to autonomous mode. -Provide a high level programming environment to implement cooperative robotic systems using Timed Input/Output Automata (TIOA). The programming environment should provide instructions to control the actuators, read sensory data, provide complex queries.

Related Work
Testbed for lowering the entrance barrier to multi-robot systems have been proposed previously, see for example [9], [13], where the the authors present a testbed, called GRITSBot and Kilobots, respectively, using inexpensive robots. In GRITSBot, a central server is responsible for executing the code in each robot. Moreover, it requires a precise tracking system to determine the position of each robot. Thus, user can design and test robotic synchronous system. However, any failure in the server affects the whole system. Unlike GRITSBot, in SyROF all the robots have the same role and, therefore, there is no single point of failure. In the Kilobot testbed robots asynchronously runs its own code. However, those robots do not have enough computational power to estimate their positions. Unlike Kilobots, our proposed testbed, robots can estimate their own position and synchronize the primitives. Another closely related framework is ROS (Robot Operating System) [11]. A system built using ROS consists of several processes connected in a peer-to-peer topology. ROS has been very successful and many packages for a great variety of applications are available including SLAM (Simultaneously Localization and Mapping). However, ROS does not provide support to synchronize robotic primitives nor common knowledge guarantees. Our framework provides a new high-level platform-independent programming language that provides users with synchronous executions of robotic primitives and common knowledge in realtime. Moreover, SyROF can be integrated with ROS to extend its functionalities without compromising the realtime execution.
Our synchronization mechanism is based on consensus among all robots. Many papers have based their systems on consensus where processes need to agree on specific tasks [4,?,?]. Another approach is to use of tuple spaces. Processes insert tuples in a common space that can be read by every process [10], but, there is no guarantee that a process is able to read.

Real-Time Publish-Subscribe System
In this section we present the design of the real-time publish-subscribe system that simplifies the implementation of robotic systems. The publish-subscribe system can be logically separated into three parts-the Broker, Publishers, and Subscribers as shown in Figure 3. Each process can be either publisher or subscriber or both.
-The Broker. The main functionality of the broker is to disseminate data from the publisher to subscribers that are interested in the topic. Thus, it plays a key role for the expected functionality of the system. Publishers register through the Broker using unique identifiers and subscribers subscribe to the publisher with the Broker using the identifiers. It is assumed that identifiers are unique.  -Publishers. They are dedicated to produce data without knowing which processes consume it. For example, publishers can read data from sensors, execute an algorithm to filter data, etc. When a publisher is created, it registers as publisher using a unique identifier. When data ready, it notifies the broker. -Subscribers. They are dedicated to consume data. When a subscriber is created, it subscribes to the topic that it is interested in using their unique identifier. It can subscribe to more than one topic. When a publisher publishes the data, the broker notifies all the subscribers that have declared interest in it. Subscribers can also play the role of publisher.
In this paper we report the implementation in FreeRTOS. However, the design can be also implemented in other real-time operating systems. FreeRTOS is based on coroutines to emulate a multiprocessor system. Essentially, a co-routine can have multiple entry points and maintains its state between activations. In FreeRTOS, each process executes a task that does not return during the execution of the program. To switch to other tasks, an operating system method must be invoked such as vTaskDelayUntil, vTaskDelay, etc. Since we are interested in providing a system for time-critical applications, each task must complete a step of computation in bounded time.

Broker Interface
The real-time publish-subscribe system interface is presented in Interface 1 which consists of three methods -registerPublisher. Register a publisher into the real-time publish-subscribe system using a unique id. First, the publisher task instantiates a FreeRTOS queue using the operating system method xQueueCreate and passes the handler to the system as well as the size of the tuple. The Broker inserts these values into a list of publishers. The function returns the handler (index) of the publisher which is later used to publish new data. subscribe. Register a subscriber to a given publisher. Before the subscriber calls subscribe, it creates a task and a queue that stores the publisher produced tuple. In FreeRTOS, xCreateTask and xQueueCreate are used to create the task and the queue, respectively. These values are passed as parameters to the function subscribe and the Broker inserts these two values into a publisher queue. publish. Publishers use the function publish to publish new data. To avoid blocking, the broker notifies the main broker task. When the broker receives the notification, it reads the data from the publisher using the queue handler and then copy it to all the subscribers using their queue handlers.

Kalman Filter
In this section we present the implementation of the Kalman filter [7]. The Kalman filter estimates the state of the system in real-time from noisy sensory information, assuming that the noise follows a Gaussian distribution. The Kalman filter is critical for the correct functionality of our testbed. Sensors suffer from errors occurring due to many reasons. For instance, GPS sensors might suffer deviation while the device does not have a direct sight-of-view to the satellite. Furthermore, odometric values must be accurate to determine the actual position of the vehicle.

Kalman Filter Design
Let ∆ be the rate at which the Kalman filter runs and X(t) = (x(t), y(t),ẋ(t),ẏ(t), θ (t)) be the robot's state at time t where x(t) and y(t) are the absolute position,ẋ(t) anḋ y(t) are the speed and θ (t) the orientation of the robot. Since the current state only depends on the previous state, we omit t. Let P be the covariance matrix of X at time t. P represents the uncertainties in the current state. Let u a be the motor thrust and u θ be the steering angle. Based on the dynamic model, we can compute the new state as follows: x It can be simple written asX = f (X) + f (U). Let J be the Jacobian matrix of f (X) and Q be the covariance matrix representing the process noise. The estimation of covariance matrix at time t + 1 is defined asP = FPF T + Q.
Let Z = (gyro z , f low x , pos x , pos y ) be the sensor readings at time t. Let R be the covariance matrix measuring the noise. We use the following equations to deduce h(X).
f low x =x f low y =ŷ pos x =x pos y =ŷ gyro z =θ Let F be the system state matrix. We can summarize the Kalman filter as: Step correction

Implementation
We implement the described Kalman filter using the real-time publish-subscribe system. Thus, we create dedicated tasks for each sensor. Namely, IMU that consists of reading the gyroscope/accelerometer data, optical flow that reads the offset between two consecutive images and ultra-wideband that reads the ranging between the sensor and the fix stations. We register these tasks as publishers and publish the data at the updated refresh time. The core of the Kalman filter is implemented using two tasks:  measures the lateral velocity of the sensor in both directions, that is δ x and δ y . The effective viewing angle of the sensor θ is assumed to be equal to 25 • . Since there will be a slight orientation in the sensor's axis we are adding an angle α to be the angle of orientation. Let h be the height of the sensor from the ground.
Observe that β = π − θ 2 − α and a + x can be calculated using β as we already know the height of the sensor. That is, a + x = h cot(β ). The Flow Breakout sensor measures the lateral velocity in pixels per second. The number of pixels in the x and y axis of the image frame is 30 each. Therefore, the normalized speed is x = h cot(β )−a 30 . (c) DWM1000 (Ultra-wide band): The sensor returns the distance to a fixed number of anchors. An anchor is a station at a well known position. We compute the position using simple trigonometry. We consider four anchors with a layout depicted in Figure 5 where anchor a 0 , a 1 , a 2 , a 3 are located at (0, 0, 0), (1, 1, 0), (0, 1, 1) and (1, 0, 1), respectively. Let p = (x, y, z) be the robot position and let [p 1 , p 2 , p 3 ] denote the plane determined by the three points p 1 , p 2 , p 3 . Consider any two different anchors a i , a j , the line segment (a i , a j ) and its perpendicular line segment (q, p) such that q is on (a i , a j ). Observe that the perpendicular line has an angle of 45 o and dist(a i , Observe that q = (x, y) is the intersection of the perpendicular lines of (a 0 , a 1 ), (a 2 , a 3 ) in the plane XY , q = (x, z) is the intersection of the perpendicular lines  2. The Kalman task executes at a fixed rate. First it updates the state using equation 1 and 2 and then it sets high uncertainties in R for the new calculations. Recall that in the Kalman filter the weight of each sensor information depends on the uncertainties. Once a new sensory reading is completed the uncertainties matrix R is adjusted. Observe that if one step of the Kalman filter is executing without reading the sensory data, the state will be determined by the model. This approach allows the Kalman filter to handle sensors reading at different rates and reduces the maintenance time.
We show a sketch of the code that receives the data to populate the matrices Z and R. The task of the Kalman Filter is executed at the frequency of FREQUENCY KF. It executes one step of the Kalman filter, update the variables for the next step and publish the new state. After publishing the data, the matrices Z and R are reset to high uncertainties.

Membership and Synchronizer Service
In this section, we describe the protocol which allows the synchronization of Timed Input/Output Automata. We present the Algorithm as a Timed Input/Output Automata in Protocol 2. Let R = {r 1 , r 2 , ..., r n } denote the set of robots. The protocol relies on three states: PROGRESS where robots are performing a maneuver, WAIT where robots have completed the maneuver and VOT ING where robots are voting to start the next instruction. Let M i , initially set to / 0, be the set of boolean values that indicates when a robot r i has completed the maneuvers, and let v i denote the number of rounds in voting of robot r i For simplicity of presentation, we assume that every robot is aware of the rest of the robots. Later we explain how to remove this assumption. Every robot broadcasts its id, state of the automata and the number of rounds it has been in the VOT ING state.
While robots are in the state PROGRESS, they are performing a maneuver. When a robot completes it maneuver, it changes its state to WAIT and waits for the other robots to complete their maneuver. When a robot r i receives the WAIT state from robot r k , it sets a M i [k] = true. Robot r i changes its state from WAIT ING to VOT ING when ∧ n i=1 M i = T RUE or if it receives the VOT ING state from a robot r k in which case it sets v i = v k . Robot r i increases v i and when v i = K, it changes to PROGRESS, sets M i = / 0, v i = 0 and start a new maneuver. In the following theorem we show that if the number of consecutive rounds with message lost in the system is less than K, all robots start a new maneuver at the same time. We assume that all the maneuver take a bounded number of rounds and at least K rounds. Proof. We first prove that property (1) holds under the assumptions. Consider any robot r i that reaches the WAIT state. Observe that, r i remains in WAIT until it receives that all other robots are in the WAIT state since ∧ n i=1 M i = FALSE or it receives VOT ING from a robot. Therefore, the earliest time that a robot can change its state to VOT ING is when all robots are in WAIT for at least one round. Let m 1 be the round where the last robot changes its state to WAIT . Observe that there is a round in the interval [m 1 , m 1 + K] where all robots receive the message with the state WAIT , since the number of consecutive rounds with message lost in the system is less than K. Consider the first robot r i that listens the WAIT from all other robots in round m 2 ∈ [m 1 , m 1 + K]. Therefore, r i changes its state to VOT E and broadcasts v i + j in each round j ∈ [m 2 + m2 + K]. Observe that r i changes its state to PROGRESS when v i + j > K. When any other robot, say r k , receives the message from r i at any round during the interval [m 2 , m 2 + K] it changes its state to VOT ING and set v k = v i + j. Therefore, every other robot changes its state to PROGRESS when v i + j > K.
It is not difficult to see that Property (2) holds under the assumptions that the number of consecutive rounds with message loss is less than K.
Observe that from Theorem 1, robots reach a consensus to start a new maneuver at the same time. Therefore, it provides a synchronous robot system. Although one can expect that the number of consecutive rounds with message loss is less than K, in practice we can have communication faults, i.e., the number of consecutive rounds with message loss is at least K. Therefore, properties (1) and (2) may not hold. Indeed, it is known that the consensus problem cannot be solved deterministically if messages can be lost. To alleviate the problem, we consider two operation modes. Namely COOPERAT IV E mode where every robot receives the message from every other robot and AUT ONOMOUS mode where at least one robot does not receive the message from other robot. Observe that if there is a partition among the robots such that some robots are in the AUT ONOMOUS mode and others are in COOPERAT IV E mode, a cooperative robotic application may not be completed successfully or robots may collide. Therefore, the goal is to let robots agree on the operation mode. However, it is again a consensus problem and consequently there is no deterministic algorithm that can solve it. However, we can minimize the number of rounds where robots do not agree using the protocol proposed in [8]. In this protocol, when a robot does not receive a message at round r from another robot or when it receives AUT ONOMOUS operation mode from any other robot, then it changes its operation mode to AUT ONOMOUS. The robots return to COOPERAT IV E operation mode when they receive the AUT ONOMOUS operation mode from every other robot. Lemma 1. Stream Consensus [8] Robots may disagree in at most two continuous rounds.
Consider the case where robots are in WAIT or VOT ING state. Observe that if the robots change to AUT ONOMOUS operation mode due to message loss, then it is safe to start the next maneuver when they change to COOPERAT IV E operation mode. From Lemma 1, robots may start within two rounds of difference. However, when robots are in the PROGRESS state, they always send COOPERAT IV E as the operation mode and do not execute the Stream Consensus protocol. The following theorem summarizes the the previous discussion and is presented without a proof.
Theorem 2. Protocol 2 allows the robots to start a new maneuver within at most two rounds of difference. Further, all robots have common knowledge before starting a new maneuver. Now, we show how to remove the assumption that robots need to know the number of active robots. Indeed, during the PROGRESS state, robots implement a membership service. More precisely, robots maintain the set members i of participating robots that they receive messages from. Further, robots maintain the set membersInWait i of robots that are in the WAIT state. Robots broadcast membersInWait k while they are in the WAIT state. A robot decides to change its state to VOT ING when it receives membersInWait k = members i from every other robot.

Virtual Machine
In this section we present the implementation of the programming interface that is used to implement robotic applications in the framework which consists of three callback functions and one method to send messages; see Interface 3.
init. It is called when the system starts. It is used to initialize the local state of the robot. -newRound. It is called at the beginning of each application round. In other words, when the robots change their state to PROGRESS. This function allows setting the robot's commands. Application rounds are suggested to be of 1 or 2 seconds to let the robot make progress. The function receives the local dynamic map that contains Interface 3 Programming Interface 1: void *init() 2: uint8 t (*newRound)(CarCommand *command, LDMap *ldmap, uint8 t globalState, uint32 t clock) 3: uint8 t (*endOfRound)(LDMap *ldmap, uint8 t globalState, uint32 t clock) 4: void sendMessageData(uint8 t *payload) the state of all the participant robots at the end of previous round. If the operation mode in the local dynamic map is COOPERAT IV E, then all robots agree in the content of the local dynamic map. It also receives the globalState and the local clock.
-endOfRound. The function receives the local dynamic map that contains the state of all the participant robots in the end of the round, i.e., when the robot complete the maneouver. It also receives the globalState, and the local clock. The TIOA is responsible for performing the transitions of globalState accordingly. -sendMessageData. It allows to broadcast up to 9 bytes in each round.
We enhance SyROF by implementing a set of local and distributed queries to simplify the design of cooperative robotic applications: -NumberOfMembers. Returns the number of active members performing the current primitive. -Leader. Returns the leader defined as the robot with minimum id.
-ShortestEnclosingCircle. Returns the center and the radius of the shortest circle that contains all the robots. -ConvexHull. Returns the list of active robots in the convex hull.
-MinWeightedMatching. Given a set of points, it returns the matching point for each robot that minimizes the maximum sum of distances from each point to its destination.

Conclusion
In this paper, we present the current work on SyROF, a testbed that allows undergraduate students to implement and demo collaborative robotic applications. SyROF provides a synchronous robotic system to implement cooperative applications. We expect that the testbed lowers the barriers for the students of computer science and computer engineering at CSULB. We plan to perform extensive experiments with different robots. The implementation has demonstrated that SyROF is feasible.