/** \file
 *
 *  Contains the Lane class declaration.
 *
 *  Lane.h should only be included by Lane.cpp
 *  Other classes should include LaneIF.h
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef LANE_H_
#define LANE_H_

#include "component/Behavior.h"
#include "data/Location.h"

class UniversalDataReader;

/**
 *  Contains the Lane Behavior/Command.  This is a very
 *  simple routine that simply points the nose of the vehicle
 *  at the indicated waypoint, until the waypoint is reached.
 *  If a angle is specified, then the waypoiny is
 *  reached when the vehicle is within the specified radius
 *  of the waypoint.
 *
 *  /todo implement waypoint satisfaction by "passing" waypoint
 *
 *  Lane.h should only be included by Lane.cpp
 *  Other classes should include LaneIF.h
 *
 *  \ingroup modules_controller
 */
class Lane : public Behavior
{
public:

    Lane( const Str& prefix, const Module* module );

    virtual ~Lane();

    /// Read settings
    void readSettings();

    /// Initialize function
    void initialize( void );

    /// Returns true when vehicle has "arrived"
    /// within the angle of the waypoint
    bool isSatisfied();

    /// runs only if unsatisfied
    bool runIfUnsatisfied();

    /// The actual "payload" of the component
    void run();

    /// Uninit function
    void uninitialize( void );

    /// Mission Component factory interface
    static Behavior* CreateBehavior( const Str& prefix, const Module* module );

protected:

    /// Desired Bearing
    float bearingSetting_;

    /// Desired Distance
    float distanceSetting_;

    /// Desired (calculated) Latitude
    double latitudeSetting_;

    /// Desired (calculated) Longitude
    double longitudeSetting_;

    /// Desired width
    float widthSetting_;

    /// Desired offset
    float offsetSetting_;

    /// Current Latitude
    double latitude_;

    /// Current Longitude
    double longitude_;

    /// Slope for crossing line (thru wapoint)
    float perpendicularSlope_;

    /// Is our starting point latitude > than the latitude of the starting
    /// longitude on the crossing line?
    bool startOverLine_;

    /// Indicates initialization success
    bool initialized_;

    // Slate input setting variables

    // Desired bearing
    SettingReader *bearingSettingReader_;

    // Desired distance
    SettingReader *distanceSettingReader_;

    /// Width of the lane
    SettingReader *widthSettingReader_;

    /// Offset of the lane
    SettingReader *offsetSettingReader_;

    // Slate input measurements

    // Current platform latitude
    UniversalDataReader *latitudeReader_;

    // Current platform longitude
    UniversalDataReader *longitudeReader_;

    // Current platform heading
    UniversalDataReader *headingReader_;

    // Gets the horizontal mode for HorizontalControl
    DataReader *horizontalModeReader_;

    // Gets the heading for HorizontalControl
    DataReader *headingCmdReader_;

    // Gets the bearing for HorizontalControl
    DataReader *bearingCmdReader_;

    // Slate output variables

    // Sets the horizontal mode for HorizontalControl
    DataWriter *horizontalModeWriter_;

    // Sets the heading for HorizontalControl
    DataWriter *headingCmdWriter_;

    // Carries out behavior on parameters
    void doRun();

    // Determines if behavior is satisfied
    bool calcSatisfied();

    // Reads in parameters used by doRun and calcSatisfied
    bool readParams();

private:
    // Note that the copy constructor below is private and not given a body.
    // Any attempt to call it will return a compiler error.
    Lane( const Lane& old ); // disallow copy constructor


};

#endif /*LANE_H_*/
