Ravens Robotics FRC 2015
Public Member Functions | List of all members
RobotComponent Class Reference

#include <RobotComponent.h>

Inheritance diagram for RobotComponent:
Camera MecanumDrive RobotArms

Public Member Functions

 RobotComponent ()
 
virtual ~RobotComponent ()
 
virtual void ComponentInit ()
 
virtual void Sense ()
 
virtual void DoWork ()
 

Detailed Description

Standard interface for Robot Components supporting iterative operation.

Example

Here we have a robot component, "SmelloVision", which is a subclass of RobotComponent. The SmelloVision class implements just two of the parent class members, ComponentInit() and Sense(). Because the (fictional) Olfactory sensor is input-only, the DoWork() member is not implemented in this subclass.

To facilitate reporting of the sensed value, the class has a private data member scentIndex, which stores the reading from the sensor, and a public member function reportScent(), which can be called to retrieve the most recent sensor value.

The Robot class utilizes the component via the standard interface provided through class RobotComponent, and does not need to be concerned with any of the details of the component itself.

In SmelloVision.h:

#include <RobotComponent.h>

class SmelloVision : public RobotComponent
{
public:
    void ComponentInit()       // This subclass has specific initialization
    void Sense();              // ...and it has specific sensor input
    uint32_t reportScent();    // ...and extends its own reporting method
                                  // BUT does not DoWork!

private:
    Olfactory m_nose;
    static const uint32_t
                SmellChannel;  ///< Channel number for nose
    uint32_t scentIndex;       // 0-255, identifying dominant smell,
                            // shared amongst member functions
};

In SmelloVision.cpp:

#include <SmelloVision.h>

const uint32_t SmelloVision::SmellChannel = 5;

SmelloVision::SmelloVision()
{
    scentIndex = 0;            // Initialize private member value
    // Remember: use ComponentInit to set up devices.
}

void SmelloVision::Sense() {
    scentIndex = m_nose.Get(); // Set private member value
}

void SmelloVision::ComponentInit() {
    m_nose = new Olfactory(SmellChannel);  // Initialize Olfactory sensor
}

uint32_t SmelloVision::reportScent() {
    return scentIndex;
}

In myRobot.cpp:

#include <RobotComponent.h>
#include <SmelloVision.h>

class myRobot : public IterativeRobot
{
public:
    myRobot() {};
    void RobotInit();
    void TeleopPeriodic();

private:
    SmelloVision sniffer;        ///< Instance of RobotComponent
};

void myRobot::RobotInit()
{
    sniffer.ComponentInit();
}

void myRobot::TeleopPeriodic()
{
    // Start iteration by having each component sense
    sniffer.Sense();

    // Complete iteration by having each component DoWork
    sniffer.DoWork();  // Remember - SmelloVision doesn't DoWork,
                       // But the common interface from RobotComponent
                       // provides default behavior. (do nothing)
}

Definition at line 111 of file RobotComponent.h.

Constructor & Destructor Documentation

RobotComponent::RobotComponent ( )

Constructor

Definition at line 12 of file RobotComponent.cpp.

RobotComponent::~RobotComponent ( )
virtual

Destructor

Definition at line 17 of file RobotComponent.cpp.

Member Function Documentation

void RobotComponent::ComponentInit ( )
virtual

Called once, to perform initialization that isn't appropriate for constructor.

Reimplemented in Camera, MecanumDrive, and RobotArms.

Definition at line 21 of file RobotComponent.cpp.

void RobotComponent::DoWork ( )
virtual

Component-specific worker function.

Reimplemented in MecanumDrive, Camera, and RobotArms.

Definition at line 29 of file RobotComponent.cpp.

void RobotComponent::Sense ( )
virtual

Component-specific sensory input collector

Reimplemented in Camera, MecanumDrive, and RobotArms.

Definition at line 25 of file RobotComponent.cpp.


The documentation for this class was generated from the following files: