Waiter robot analogy

Let's continue with our waiter robot analogy to understand state machines better. Have a look at the following setup:

Waiter robot analogy

Let's try to get in-depth and list the possible tasks that need to be carried out by the robot:

  • Navigate to the tables (T1, T2, ..., and T6, as shown in the preceding diagram).
  • Take the order from the customer.
  • Go to the kitchen (and confirm with the chef if necessary).
  • Bring the food to the customer (from the delivery area, as shown in the preceding diagram).

The robot can navigate around the restaurant autonomously and reach customer locations based on the table the customer is seated at. In this process, the robot has the necessary information such as the locations of the table, delivery, kitchen, storeroom, and charging area through the map it has created. Once the robot has reached the table, let's assume that the robot takes the order from the customer through a touch-based interaction system combined with voice-based interactions.

Once the order is received, the robot sends it to the kitchen through a central management system. Once the kitchen confirms the order reception, the robot goes to the delivery location and waits for the food to be delivered. If the order is not confirmed by the kitchen, the robot goes to the kitchen and confirms the order with the chef. Once the food is ready, the robot takes the food from the delivery location and delivers it to the specific customer table. Once it is delivered, the robot goes to its standoff position or gets charged. The pseudocode for this may look as follows:

table_list = (table_1, table_2,....) 
robot_list = (robot_1, robot_2,....)
locations = (table_location, delivery_area, kitchen, store_room, charging_area, standoff)

customer_call = for HIGH in [table_list], return table_list(i) #return table number
customer_location = customer_call(table_list)

main ():
while customer_call is "True"
navigate_robot(robot_1, customer_location)
display_order()
accept_order()
wait(60) # wait for a min for order acceptance from kitchen
if accept_order() is true
navigate_robot(robot_1, delivery_area)
else
navigate_robot(robot_1, kitchen)
inform_chef()
wait(10)
wait_for_delivery_status()
pick_up_food()
navigate_robot(robot_1, customer_location)
deliver_food()

This pseudocode allows us to do all of the tasks in sequence based on specific function calls. What if we wanted to do more than just the sequence? For instance, if the robot needs to keep track of its battery usage and perform necessary tasks, the preceding main() function can get inside another condition block that monitors the battery state and makes the robot navigate to charging_area in case the battery state is less than the threshold mentioned.

But what if the robot actually goes into a low battery state while trying to deliver food? It may go into the charging station with the food instead of going to the customer table. Instead, the robot can predict its battery state before attempting delivery and charge while the food is being cooked or—in the worst case scenario—it can call another robot that is free and with sufficient charge to deliver the food. Writing scripts for such characteristics becomes complex and can give the developer nightmares. Instead, what we would need is a simple method to implement such complex behavior in a standard manner and have the ability to diagnose, debug, and run tasks in parallel. Such an implementation is done through state machines.

The next section will help us get a better understanding of state machines.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.104.120