Now you can download a copy of these docs so you can use them offline! Download now
SendablePIDController.cpp
00001 /*----------------------------------------------------------------------------*/ 00002 /* Copyright (c) FIRST 2011. 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 "SmartDashboard/SendablePIDController.h" 00008 00009 #include "NetworkTables/NetworkTable.h" 00010 00011 static const char *kP = "p"; 00012 static const char *kI = "i"; 00013 static const char *kD = "d"; 00014 static const char *kSetpoint = "setpoint"; 00015 static const char *kEnabled = "enabled"; 00016 00025 SendablePIDController::SendablePIDController(double p, double i, double d, 00026 PIDSource* source, PIDOutput* output) : 00027 PIDController(p, i, d, source, output), 00028 m_table(NULL) 00029 { 00030 } 00031 00042 SendablePIDController::SendablePIDController(double p, double i, double d, 00043 PIDSource* source, PIDOutput* output, double period) : 00044 PIDController(p, i, d, source, output, period), 00045 m_table(NULL) 00046 { 00047 } 00048 00049 SendablePIDController::~SendablePIDController() 00050 { 00051 if (m_table != NULL) 00052 m_table->RemoveChangeListenerAny(this); 00053 } 00054 00059 void SendablePIDController::SetSetpoint(float setpoint) 00060 { 00061 PIDController::SetSetpoint(setpoint); 00062 00063 if (m_table != NULL) 00064 { 00065 m_table->PutDouble(kSetpoint, setpoint); 00066 } 00067 } 00068 00076 void SendablePIDController::SetPID(double p, double i, double d) 00077 { 00078 PIDController::SetPID(p, i, d); 00079 00080 if (m_table != NULL) 00081 { 00082 m_table->PutDouble(kP, p); 00083 m_table->PutDouble(kI, i); 00084 m_table->PutDouble(kD, d); 00085 } 00086 } 00087 00091 void SendablePIDController::Enable() 00092 { 00093 PIDController::Enable(); 00094 00095 if (m_table != NULL) 00096 m_table->PutBoolean(kEnabled, true); 00097 } 00098 00102 void SendablePIDController::Disable() 00103 { 00104 PIDController::Disable(); 00105 00106 if (m_table != NULL) 00107 m_table->PutBoolean(kEnabled, false); 00108 } 00109 00110 NetworkTable* SendablePIDController::GetTable() 00111 { 00112 if (m_table == NULL) 00113 { 00114 m_table = new NetworkTable(); 00115 00116 m_table->PutDouble(kP, GetP()); 00117 m_table->PutDouble(kI, GetI()); 00118 m_table->PutDouble(kD, GetD()); 00119 m_table->PutDouble(kSetpoint, GetSetpoint()); 00120 m_table->PutBoolean(kEnabled, IsEnabled()); 00121 00122 m_table->AddChangeListenerAny(this); 00123 } 00124 return m_table; 00125 } 00126 00127 void SendablePIDController::ValueChanged(NetworkTable *table, const char *name, NetworkTables_Types type) 00128 { 00129 if (strcmp(name, kP) == 0 || strcmp(name, kI) == 0 || strcmp(name, kD) == 0) 00130 { 00131 PIDController::SetPID(table->GetDouble(kP), table->GetDouble(kI), 00132 table->GetDouble(kD)); 00133 } 00134 else if (strcmp(name, kSetpoint) == 0) 00135 { 00136 PIDController::SetSetpoint(table->GetDouble(kSetpoint)); 00137 } 00138 else if (strcmp(name, kEnabled) == 0) 00139 { 00140 if (table->GetBoolean(kEnabled)) 00141 PIDController::Enable(); 00142 else 00143 PIDController::Disable(); 00144 } 00145 }
Generated on Thu Jan 12 2012 22:35:24 for WPILibC++ by
1.7.1