00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "comm.h"
00016
00017 #include <time.h>
00018 #include <math.h>
00019 #include <string>
00020 #include <iostream>
00021 #include <vector>
00022
00024 enum SensorType
00025 {
00026 Touch,
00027 Sound,
00028 Light,
00029 ActiveLight,
00030 Sonar
00031 };
00032
00034 const int OUT_A = 0;
00036 const int OUT_B = 1;
00038 const int OUT_C = 2;
00040 const int IN_1 = 0;
00042 const int IN_2 = 1;
00044 const int IN_3 = 2;
00046 const int IN_4 = 3;
00047
00049 namespace NXT
00050 {
00052
00054 bool Open(Comm::NXTComm* comm);
00056
00059 bool OpenBT(Comm::NXTComm* comm);
00061 void Close(Comm::NXTComm* comm);
00063
00064 void PlayTone(Comm::NXTComm* comm, int frequency, int duration);
00066
00067 int BatteryLevel(Comm::NXTComm* comm);
00069
00070 std::string GetName(Comm::NXTComm* comm);
00072
00073 double GetAvailableFlash(Comm::NXTComm* comm);
00075 void StopProgram(Comm::NXTComm* comm);
00077
00078 double GetProtocolVersion(Comm::NXTComm* comm);
00080
00081 double GetFirmwareVersion(Comm::NXTComm* comm);
00083
00084 void StartProgram(Comm::NXTComm* comm, std::string name);
00086
00087 void PlaySoundFile(Comm::NXTComm* comm, std::string name, bool loop);
00089 void StopSound(Comm::NXTComm* comm);
00091
00094 void KeepAlive(Comm::NXTComm* comm);
00096
00103 void SendDirectCommand(Comm::NXTComm* comm, ViBoolean response, ViByte * dc_buf, int dc_buf_size, ViByte *re_buf, int re_buf_size);
00104
00106 namespace Motor
00107 {
00109
00111 int GetRotationCount(Comm::NXTComm* comm, int port);
00113
00116 void ResetRotationCount(Comm::NXTComm* comm, int port, bool relative);
00118
00120 void SetForward(Comm::NXTComm* comm, int port, int power);
00122
00124 void SetReverse(Comm::NXTComm* comm, int port, int power);
00126
00128 void Stop(Comm::NXTComm* comm, int port, bool brake);
00130
00131 void BrakeOn(Comm::NXTComm* comm, int port);
00133
00134 void BrakeOff(Comm::NXTComm* comm, int port);
00136
00140 void GoTo(Comm::NXTComm* comm, int port, int power, int tacho, bool brake);
00141 }
00142
00144 namespace Sensor
00145 {
00147
00149 void SetTouch(Comm::NXTComm* comm, int port);
00151
00153 void SetSound(Comm::NXTComm* comm, int port);
00155 ;
00157 void SetLight(Comm::NXTComm* comm, int port, bool active);
00159 ;
00161 void SetSonar(Comm::NXTComm* comm, int port);
00163
00165 void SetCmpsNx(Comm::NXTComm* comm, int port);
00167
00169 void SetDistNx(Comm::NXTComm* comm, int port);
00171
00173 void SetRaw(Comm::NXTComm* comm, int port);
00175
00177 void Set(Comm::NXTComm* comm, int port, SensorType type);
00179
00181 int GetValue(Comm::NXTComm* comm, int port);
00183
00186 int GetAvgCmpsNxValue(Comm::NXTComm* comm, int port, int numValues, int waitTime);
00188
00190 int GetCmpsNxValue(Comm::NXTComm* comm, int port);
00192
00194 int GetDistNxValue(Comm::NXTComm* comm, int port);
00196
00198 int GetCleanDistNxValue(Comm::NXTComm* comm, int port);
00200
00203 int LSGetStatus(Comm::NXTComm* comm, int port);
00205
00207 int GetSonarValue(Comm::NXTComm* comm, int port);
00209
00210 void SetSonarOff(Comm::NXTComm* comm, int port);
00212
00213 void SetSonarSingleShot(Comm::NXTComm* comm, int port);
00215
00216 void SetSonarContinuous(Comm::NXTComm* comm, int port);
00218
00221 void SetSonarContinuousInterval(Comm::NXTComm* comm, int port, int interval);
00223
00227 void writeI2C(Comm::NXTComm* comm, int port, ViUInt8 command[], int replySz, int tx_length);
00229
00231 ViUInt8* readI2C(Comm::NXTComm* comm, int port);
00232 }
00233
00234
00236 namespace File
00237 {
00239 enum FileType
00240 {
00241 ANY,
00242 PROGRAM,
00243 SOUND,
00244 GRAPHICS,
00245 DATALOG,
00246 };
00247
00249 enum FileMode
00250 {
00251 READ,
00252 WRITE,
00253 APPEND,
00254 DATA_WRITE,
00255 LINEAR_WRITE,
00256 };
00257
00259 int getNXTFile(Comm::NXTComm* comm, std::string filename, NXTFile& file);
00260
00262 int getNXTFilesByName(Comm::NXTComm* comm, std::string pattern, NXTFileIterator& iter);
00263
00265 int getNXTFilesByType(Comm::NXTComm* comm, int fileType, NXTFileIterator& iter);
00266
00268 void destroyFileIterator(Comm::NXTComm* comm, NXTFileIterator &iter);
00269
00271 void destroyFile(Comm::NXTComm* comm, NXTFile& file);
00272
00273 };
00274
00276 namespace Module
00277 {
00279 int getNXTModules(Comm::NXTComm* comm, std::string pattern, NXTModuleIterator &iter);
00280
00282 int getNXTModule(Comm::NXTComm* comm, std::string pattern, int moduleID, int moduleSize,
00283 int ioMapSize, int &status, NXTModule &module);
00284 };
00285
00287 namespace NxtCam
00288 {
00289 void NxtCamFlush(Comm::NXTComm* comm, int port);
00290 void NxtCamCmd(Comm::NXTComm* comm, int port, ViUInt8 command[], int tx_length);
00291 void NxtCamInit(Comm::NXTComm* comm, int port);
00292 std::vector<std::vector<int>> GetNxtCamObjects(Comm::NXTComm* comm, int port, int minArea);
00293 int GetNxtCamNumObjects(Comm::NXTComm* comm, int port);
00294 };
00295 }
00296
00298 ;
00299 void Wait(int time);
00300