Recent Changes - Search:

Tracking

Hardware

Software

Mega Plan

Etc.

V2Software

The flockbot revision brings with it two new systems for software development. For our new revision, we opted to use currently popular hobbyist technology, namely the Raspberry Pi and Arduino Uno, for these robots. With these controllers, we have a world of beautiful, simple, and efficient languages in which the software may be developed. So, naturally, we stuck with C and C++.

C and C++/Processing The Raspberry Pi controller was written almost exclusively in C, using a native gcc compiler on the custom Raspbian linux operating system. The advantage of this operating system being a derivation of a very common linux distribution (Debian/Ubuntu) is that native support is bountiful. All code is now compiled directly on each robot and is immediately available for operation. Likewise, the Raspberry Pi brings with it a standard platform with thread, sockets, and serial communications support.

The Arduino Uno is typically built using a provided IDE and the Processing language. Instead of using this approach, which would have resulted in having to connect the Uno to an external laptop for every build, we opted to switch to C++ for out programming and do the compiling and flashing of the Uno directly from the Raspberry Pi. This increased driver writing productivity dramatically when it was initially implemented. While the code is written and compiled in C++, the style is still very heavily C, with some of the Arduino libraries making use of the nicer C++ constructs.

Code Overview

Raspberry Pi

On the Raspberry Pi, we have our main function which begins by initializing serial communications with the Arduino Uno. Once communications are confirmed, the locally stored robot configuration file is transmitted over serial to the waiting Uno and normal operations begin.

Serial Listener At this point a dedicated serial listener thread is created to handle all incoming traffic from the Uno. At 30ms intervals from this point forth, sensor data arrives from the Uno, carrying with it information from 5 IR sensors, two bump sensors, and information about the state of the wheels. This data is buffered into a configurable-sized array, enabling behavior programmers to access both the latest sensor information, as well as aggregating older sensor information.

Camera Processing with OpenCV The next step of the main code is to start the camera processing thread. The camera thread uses OpenCV for all vision processing and has the immediate capability for controlling the camera servo directly. Once the image information is processed, the resulting data will be sent into an array for the behavior code to use.

TCP/IP Socket Listener The final initialization step is to open a TCP/IP socket, on a dedicated thread, for remote client connections. This socket is able to accept any reasonable number of clients (where reasonable is defined in the settings) and allow them to perform all of the interactions with the robot remotely. As the main flockbot process will begin automatically on bootup, this is the primary venue for command and control of the flockbots.

Linux and Android Clients Commands may be sent over TCP/IP and directed either to the flockbot control code, or may be sent as a pass-through straight into the Arduino Uno for direct processing. As of the latest build, both a linux client and an Android phone have been used to directly control the flockbots.

Direct Input The final step of this code is to display a menu and pause for direct input. This is useful for debugging the software on the robot directly. All of the functionality available to the clients is directly available through the flockbot. This includes calibration of all of the servos and sensors, starting and stopping of behaviors, direct control of all of the servos, and configuration of the flockbots.

Dynamic C Library and Lua Script Behaviors On demand, the flockbot code on the Raspberry Pi is also able to dynamically load and execute behaviors written either in C or in Lua, through an integrated interpreter. Both C and Lua APIs are mirror copies of each other, enabling versatility in selecting the appropriate language for the given task. The C behaviors are dynamic libraries which may be loaded and unloaded at will. Only one behavior may execute at any given time.

Edit - History - Print - Recent Changes - Search
Page last modified on November 16, 2013, at 10:33 PM