Home arrow Enthusiast Projects arrow Control Center
Control Center
Friday, 22 December 2006
ImageI have received this 'enthusiast project' from Ernie Daniels. He has provided the following information:

Here's my Winter Festival present. It's incomplete for reasons I already posted in the forums, but it contains all the C++ code that you need to run your robot, and you can easily adapt it to your own application.

The code that I wrote is in the "Executive" folder. Feel free to use it or modify it. It's very much a work in progress -- I plan to continue this work for a long time. This code lets Kurtbot navigate around reasonably well, but it's just a first cut and far from perfect (use it at your own risk.) A brief description:

RobotMath.h, RobotMath.cpp -- constants and a couple of C++ classes, one to calculate moving averages and one to analyze a "Sensor Arc" -- a set of range measurements taken while the robot is turning.

PMDInterface.h, PMDInterface.cpp -- this is a C++ class that I built on top of PMD's "C-Motion" library.

Behavior.h, Behavior.cpp -- this is my first cut at defining the following:

1. An arbiter class. This lets you construct a list of behaviors to be executed during each time slice or "tick". Behaviors associated with an arbiter can be enabled or disabled; enabled behaviors execute in the order that you add them to the arbiter.
2. A behavior class. Behaviors each define three member functions: "BehaviorType()" tells the arbiter what type of behavior it is, Reset() resets the behavior, and Act() allows the behavior to process sensor data, send commands to the robot, enable/disable other behaviors, etc.
3. Some basic behaviors. "Stop" and "Start" allow the user to interact with the robot by putting a hand in front of its beak sensors. I modified these behaviors to require "2 out of 3", meaning that the robot will not recognize a "Start" or "Stop" unless you cover two of the beak sensors. "Scan" causes the robot to turn and look for an opening to drive through. "Drive" takes the output from "Scan", turns the robot towards a perceived opening, and drives forward a safe distance. "Avoid" tells the robot to stop if it gets too close to something.

Executive.h, Executive.cpp -- these define a Win32 DLL which represents one thread of execution. At this point the whole application is single-threaded, but that could easily change. Executive instantiates everything, hooks up the arbiter and behaviors, connects to the robot, and executes a basic time-sliced "service loop" every 100 ms. Every 100 ms the Executive polls the PMD status registers, polls the analog inputs, and then calls Arbiter->Tick() which allows the arbiter to execute all enabled behaviors.

Running this code, Kurtbot connects to his M3 board, sets it up, and then waits for user to signal "Start" by covering two beak sensors. Then it does a "Scan", then a "Drive", Scan/Drive/Scan/Drive until the user signals "Stop". Sometimes a drive is interrupted by the Avoid behavior, but then the robot goes back to scanning and driving. The emergent behavior is quite impressive for a first try.

Credit where credit is due -- I am indebted to Joseph L. Jones and his book "Robot Programming (A Practical Guide to Behavior-Based Robotics)". I am also indebted to the founders of Owl Control Systems (OCS) for producing a practical Win32 control system framework. Which brings me to "What is all of this DML stuff littering your code?" The references that you will see like "DML_ChannelRef" are hooks into the OCS framework, which is not included for reasons I've already explained. A "DML_ChannelRef" defines a value (nearly all of them are integer values) that I can display using the OCS GUI, or modify using the OCS scripting language. Since I'm not doing much of either yet I'll say nothing more about it for the moment. Simply replace the DML_ChannelRefs with "int" in your own application. Similarly, you'll see a lot of "gController->LogDebugString()" calls -- these allow me to log whatever text I want to a file, and you can again substitute your own logging methodology pretty easily. If you are interested in getting access to the OCS framework, email me. I'll have more to say about this stuff in the new year; my primary purpose in releasing this code subset is to give everyone low-level "SDK" access to the PMD chipset on your robot.

You can download the source and documentation here: ControlCenter_public_dist.zip

This article will remain in the Enthusiast projects section for future reference.

Discuss this article on the forums. (12 posts)
< Prev   Next >