Calling Web Services from Robot

John Keogh | June 8, 2013

I'm starting to add autonomy to the robots that have been the main subject of this blog and one of the major considerations of permitting autonomy is how to coordinate and modify the behavior of mobile robots. One solution is to use web services, which are very commonly used to expose server based applications to either server or browser based consumers. The main uses I've been considering are task assignment and progress reporting, offloading processing from the weak onboard computer to a more powerful server, and to create a method for customizing the robots without exposing all of the source code.

For a demo, I wrote a web app that permits inputing numbers that represent direction of the robot and the duration of motion and stored it in a database. The robot then sends a request to a web service which gets the next entry from the database, returns it in XML format to the robot, and then deletes the entry from the database. The web service is a very simple REST style web service. It turned out to be very easy to do and took very little code. The following video demonstrate the web UI, the web service, and the robot calling the web service.

The PHP and SQL for the very simple web service is here. The following code just creates a client, which is an XML parser that uses code like...

NSData *xmlDataFromWebService = [ NSURLConnection sendSynchronousRequest:request returningResponse: nil error: &error] get the response from the server then parses it. The interesting thing is that the polling that is in the following code can be replaced by a call to the embedded web server running on the iPod (part of EyesBot Driver) and that can initialize the request for the next task. In that case, each robot would check in when it comes online, basically giving its contact information (IP and port) to the web service, which would permit deploying new robots without requiring additional configuration.

-(void)requestNextAction{ if(!stopRequesting){ double timerInterval = 5.0; WebServiceClient *client = [[WebServiceClient alloc] init]; [client parseXMLFileAtURL: @"hard coded url of web service here"]; NSArray *actions = [client getActions]; if(actions.count>0){ NSDictionary *action = [actions objectAtIndex:0]; int leftPower = [[action objectForKey:@"left"] intValue]; int rightPower = [[action objectForKey:@"right"] intValue]; int lightPower = [[action objectForKey:@"light"] intValue]; int duration = [[action objectForKey:@"duration"] intValue]; [[LightCodedOutput sharedInstance] setLeftPower:leftPower]; [[LightCodedOutput sharedInstance] setRightPower:rightPower]; [[LightCodedOutput sharedInstance] setLightPower:lightPower]; timerInterval = (double)duration; if(timerInterval<1.0){ timerInterval = 5.0; } } else{ [[LightCodedOutput sharedInstance] setLeftPower:0]; [[LightCodedOutput sharedInstance] setRightPower:0]; [[LightCodedOutput sharedInstance] setLightPower:0]; } [self performSelector:@selector(requestNextAction) withObject:nil afterDelay:timerInterval]; } } -(void)stopRequestingActions{ stopRequesting = YES; }

These sort of instructions could clearly be applied to warehouse robots being assigned objects to retrieve, cleaning robots waiting for tasks to perform or security robots being told where potential intruders are. Additionally, moving logic and processing to servers makes it possible to take advantage of servers ability to horizontally scale and distribute workload, as well as coordinate work.

Eyesbot Company

Computer vision

Artificial intelligence

Effecting the physical world