Now you can download a copy of these docs so you can use them offline! Download now
RobotBase.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2008. All Rights Reserved. */ 00003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */ 00005 /*----------------------------------------------------------------------------*/ 00006 00007 #include "RobotBase.h" 00008 00009 #include "DriverStation.h" 00010 #include "NetworkCommunication/FRCComm.h" 00011 #include "NetworkCommunication/symModuleLink.h" 00012 #include "NetworkCommunication/UsageReporting.h" 00013 #include "Utility.h" 00014 #include <moduleLib.h> 00015 #include <taskLib.h> 00016 #include <unldLib.h> 00017 00018 RobotBase* RobotBase::m_instance = NULL; 00019 00020 void RobotBase::setInstance(RobotBase* robot) 00021 { 00022 wpi_assert(m_instance == NULL); 00023 m_instance = robot; 00024 } 00025 00026 RobotBase &RobotBase::getInstance() 00027 { 00028 return *m_instance; 00029 } 00030 00039 RobotBase::RobotBase() 00040 : m_task (NULL) 00041 , m_ds (NULL) 00042 { 00043 m_ds = DriverStation::GetInstance(); 00044 } 00045 00051 RobotBase::~RobotBase() 00052 { 00053 SensorBase::DeleteSingletons(); 00054 delete m_task; 00055 m_task = NULL; 00056 m_instance = NULL; 00057 } 00058 00064 bool RobotBase::IsSystemActive() 00065 { 00066 return m_watchdog.IsSystemActive(); 00067 } 00068 00074 Watchdog &RobotBase::GetWatchdog() 00075 { 00076 return m_watchdog; 00077 } 00078 00083 bool RobotBase::IsEnabled() 00084 { 00085 return m_ds->IsEnabled(); 00086 } 00087 00092 bool RobotBase::IsDisabled() 00093 { 00094 return m_ds->IsDisabled(); 00095 } 00096 00101 bool RobotBase::IsAutonomous() 00102 { 00103 return m_ds->IsAutonomous(); 00104 } 00105 00110 bool RobotBase::IsOperatorControl() 00111 { 00112 return m_ds->IsOperatorControl(); 00113 } 00114 00119 bool RobotBase::IsNewDataAvailable() 00120 { 00121 return m_ds->IsNewControlData(); 00122 } 00123 00127 void RobotBase::robotTask(FUNCPTR factory, Task *task) 00128 { 00129 RobotBase::setInstance((RobotBase*)factory()); 00130 RobotBase::getInstance().m_task = task; 00131 RobotBase::getInstance().StartCompetition(); 00132 } 00133 00142 void RobotBase::startRobotTask(FUNCPTR factory) 00143 { 00144 #ifdef SVN_REV 00145 if (strlen(SVN_REV)) 00146 { 00147 printf("WPILib was compiled from SVN revision %s\n", SVN_REV); 00148 } 00149 else 00150 { 00151 printf("WPILib was compiled from a location that is not source controlled.\n"); 00152 } 00153 #else 00154 printf("WPILib was compiled without -D'SVN_REV=nnnn'\n"); 00155 #endif 00156 00157 // Check for startup code already running 00158 INT32 oldId = taskNameToId("FRC_RobotTask"); 00159 if (oldId != ERROR) 00160 { 00161 // Find the startup code module. 00162 char moduleName[256]; 00163 moduleNameFindBySymbolName("FRC_UserProgram_StartupLibraryInit", moduleName); 00164 MODULE_ID startupModId = moduleFindByName(moduleName); 00165 if (startupModId != NULL) 00166 { 00167 // Remove the startup code. 00168 unldByModuleId(startupModId, 0); 00169 printf("!!! Error: Default code was still running... It was unloaded for you... Please try again.\n"); 00170 return; 00171 } 00172 // This case should no longer get hit. 00173 printf("!!! Error: Other robot code is still running... Unload it and then try again.\n"); 00174 return; 00175 } 00176 00177 // Let the framework know that we are starting a new user program so the Driver Station can disable. 00178 FRC_NetworkCommunication_observeUserProgramStarting(); 00179 00180 // Let the Usage Reporting framework know that there is a C++ program running 00181 nUsageReporting::report(nUsageReporting::kResourceType_Language, nUsageReporting::kLanguage_CPlusPlus); 00182 00183 // Start robot task 00184 // This is done to ensure that the C++ robot task is spawned with the floating point 00185 // context save parameter. 00186 Task *task = new Task("RobotTask", (FUNCPTR)RobotBase::robotTask, Task::kDefaultPriority, 64000); 00187 task->Start((INT32)factory, (INT32)task); 00188 } 00189 00196 class RobotDeleter 00197 { 00198 public: 00199 RobotDeleter() {} 00200 ~RobotDeleter() 00201 { 00202 delete &RobotBase::getInstance(); 00203 } 00204 }; 00205 static RobotDeleter g_robotDeleter;
Generated on Thu Jan 12 2012 22:35:23 for WPILibC++ by
1.7.1