main.cpp
Go to the documentation of this file.
00001 //
00002 // main.cpp
00003 //
00004 // LD-MRS example driver and application.
00005 // This code should compile under Linux.
00006 //
00007 // The main() function contains calls to several demo applications. 
00008 // Most of the scanner parameters - including its IP address - are set up
00009 // directly in the LDMRS class constructor.
00010 //
00011 // All source code provided here is intended for demonstration and reference purposes only.
00012 // SICK provides no warranty whatsoever for the function of this code.
00013 //
00014 // Note that not all features are available with all firmware versions of the MRS. Please refer
00015 // to the manual if the intended functionality is available with your device.
00016 //
00017 // Change log:
00018 // 2013-09-18, willhvo:
00019 //  - Started change log.
00020 // 2014-03-04, willhvo:
00021 //  - Added NtpTimeApp demo.
00022 // 2014-12-18, willhvo:
00023 //  - Added ScanpointCoordinateApp demo.
00024 //
00025 
00026 #include "tools/errorhandler.hpp"
00027 #include "BasicDatatypes.hpp"
00028 #include "manager.hpp"
00029 
00030 //
00031 // This example demonstrates setting and receiving the NTP timestamp of the MRS. The timestamp
00032 // can be set with two commands, and is automatically included in every data packet received
00033 // from the sensor. 
00034 // This feature is available in all firmware versions.
00035 //
00036 // The MRS device should be configured like this:
00037 // m_weWantScanData:          true
00038 // m_weWantObjectData:        false
00039 // m_weWantFieldData:         false
00040 // m_weWantScanDataFromSopas: false
00041 //
00042 int mrsNtpTimeApp()
00043 {
00044         // First, create the manager object. The manager handles devices, collects
00045         // device data and forwards it to the application(s).
00046         printInfoMessage("mrsNtpTimeApp: Creating the manager.", true);
00047         Manager manager;
00048         
00049         Sourcetype type;
00050         std::string name;
00051         UINT16 id;
00052         bool result = false;
00053         
00054         // Add the MRS device (sensor)
00055         printInfoMessage("mrsNtpTimeApp: Adding the LDMRS device.", true);
00056         type = Sourcetype_LDMRS;
00057         name = "LDMRS-1";
00058         id = 1;
00059         result = manager.addAndRunDevice(type, name, id);
00060         if (result == false)
00061         {
00062                 printError("mrsNtpTimeApp: Failed to add device " + name + ", aborting!");
00063                 return 0;
00064         }
00065         
00066         // Add the application. As the devices may send configuration data only once
00067         // at startup, the applications may want to be present before the devices are
00068         // started. But - this is not needed here.
00069         printInfoMessage("mrsNtpTimeApp: Adding the application MrsNtpTimeApp.", true);
00070         type = Sourcetype_MrsNtpTimeApp;
00071         name = "MRS Example NTP time App";
00072         id = 51;
00073         result = manager.addApplication(type, name, id);
00074         if (result == false)
00075         {
00076                 printError("mrsNtpTimeApp: Failed to add application " + name + ", aborting!");
00077                 return 0;
00078         }
00079         printInfoMessage("mrsNtpTimeApp: Application NTP-time is running.", true);
00080 
00081         
00082         // This loop never ends
00083         while (1)
00084         {
00085                 // Sleep 100 ms
00086                 usleep(100000);
00087         }
00088         
00089         return 0;
00090 }
00091 
00092 
00093 //
00094 // This example demonstrates setting and checking the FlexibleResolution feature of the
00095 // LDMRS. This feature is not available in all firmware versions.
00096 //
00097 // The MRS device should be configured like this:
00098 // m_weWantScanData:          true
00099 // m_weWantObjectData:        false
00100 // m_weWantFieldData:         false
00101 // m_weWantScanDataFromSopas: false
00102 //
00103 int sectorChangeApp()
00104 {
00105         // First, create the manager object. The manager handles devices, collects
00106         // device data and forwards it to the application(s).
00107         printInfoMessage("sectorChangeApp: Creating the manager.", true);
00108         Manager manager;
00109         
00110         Sourcetype type;
00111         std::string name;
00112         UINT16 id;
00113         bool result = false;
00114         
00115         // Add the MRS device (sensor)
00116         printInfoMessage("sectorChangeApp: Adding the LDMRS device.", true);
00117         type = Sourcetype_LDMRS;
00118         name = "LDMRS-1";
00119         id = 1;
00120         result = manager.addAndRunDevice(type, name, id);
00121         if (result == false)
00122         {
00123                 printError("sectorChangeApp: Failed to add device " + name + ", aborting!");
00124                 return 0;
00125         }
00126         
00127         // Add the application. As the devices may send configuration data only once
00128         // at startup, the applications may want to be present before the devices are
00129         // started. But - this is not needed here.
00130         printInfoMessage("sectorChangeApp: Adding the application MrsSectorChangeApp.", true);
00131         type = Sourcetype_MrsChangeApp;
00132         name = "MRS Example Sector Change App";
00133         id = 51;
00134         result = manager.addApplication(type, name, id);
00135         if (result == false)
00136         {
00137                 printError("sectorChangeApp: Failed to add application " + name + ", aborting!");
00138                 return 0;
00139         }
00140         printInfoMessage("sectorChangeApp: Application SectorChange is running.", true);
00141 
00142         
00143         // This loop never ends
00144         while (1)
00145         {
00146                 // Sleep 100 ms
00147                 usleep(100000);
00148         }
00149         
00150         return 0;
00151 }
00152 
00153 
00154 //
00155 // SOPAS scan data reception application.
00156 // This example shows the reception of scan data via the SOPAS interface.
00157 // Note 1: If only scan data is required, it is recommended to use the MRS interface instead.
00158 // Note 2: Not all MRS devices have a SOPAS interface.
00159 //
00160 // The MRS device should be configured like this:
00161 // m_weWantScanData:          false
00162 // m_weWantObjectData:        false
00163 // m_weWantFieldData:         false
00164 // m_weWantScanDataFromSopas: true
00165 //
00166 int mrsSopasScandataApp()
00167 {
00168         // First, create the manager object. The manager handles devices, collects
00169         // device data and forwards it to the application(s).
00170         printInfoMessage("mrsSopasScandataApp: Creating the manager.", true);
00171         Manager manager;
00172         
00173         // Add the application. As the devices may send configuration data only once
00174         // at startup, the applications must be present before the devices are
00175         // started. Here, we are using the general data display app because we only want
00176         // to show the received data.
00177         Sourcetype type;
00178         std::string name;
00179         UINT16 id;
00180         bool result = false;
00181 
00182         printInfoMessage("mrsSopasScandataApp: Adding the application MrsApp.", true);
00183         type = Sourcetype_MrsApp;
00184         name = "MRS ExampleApp";
00185         id = 50;
00186         result = manager.addApplication(type, name, id);
00187         if (result == false)
00188         {
00189                 printError("mrsSopasScandataApp: Failed to add application " + name + ", aborting!");
00190                 return 0;
00191         }
00192         printInfoMessage("mrsSopasScandataApp: Application is running.", true);
00193         
00194         //
00195         // Add and run the sensor
00196         //
00197         printInfoMessage("mrsSopasScandataApp: Adding the LDMRS device.", true);
00198         type = Sourcetype_LDMRS;
00199         name = "LDMRS-1";
00200         id = 1;
00201         result = manager.addAndRunDevice(type, name, id);
00202         if (result == false)
00203         {
00204                 printError("mrsSopasScandataApp: Failed to add device " + name + ", aborting!");
00205                 return 0;
00206         }
00207 
00208         // This loop never ends
00209         while (1)
00210         {
00211                 // Sleep 100 ms
00212                 usleep(100000);
00213         }
00214         
00215         return 0;
00216 }
00217 
00218 
00219 //
00220 // Field setting application.
00221 //
00222 // The MRS device should be configured like this:
00223 // m_weWantScanData:          false
00224 // m_weWantObjectData:        false
00225 // m_weWantFieldData:         true
00226 // m_weWantScanDataFromSopas: false
00227 //
00228 int mrsFieldApp()
00229 {
00230         // First, create the manager object. The manager handles devices, collects
00231         // device data and forwards it to the application(s).
00232         printInfoMessage("mrsFieldApp: Creating the manager.", true);
00233         Manager manager;
00234         
00235         // Add the application. As the devices may send configuration data only once
00236         // at startup, the applications must be present before the devices are
00237         // started.
00238         Sourcetype type;
00239         std::string name;
00240         UINT16 id;
00241         bool result = false;
00242 
00243         printInfoMessage("mrsFieldApp: Adding the application MrsFieldApp.", true);
00244         type = Sourcetype_MrsFieldApp;
00245         name = "MRS FieldApp";
00246         id = 50;
00247         result = manager.addApplication(type, name, id);
00248         if (result == false)
00249         {
00250                 printError("mrsFieldApp: Failed to add application " + name + ", aborting!");
00251                 return 0;
00252         }
00253         printInfoMessage("mrsFieldApp: Application is running.", true);
00254         
00255         //
00256         // Add and run the sensor
00257         //
00258         printInfoMessage("mrsFieldApp: Adding the LDMRS device.", true);
00259         type = Sourcetype_LDMRS;
00260         name = "LDMRS-1";
00261         id = 1;
00262         result = manager.addAndRunDevice(type, name, id);
00263         if (result == false)
00264         {
00265                 printError("mrsFieldApp: Failed to add device " + name + ", aborting!");
00266                 return 0;
00267         }
00268 
00269         // This loop never ends
00270         while (1)
00271         {
00272                 // Sleep 100 ms
00273                 usleep(100000);
00274         }
00275         
00276         return 0;
00277 }
00278 
00279 
00280 //
00281 // Demo application for scanpoint coordinate calculation. Receives the scanpoints, and prints coordinates of the points at the
00282 // configured scan angle.
00283 //
00284 // The MRS device could be configured like this:
00285 // m_weWantScanData:          true
00286 // m_weWantObjectData:        false
00287 // m_weWantFieldData:         false
00288 // m_weWantScanDataFromSopas: false
00289 //
00290 int mrsScanpointCoordinateApp()
00291 {
00292         // First, create the manager object. The manager handles devices, collects
00293         // device data and forwards it to the application(s).
00294         printInfoMessage("mrsScanpointCoordinateApp: Creating the manager.", true);
00295         Manager manager;
00296         
00297         // Add the application. As the devices may send configuration data only once
00298         // at startup, the applications must be present before the devices are
00299         // started.
00300         Sourcetype type;
00301         std::string name;
00302         UINT16 id;
00303         bool result = false;
00304 
00305         printInfoMessage("mrsScanpointCoordinateApp: Adding the application MrsScanpointCoordinateApp.", true);
00306         type = Sourcetype_MrsScanpointCoordinateApp;
00307         name = "MRS CoordinateApp";
00308         id = 50;
00309         result = manager.addApplication(type, name, id);
00310         if (result == false)
00311         {
00312                 printError("mrsScanpointCoordinateApp: Failed to add application " + name + ", aborting!");
00313                 return 0;
00314         }
00315         printInfoMessage("mrsScanpointCoordinateApp: Application is running.", true);
00316         
00317         //
00318         // Add and run the sensor
00319         //
00320         printInfoMessage("mrsScanpointCoordinateApp: Adding the LDMRS device.", true);
00321         type = Sourcetype_LDMRS;
00322         name = "LDMRS-1";
00323         id = 1;
00324         result = manager.addAndRunDevice(type, name, id);
00325         if (result == false)
00326         {
00327                 printError("mrsScanpointCoordinateApp: Failed to add device " + name + ", aborting!");
00328                 return 0;
00329         }
00330 
00331         // This loop never ends
00332         while (1)
00333         {
00334                 // Sleep 100 ms
00335                 usleep(100000);
00336         }
00337         
00338         return 0;
00339 }
00340 
00341 
00342 
00343 //
00344 // Minimal demo application. Receives all datatypes and just prints the data.
00345 //
00346 // The MRS device could be configured like this:
00347 // m_weWantScanData:          true
00348 // m_weWantObjectData:        true
00349 // m_weWantFieldData:         false
00350 // m_weWantScanDataFromSopas: false
00351 //
00352 int mrsApp()
00353 {
00354         // First, create the manager object. The manager handles devices, collects
00355         // device data and forwards it to the application(s).
00356         printInfoMessage("mrsApp: Creating the manager.", true);
00357         Manager manager;
00358         
00359         // Add the application. As the devices may send configuration data only once
00360         // at startup, the applications must be present before the devices are
00361         // started.
00362         Sourcetype type;
00363         std::string name;
00364         UINT16 id;
00365         bool result = false;
00366 
00367         printInfoMessage("mrsApp: Adding the application MrsApp.", true);
00368         type = Sourcetype_MrsApp;
00369         name = "MRS ExampleApp";
00370         id = 50;
00371         result = manager.addApplication(type, name, id);
00372         if (result == false)
00373         {
00374                 printError("mrsApp: Failed to add application " + name + ", aborting!");
00375                 return 0;
00376         }
00377         printInfoMessage("mrsApp: Application is running.", true);
00378         
00379         //
00380         // Add and run the sensor
00381         //
00382         printInfoMessage("mrsApp: Adding the LDMRS device.", true);
00383         type = Sourcetype_LDMRS;
00384         name = "LDMRS-1";
00385         id = 1;
00386         result = manager.addAndRunDevice(type, name, id);
00387         if (result == false)
00388         {
00389                 printError("mrsApp: Failed to add device " + name + ", aborting!");
00390                 return 0;
00391         }
00392 
00393         // This loop never ends
00394         while (1)
00395         {
00396                 // Sleep 100 ms
00397                 usleep(100000);
00398         }
00399         
00400         return 0;
00401 }
00402 
00403 
00404 //
00405 // The main program.
00406 // Choose the desired application here.
00407 //
00408 int main(int argc, char **argv)
00409 {
00410         //
00411         // LD-MRS Example
00412         //
00413         int result;
00414         
00415         // The MRS-App connects to an MRS, reads its configuration and receives all incoming data.
00416         result = mrsApp();
00417         
00418         // The MRS-App connects to an MRS, reads its configuration and displays scanpoint coordinates.
00419 //      result = mrsScanpointCoordinateApp();
00420         
00421         // The MRS NtpTimeApp demonstrates setting and reading the NTP timestamp.
00422 //      result = mrsNtpTimeApp();
00423         
00424         // The SectorChangeApp demonstrates the usage of the FlexRes feature.
00425 //      result = sectorChangeApp();
00426         
00427         // The FieldApp demonstrates the usage of the SOPAS interface. It removes and creates fields and
00428         // eval cases.
00429 //      result = mrsFieldApp();
00430         
00431         // The SopasScandataApp demonstrates reading scan data via the SOPAS interface.
00432 //      result = mrsSopasScandataApp();
00433 
00434         
00435         return result;
00436 }


libsick_ldmrs
Author(s): SICK AG , Martin Günther , Jochen Sprickerhof
autogenerated on Thu Jun 6 2019 21:02:36