MOOS 0.2375
|
00001 /* 00002 * VehicleFrameWayPointTask.h 00003 * MOOS 00004 * 00005 * Created by pnewman on 27/03/2008. 00006 * Copyright 2008 University of Oxford. All rights reserved. 00007 * 00008 */ 00009 #include <MOOSGenLib/MOOSGenLib.h> 00010 #include "MOOSBehaviour.h" 00011 #include <MOOSUtilityLib/InterpBuffer.h> 00012 00013 00014 00015 class CVehicleFrameWayPointTask : public CMOOSBehaviour 00016 { 00017 public: 00018 CVehicleFrameWayPointTask(); 00019 virtual ~CVehicleFrameWayPointTask(); 00020 00021 protected: 00022 virtual bool SetParam(string sParam, string sVal); 00023 virtual bool GetRegistrations(STRING_LIST &List); 00024 bool OnNewMail(MOOSMSG_LIST &NewMail); 00025 bool Run(CPathAction &DesiredAction); 00026 virtual bool RegularMailDelivery(double dfTimeNow); 00027 bool OnNewTargetWayPoint(const std::string & sVal ,double dfMsgTime); 00028 bool ValidData(); 00029 double GetDistanceToGo(); 00030 00031 class CSE2Pose 00032 { 00033 public: 00034 double X; 00035 double Y; 00036 double A; 00037 }; 00038 00039 00040 CSE2Pose Compose(const CSE2Pose & Xab,const CSE2Pose & Xbc) 00041 { 00042 CSE2Pose Xac; 00043 00044 double dfCab = cos(Xab.A); 00045 double dfSab = sin(Xab.A); 00046 00047 Xac.X = Xab.X+Xbc.X*dfCab-Xbc.Y*dfSab; 00048 Xac.Y = Xab.Y+Xbc.X*dfSab+Xbc.Y*dfCab; 00049 Xac.A = MOOS_ANGLE_WRAP(Xab.A+Xbc.A); 00050 00051 return Xac; 00052 00053 } 00054 CSE2Pose Inverse(const CSE2Pose &Xab) 00055 { 00056 CSE2Pose Xba; 00057 double ct = cos(Xab.A); 00058 double st = sin(Xab.A); 00059 Xba.X = -ct*Xab.X - st*Xab.Y; 00060 Xba.Y = +st*Xab.X - ct*Xab.Y; 00061 Xba.A = -Xab.A; 00062 return Xba; 00063 } 00064 00065 00066 class CSE2PoseInterpolator 00067 { 00068 typedef std::pair<double,CSE2Pose> Pair; 00069 public: 00070 CSE2Pose operator()(const Pair &loPair, const Pair &hiPair, double dfInterpTime) const 00071 { 00072 const CSE2Pose &lo = loPair.second; 00073 const CSE2Pose &hi = hiPair.second; 00074 CSE2Pose NewPose; 00075 00076 double dt = (hiPair.first - loPair.first); 00077 double alpha = 0.0; 00078 00079 if ( dt != 0.0 ) 00080 alpha = (dfInterpTime - loPair.first) / dt; 00081 00082 NewPose.X = alpha*hi.X + (1-alpha)*lo.X; 00083 NewPose.Y = alpha*hi.Y + (1-alpha)*lo.Y; 00084 NewPose.A = alpha*hi.A + (1-alpha)* lo.A; 00085 00086 double dfAngDiff = MOOS_ANGLE_WRAP(hi.A - lo.A); 00087 NewPose.A = lo.A + alpha*dfAngDiff; 00088 00089 return NewPose; 00090 } 00091 }; 00092 00093 00094 TInterpBuffer<double, CSE2Pose,CSE2PoseInterpolator > m_PoseHistory; 00095 00096 //name of message indicating current pose 00097 std::string m_sPoseSource; 00098 //name of message indicating current goal 00099 std::string m_sTargetWayPoint; 00100 //name of message indicating desired thrust 00101 std::string m_sDesiredThrustSource; 00102 00103 double m_dfVicinityRadius; 00104 00105 double m_dfDesiredThrust; 00106 00107 bool m_bThrustSet; 00108 bool m_bWayPointSet; 00109 ControlledDOF m_YawDOF; 00110 ControlledDOF m_XDOF; 00111 ControlledDOF m_YDOF; 00112 00113 00114 }; 00115