Main Page | Modules | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Hardware abstraction layer


Detailed Description

A robot consists of a large variety of hardware: motors, encoders, analog and digital input and output, etc. RHexLib provides a uniform mechanism for defining and accessing these pieces of hardware in an abstract (to ease porting to different devices or from hardware to simulation) but uniform (to promote code maintainability and reduce bugs) manner.

Specifically, each type of hardware can be defined as a class which has operations specific to that type of hardware. RHexLib provides a Hardware template to implement the uniform interface mechanisms. Developers then use the HARDWARE_DECL() macro to declare their hardware class, and use the HARDWARE_IMPL() macro when implementing it, and the resulting class has all of the Hardware template's functionality in addition to the hardware specific functionality.

Then, in a hardware specific library, the developer must create the functions initHardware() and cleanupHardware(). initHardware() is where specific concrete instances of hardware are allocated and created and registered as "hardware instances" using the Hardware::registerInstance static methods.

After initHardware() is called, developers can simply use the static Hardware::instance() method to access that instance.

cleanupHardware() is called at the end of the program to deallocate and destroy all of the hardware instances created in initHardware().

In addition, the Hardware template provides rudimentary facilities for "grabbing" and "releasing" hardware instances. This may be useful in order to mark a piece of hardware which, for physical reasons, should only have one user at a time, such as a digital output. We also provide for "multi-channel" hardware instances, such as a multi-channel A/D board. Individual channels can then be grabbed and released by passing in a channel index.

When running with different physical hardware, the developer simply replaces the hardware library with another that creates different concrete hardware instances, but which registers them in a manner consistent with the "old" physiucal hardware. To the user of the hardware classes, there should be no need for change for a different set of "real" hardware. In addition, ths approach allows incremental addition of novel hardware, as opposed to a single hardware abstraction which, hopefully, covers all possible types of hardware.


Compounds

class  Hardware
 Basic template for Hardware classes. More...


Defines

#define HARDWARE_IMPL(T)
 Macro for implementing a hardware class.

#define HARDWARE_DECL(T)
 Macro for defining a hardware class.

#define HARDWARE_DECL2(T, S)
 Macro for defining a hardware class which has a single superclass.


Functions

void initHardware ()
 Initialize hardware instances.

void cleanupHardware ()
 Clean up hardware.


Define Documentation

#define HARDWARE_DECL  ) 
 

Macro for defining a hardware class.

Does the C++ template magic to declare a class T as a hardware class.

Parameters:
T The hardware class being declared

#define HARDWARE_DECL2 T,
 ) 
 

Macro for defining a hardware class which has a single superclass.

Does the C++ template magic to declare a class T, which is a subclass of class S, as a hardware class.

Parameters:
T The hardware class being declared
S Its superclass

#define HARDWARE_IMPL  ) 
 

Macro for implementing a hardware class.

Does the C++ magic necessary to implement class T as a hardware class. This must be in exactly one source file for each hardware class in order to implement the various static member variables of the hardware interface.

Parameters:
T The hardware class being implemented


Function Documentation

void cleanupHardware  ) 
 

Clean up hardware.

This must be defined in the hardware library and uninstalls the various pieces of hardware created in initHardware().

void initHardware  ) 
 

Initialize hardware instances.

This must be defined in the hardware library and installs the various pieces of hardware needed by the robot.


RHexLib Reference Documentation