00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 #ifndef __JAUS_MOBILITY_GLOBAL_WAYPOINT_DRIVER__H 00042 #define __JAUS_MOBILITY_GLOBAL_WAYPOINT_DRIVER__H 00043 00044 #include "jaus/core/management/management.h" 00045 #include "jaus/mobility/drivers/settravelspeed.h" 00046 #include "jaus/mobility/drivers/setglobalwaypoint.h" 00047 #include "jaus/mobility/drivers/querytravelspeed.h" 00048 #include "jaus/mobility/drivers/queryglobalwaypoint.h" 00049 #include "jaus/mobility/drivers/reporttravelspeed.h" 00050 #include "jaus/mobility/drivers/reportglobalwaypoint.h" 00051 #include "jaus/mobility/sensors/globalposesensor.h" 00052 #include "jaus/mobility/sensors/velocitystatesensor.h" 00053 00054 namespace JAUS 00055 { 00056 typedef JAUS::ReportTravelSpeed TravelSpeed; 00057 00064 // The function of the Global Waypoint Driver is to move the platform given a 00081 class JAUS_MOBILITY_DLL GlobalWaypointDriver : public Management::Child 00082 { 00083 public: 00084 const static std::string Name; 00085 GlobalWaypointDriver(); 00086 virtual ~GlobalWaypointDriver(); 00087 // Overloaded by the inheriting class to generate commands for the controlled driver. 00088 virtual Message* GenerateDriveCommand(const Byte status) = 0; 00089 // Overloaded by the inheriting class to generate default commands for the controlled driver. 00090 virtual Message* GenerateIdleDriveCommand(const Byte status) const = 0; 00091 // Returns true if target waypoint is achieved. 00092 virtual bool IsWaypointAchieved(const GlobalPose& currentPose, 00093 const JAUS::SetGlobalWaypoint& desiredWaypoint) const = 0; 00094 // Virtual method called whenever waypoint driver updates, overload to add additional behaviors/checks needed. 00095 virtual void WaypointDriverUpdateEvent(const unsigned int timeSinceLastUpdateMs) {} 00096 // Method is called when desired waypoint is achieved. 00097 virtual void WaypointAchieved(const JAUS::SetGlobalWaypoint& waypoint) = 0; 00098 // Method called whenever a Set Global Waypoint command is received by service. 00099 virtual bool SetGlobalWaypoint(const JAUS::SetGlobalWaypoint* command); 00100 // Method called whenever a Set Travel Speed command is received by service, overload for extra functionality. 00101 virtual bool SetDesiredTravelSpeed(const JAUS::SetTravelSpeed* command) {return true;} 00102 // Change the Desired Travel Speed without sending a SetTravelSpeed command 00103 virtual bool SetDesiredTravelSpeed(const double speed); 00104 // Try to take control of lower-level (e.g. primitive) driver, in order to move to waypoint. 00105 virtual bool SetDriverToControl(const Address& driver); 00106 // Gets the current GlobalWaypoint command. 00107 virtual JAUS::SetGlobalWaypoint GetGlobalWaypoint() const; 00108 // Gets the current GlobalPoseSensor report. 00109 virtual GlobalPose GetGlobalPose() const; 00110 // Gets the current velocity state report. 00111 virtual VelocityState GetVelocityState() const; 00112 // Gets the current travel speed command. 00113 virtual JAUS::SetTravelSpeed GetDesiredTravelSpeed() const; 00114 // Gets the time when the last wrench effort command was received. 00115 virtual Time GetGlobalWaypointTime() const; 00116 // Gets the time when the last travel speed command was received. 00117 virtual Time GetTravelSpeedTime() const; 00118 // Gets the address of the lower-level (e.g. primitive) driver being controlled. 00119 virtual Address GetControlledDriverID() const; 00120 // Generates Global Waypoint Driver related events. 00121 virtual bool GenerateEvent(const Events::Subscription& info) const; 00122 // Adds support for Report Global Waypoint events. 00123 virtual bool IsEventSupported(const Events::Type type, 00124 const double requestedPeriodicRate, 00125 const Message* queryMessage, 00126 double& confirmedPeriodicRate, 00127 std::string& errorMessage) const; 00128 // By default, the Global Waypoint Driver is discoverable to other components (overload to hide). 00129 virtual bool IsDiscoverable() const { return true; } 00130 // Method called whenever a message is received. 00131 virtual void Receive(const Message* message); 00132 // Creates messages associated with this service. 00133 virtual Message* CreateMessage(const UShort messageCode) const; 00134 // Prints information about the service. 00135 virtual void PrintStatus() const; 00136 // Method called when transitioning to a ready state. 00137 virtual bool Resume(); 00138 // Method called to transition due to reset. 00139 virtual bool Reset(); 00140 // Method called when transitioning to a standby state. 00141 virtual bool Standby(); 00142 // Method called when transitioning to an emergency state. 00143 virtual bool SetEmergency(); 00144 // Method called when leaving the emergency state. 00145 virtual bool ClearEmergency(); 00146 // Method called when control is released. 00147 virtual bool ReleaseControl(); 00148 private: 00149 // In this method, drive commands are generated. 00150 virtual void CheckServiceStatus(const unsigned int timeSinceLastCheckMs); 00151 // Creates a ReportGlobalWaypoint from QueryGlobalWaypoint. 00152 void CreateReportFromQuery(const QueryGlobalWaypoint* query, 00153 ReportGlobalWaypoint& report) const; 00154 // Creates a ReportTravelSpeed from QueryTravelSpeed. 00155 void CreateReportFromQuery(const QueryTravelSpeed* query, 00156 TravelSpeed& report) const; 00157 // Checks if Driver is controlled, acquire control if necessary. 00158 bool CheckDriver(); 00159 // Checks if Sensor data is availabe, acquire subscriptions if necessary. 00160 bool CheckSensors(); 00161 // Removes Control of driver and stops subscriptions. 00162 bool ReleaseResources(); 00163 bool mWaypointAchievedFlag; 00164 Mutex mGlobalWaypointDriverMutex; 00165 Address mControlledDriverID; 00166 GlobalPoseSensor* mpGlobalPoseSensor; 00167 VelocityStateSensor* mpVelocityStateSensor; 00168 Time mGlobalWaypointTime; 00169 Time mTravelSpeedTime; 00170 JAUS::SetGlobalWaypoint mGlobalWaypoint; 00171 JAUS::SetTravelSpeed mDesiredTravelSpeed; 00172 GlobalPose mGlobalPose; 00173 VelocityState mVelocityState; 00174 }; 00175 } 00176 00177 #endif 00178 /* End of File */