MOOS 0.2375
|
00001 00002 // 00003 // MOOS - Mission Oriented Operating Suite 00004 // 00005 // A suit of Applications and Libraries for Mobile Robotics Research 00006 // Copyright (C) 2001-2005 Massachusetts Institute of Technology and 00007 // Oxford University. 00008 // 00009 // This software was written by Paul Newman and others 00010 // at MIT 2001-2002 and Oxford University 2003-2005. 00011 // email: pnewman@robots.ox.ac.uk. 00012 // 00013 // This file is part of a MOOS Instrument. 00014 // 00015 // This program is free software; you can redistribute it and/or 00016 // modify it under the terms of the GNU General Public License as 00017 // published by the Free Software Foundation; either version 2 of the 00018 // License, or (at your option) any later version. 00019 // 00020 // This program is distributed in the hope that it will be useful, 00021 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00023 // General Public License for more details. 00024 // 00025 // You should have received a copy of the GNU General Public License 00026 // along with this program; if not, write to the Free Software 00027 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 00028 // 02111-1307, USA. 00029 // 00031 // MOOSASCDriver.cpp: implementation of the CMOOSASCDriver class. 00032 // 00034 #include <MOOSLIB/MOOSLib.h> 00035 #include <iostream> 00036 #include "MOOSASCDriver.h" 00037 #include <math.h> 00038 00040 // Construction/Destruction 00042 00043 #define ASC_THRUSTER_RANGE 255 00044 #define ASC_THRUSTER_MAX 228 00045 #define ASC_THRUSTER_MIN 28 00046 #define ASC_THRUSTER_ZERO 128 00047 00048 CMOOSASCDriver::CMOOSASCDriver() 00049 { 00050 MOOSTrace("Creating ASC Driver\n"); 00051 } 00052 00053 CMOOSASCDriver::~CMOOSASCDriver() 00054 { 00055 00056 } 00057 00058 00059 bool CMOOSASCDriver::Initialise() 00060 { 00061 00062 if(m_pPort != NULL ) 00063 { 00064 m_pPort->SetTermCharacter(0x03); 00065 00066 STRING_LIST List; 00067 00068 //Initialization isn't really needed, but it would be nice to 00069 //see the result of this. The TT8 will spit out several lines of 00070 //initialization data, which can be turned off as needed. 00071 00072 List.push_back("#WD\r\n"); 00073 List.push_back("#WD\r\n"); 00074 List.push_front("#WD\r\n"); 00075 00076 STRING_LIST::iterator p; 00077 00078 for(p = List.begin();p!=List.end();p++) 00079 { 00080 string sCmd = *p; 00081 00082 MOOSTrace("iActuation Init() : Sending %s \n",sCmd.c_str()); 00083 00084 string sReply; 00085 if(!SendAndAck(sCmd,sReply)) 00086 { 00087 MOOSTrace("Failed command\n"); 00088 } 00089 MOOSPause(100); 00090 00091 } 00092 00093 } 00094 00095 return true; 00096 } 00097 00098 00099 bool CMOOSASCDriver::SetElevator(double dfAng) 00100 { 00101 // Elevator commands ignored 00102 return false; 00103 } 00104 00105 bool CMOOSASCDriver::SetRudder(double dfAng) 00106 { 00107 bool bResult = DoFinControl("#WD RA ",dfAng); 00108 //this pause stops things happening to fast for the ASC uP. 00109 MOOSPause(100); 00110 00111 return bResult; 00112 00113 } 00114 00115 bool CMOOSASCDriver::SetZeroElevator() 00116 { 00117 // Elevator commands ignored 00118 return false; 00119 } 00120 00121 bool CMOOSASCDriver::SetZeroRudder() 00122 { 00123 MOOSTrace("Setting home for Rudder\n"); 00124 string sReply; 00125 return SendAndAck("#WD RA 0\r\n",sReply); 00126 00127 } 00128 00129 bool CMOOSASCDriver::SetThrust(double dfPercent) 00130 { 00131 00132 int nThrust; 00133 00134 if(dfPercent>100) 00135 { 00136 dfPercent = 100.0; 00137 } 00138 if(dfPercent<-100) 00139 { 00140 dfPercent = -100.0; 00141 } 00142 00143 nThrust = (int)(dfPercent); 00144 nThrust += ASC_THRUSTER_ZERO; 00145 00146 if(m_pPort!=NULL) 00147 { 00148 char sCmd[20]; 00149 00150 sprintf(sCmd,"#WD TH %d\r\n", 00151 nThrust); 00152 00153 string sReply; 00154 if(!SendAndAck(sCmd,sReply)) 00155 { 00156 return false; 00157 } 00158 00159 //this pause stops things happening to fast for the ASC uP. 00160 MOOSPause(100); 00161 } 00162 00163 return true; 00164 } 00165 00166 00167 bool CMOOSASCDriver::DoFinControl(const char *sAddress, double dfAng) 00168 { 00169 int nAngle = (int)(dfAng); 00170 00171 if(m_pPort!=NULL) 00172 { 00173 char sCmd[20]; 00174 00175 sprintf(sCmd,"%s%d\r\n", 00176 sAddress, 00177 nAngle); 00178 00179 string sReply; 00180 return SendAndAck(sCmd,sReply); 00181 00182 } 00183 else 00184 { 00185 return false; 00186 } 00187 } 00188