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_LOCAL_WAYPOINT_DRIVER__H 00042 #define __JAUS_MOBILITY_LOCAL_WAYPOINT_DRIVER__H 00043 00044 #include "jaus/core/management/management.h" 00045 #include "jaus/mobility/drivers/globalwaypointdriver.h" 00046 #include "jaus/mobility/drivers/settravelspeed.h" 00047 #include "jaus/mobility/drivers/setlocalwaypoint.h" 00048 #include "jaus/mobility/drivers/querytravelspeed.h" 00049 #include "jaus/mobility/drivers/querylocalwaypoint.h" 00050 #include "jaus/mobility/drivers/reporttravelspeed.h" 00051 #include "jaus/mobility/drivers/reportlocalwaypoint.h" 00052 #include "jaus/mobility/sensors/localposesensor.h" 00053 #include "jaus/mobility/sensors/velocitystatesensor.h" 00054 00055 namespace JAUS 00056 { 00057 typedef JAUS::ReportLocalWaypoint LocalWaypoint; 00058 00065 // The function of the Local Waypoint Driver is to move the platform given a 00082 class JAUS_MOBILITY_DLL LocalWaypointDriver : public Management::Child 00083 { 00084 public: 00085 const static std::string Name; 00086 LocalWaypointDriver(); 00087 virtual ~LocalWaypointDriver(); 00088 // Overloaded by the inheriting class to generate commands for the controlled driver. 00089 virtual Message* GenerateDriveCommand(const Byte status) = 0; 00090 // Overloaded by the inheriting class to generate default commands for the controlled driver. 00091 virtual Message* GenerateIdleDriveCommand(const Byte status) const = 0; 00092 // Returns true if target waypoint is achieved. 00093 virtual bool IsWaypointAchieved(const LocalPose& currentPose, 00094 const JAUS::SetLocalWaypoint& desiredWaypoint) const = 0; 00095 // Virtual method called whenever waypoint driver updates, overload to add additional behaviors/checks needed. 00096 virtual void WaypointDriverUpdateEvent(const unsigned int timeSinceLastUpdateMs) {} 00097 // Method is called when desired waypoint is achieved. 00098 virtual void WaypointAchieved(const JAUS::SetLocalWaypoint& waypoint) = 0; 00099 // Method called whenever a Set Local Waypoint command is received by service. 00100 virtual bool SetLocalWaypoint(const JAUS::SetLocalWaypoint* command); 00101 // Method called whenever a Set Travel Speed command is received by service, overload for extra functionality. 00102 virtual bool SetDesiredTravelSpeed(const JAUS::SetTravelSpeed* command) {return true;} 00103 // Change the Desired Travel Speed without sending a SetTravelSpeed command 00104 virtual bool SetDesiredTravelSpeed(const double speed); 00105 // Try to take control of lower-level (e.g. primitive) driver, in order to move to waypoint. 00106 virtual bool SetDriverToControl(const Address& driver); 00107 // Gets the current LocalWaypoint command. 00108 virtual JAUS::SetLocalWaypoint GetLocalWaypoint() const; 00109 // Gets the current LocalPoseSensor report. 00110 virtual LocalPose GetLocalPose() const; 00111 // Gets the current velocity state report. 00112 virtual VelocityState GetVelocityState() const; 00113 // Gets the current travel speed command. 00114 virtual JAUS::SetTravelSpeed GetDesiredTravelSpeed() const; 00115 // Gets the time when the last wrench effort command was received. 00116 virtual Time GetLocalWaypointTime() const; 00117 // Gets the time when the last travel speed command was received. 00118 virtual Time GetTravelSpeedTime() const; 00119 // Gets the address of the lower-level (e.g. primitive) driver being controlled. 00120 virtual Address GetControlledDriverID() const; 00121 // Generates Local Waypoint Driver related events. 00122 virtual bool GenerateEvent(const Events::Subscription& info) const; 00123 // Adds support for Report Local Waypoint events. 00124 virtual bool IsEventSupported(const Events::Type type, 00125 const double requestedPeriodicRate, 00126 const Message* queryMessage, 00127 double& confirmedPeriodicRate, 00128 std::string& errorMessage) const; 00129 // By default, the Local Waypoint Driver is discoverable to other components (overload to hide). 00130 virtual bool IsDiscoverable() const { return true; } 00131 // Method called whenever a message is received. 00132 virtual void Receive(const Message* message); 00133 // Creates messages associated with this service. 00134 virtual Message* CreateMessage(const UShort messageCode) const; 00135 // Prints information about the service. 00136 virtual void PrintStatus() const; 00137 // Method called when transitioning to a ready state. 00138 virtual bool Resume(); 00139 // Method called to transition due to reset. 00140 virtual bool Reset(); 00141 // Method called when transitioning to a standby state. 00142 virtual bool Standby(); 00143 // Method called when transitioning to an emergency state. 00144 virtual bool SetEmergency(); 00145 // Method called when leaving the emergency state. 00146 virtual bool ClearEmergency(); 00147 // Method called when control is released. 00148 virtual bool ReleaseControl(); 00149 private: 00150 // In this method, drive commands are generated. 00151 virtual void CheckServiceStatus(const unsigned int timeSinceLastCheckMs); 00152 // Creates a ReportLocalWaypoint from QueryLocalWaypoint. 00153 void CreateReportFromQuery(const QueryLocalWaypoint* query, 00154 LocalWaypoint& report) const; 00155 // Creates a ReportTravelSpeed from QueryTravelSpeed. 00156 void CreateReportFromQuery(const QueryTravelSpeed* query, 00157 TravelSpeed& report) const; 00158 // Checks if Driver is controlled, acquire control if necessary. 00159 bool CheckDriver(); 00160 // Checks if Sensor data is availabe, acquire subscriptions if necessary. 00161 bool CheckSensors(); 00162 // Removes Control of driver and stops subscriptions. 00163 bool ReleaseResources(); 00164 bool mWaypointAchievedFlag; 00165 Mutex mLocalWaypointDriverMutex; 00166 Address mControlledDriverID; 00167 LocalPoseSensor* mpLocalPoseSensor; 00168 VelocityStateSensor* mpVelocityStateSensor; 00169 Time mLocalWaypointTime; 00170 Time mTravelSpeedTime; 00171 JAUS::SetLocalWaypoint mLocalWaypoint; 00172 JAUS::SetTravelSpeed mDesiredTravelSpeed; 00173 LocalPose mLocalPose; 00174 VelocityState mVelocityState; 00175 }; 00176 } 00177 00178 #endif 00179 /* End of File */