view main/robots/odr/Scoreboard.h @ 221:8e6ca2ead01a main

Latest updates.
author Bob Cook <bob@bobcookdev.com>
date Mon, 09 Sep 2013 20:03:31 -0700
parents e23198d929e9
children 50414c680910
line wrap: on
line source

// ----------------------------------------------------------------------------------------
//
//  robots/odr/Scoreboard.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
// 
//  Global thread-safe state derived from incoming CAN messages and other internal data.
//
//  Copyright (c) 2010-2013 Bob Cook
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
//
// ----------------------------------------------------------------------------------------

#ifndef BCDRL_ROBOTS_ODR_SCOREBOARD_H
#define BCDRL_ROBOTS_ODR_SCOREBOARD_H

#include <stdint.h>
#include <list>

#include <Poco/Event.h>
#include <Poco/Runnable.h>
#include <Poco/RWLock.h>
#include <Poco/Timer.h>
#include <Poco/Timestamp.h>

class CANMessage;

// ----------------------------------------------------------------------------------------

class Scoreboard : public Poco::Runnable
{
    public:
        // odr-gps
        static bool isGpsSensorAlive();

        // odr-motion
        static bool isMotionAlive();

        // odr-controller
        static bool isControllerAlive();
        static bool isEStopActive();
        static bool isButtonOneDown();
        static bool isButtonTwoDown();
        static void sendManagerMessage( const char* msg );

        // odr-sonar-front
        static bool    isSonarFrontAlive();
        static bool    isSonarFrontEnabled();
        static uint8_t sonarFrontLeft();
        static uint8_t sonarFrontCenterLeft();
        static uint8_t sonarFrontCenterRight();
        static uint8_t sonarFrontRight();

        // odr-gps
        static bool   isGpsAlive();
        static bool   gpsHasFix();
        static double gpsLatitude();
        static double gpsLongitude();

        // imu
        static bool   isImuAlive();
        static double imuRoll();
        static double imuPitch();
        static double imuYaw();
        static void   imuUpdate( double roll, double pitch, double yaw );
        static void   imuIsOffline();

        // navigation
        static int8_t navMaximumSpeed();
        static void   navSetMaximumSpeed( int8_t max );
        static double navTargetHeading();
        static void   navSetTargetHeading( double heading );

    public:
        Scoreboard( const std::string& loggerName );
        virtual ~Scoreboard();
        virtual void run();
        void timeToQuit();

    private:
        static Poco::RWLock    sm_rwLock;
        static bool            sm_isEmergencyActive;
        static bool            sm_MotionEmergency;
        static bool            sm_isMotionAlive;
        static bool            sm_isControllerAlive;
        static bool            sm_isEStopActive;
        static bool            sm_isButtonOneDown;
        static bool            sm_isButtonTwoDown;
        static std::string     sm_msgLastText;
        static Poco::Timestamp sm_msgLastUpdate;
        static bool            sm_isSonarFrontAlive;
        static bool            sm_isSonarFrontEnabled;
        static uint8_t         sm_sonarFrontLeft;
        static uint8_t         sm_sonarFrontCenterLeft;
        static uint8_t         sm_sonarFrontCenterRight;
        static uint8_t         sm_sonarFrontRight;
        static bool            sm_isGpsAlive;
        static bool            sm_gpsHasFix;
        static std::list< double > sm_gpsLatitudes;
        static double                sm_gpsLatitudeAvg;
        static std::list< double > sm_gpsLongitudes;
        static double                sm_gpsLongitudeAvg;
        static bool            sm_isImuAlive;
        static Poco::Timestamp sm_imuLastUpdate;
        static double          sm_imuRoll;
        static double          sm_imuPitch;
        static double          sm_imuYaw;
        static int8_t          sm_navMaximumSpeed;
        static double          sm_navTargetHeading;

    private:
        std::string m_loggerName;
        Poco::Event m_quitEvent;
        Poco::Timer m_timerLogStatus;
        Poco::Timer m_timerSendManagerUpdate;
        Poco::Timer m_timerGpsUpdate;
        Poco::Timer m_timerMotionUpdate;
        Poco::Timer m_timerControllerUpdate;
        Poco::Timer m_timerSonarFrontUpdate;
        Poco::Timer m_timerSendImuDataUpdate;

    private:
        void logSystemStatus( Poco::Timer& timer );
        void sendManagerUpdate( Poco::Timer& timer );
        void timeoutGpsSensorUpdate( Poco::Timer& timer );
        void timeoutMotionUpdate( Poco::Timer& timer );
        void timeoutControllerUpdate( Poco::Timer& timer );
        void timeoutSonarFrontUpdate( Poco::Timer& timer );
        void sendImuDataUpdate( Poco::Timer& timer );
        void recvEmergency( uint8_t srcNode );
        void recvAllClear( uint8_t srcNode );
        void recvHeartbeat( uint8_t srcNode );
        void recvControllerUpdate( CANMessage* msg );
        void recvButtonUpdate( CANMessage* msg );
        void recvSonarFrontStatus( bool enabled );
        void recvSonarFrontValues( CANMessage* msg );
        void recvGpsFixInfo( CANMessage* msg );
        void recvGpsLatitude( CANMessage* msg );
        void recvGpsLongitude( CANMessage* msg );
};

// ----------------------------------------------------------------------------------------
#endif // #ifndef BCDRL_ROBOTS_ODR_SCOREBOARD_H
// ----------------------------------------------------------------------------------------