31 #define INVALID_OPTION_STRING " Invalid option!!! :o(" 32 #define PROMPT_STRING "ld?> " 35 #define CONFIG_OPT_MOTOR_SPD_STR "SICK_LD_MOTOR_SPEED" 36 #define CONFIG_OPT_SCAN_AREA_STR "SICK_LD_SCAN_AREAS" 37 #define CONFIG_OPT_SCAN_RES_STR "SICK_LD_SCAN_RESOLUTION" 95 bool parseScanAreasStr(
string& scan_areas_str,
double *start_angs,
double *stop_angs,
int& num_sectors);
105 bool parseNumStr(
const string& entry,
double& num);
110 int main(
int argc,
char* argv[])
116 if(argc > 2 || (argc == 2 && strcasecmp(argv[1],
"--help") == 0)) {
117 cerr <<
"Usage: ld_config [SICK IP ADDRESS]" << endl
118 <<
"Ex. ld_config 192.168.1.11" << endl;
124 sick_ip_addr = argv[1];
128 sick_ld =
new SickLD(sick_ip_addr);
131 cout <<
"The Sick LIDAR C++/Matlab Toolbox " << endl;
132 cout <<
"Sick LD Config Utility " << endl;
141 cerr <<
"Initialize failed! Are you using the correct IP address?" << endl;
150 cout <<
"Enter your choice: (Ctrl-c to exit)" << endl;
151 cout <<
" [1] Set new configuration"<< endl;
152 cout <<
" [2] Show current settings"<< endl;
186 cout <<
"Quitting..." << endl;
197 cerr <<
"Uninitialize failed!" << endl;
202 cout <<
"Thanks for using the Sick LIDAR Matlab/C++ Toolbox!" << endl;
203 cout <<
"Bye Bye :o)" << endl;
214 string user_input_str;
215 getline(cin,user_input_str);
218 is_null_input =
true;
219 if (user_input_str.length() > 0) {
220 is_null_input =
false;
224 istringstream input_stream(user_input_str);
225 input_stream >> int_val;
238 cout <<
"config file: ";
239 getline(cin,filename);
253 double start_angs[SickLD::SICK_MAX_NUM_MEASURING_SECTORS] = {0};
254 double stop_angs[SickLD::SICK_MAX_NUM_MEASURING_SECTORS] = {0};
255 string scan_areas_str;
264 if(ifstream(config_path.c_str())) {
268 cerr <<
"Invalid filename!" << endl;
295 cerr <<
"ERROR: Parser failed to extract scan areas!" << endl;
300 cout << endl <<
"\tAttempting to configure the Sick LD..." << endl;
307 cerr <<
"ERROR: Couldn't set requested configuration!" << endl;
315 cout <<
"\t\tConfiguration Successfull!!!" << endl;
336 bool parseScanAreasStr(
string& areas,
double * start_angs,
double * stop_angs,
int& num_pairs) {
339 unsigned int start_pos = 0;
340 unsigned int end_pos = 0;
341 unsigned int split = 0;
345 start_pos = areas.find(
'[',start_pos);
346 end_pos = areas.find(
']',start_pos);
351 for(i=0; (start_pos != (
unsigned int)string::npos) && (i <= SickLD::SICK_MAX_NUM_MEASURING_SECTORS); i++) {
353 pair = areas.substr(start_pos+1,end_pos-(start_pos+1));
357 pair = pair.substr(pair.find_first_not_of(
' '));
361 cerr <<
"ERROR: There was an problem parsing your scan areas! Check your config file." << endl;
365 split = pair.find(
' ');
370 if(split == (
unsigned int)string::npos) {
371 cerr <<
"ERROR: Invalid sector definition." << endl;
376 if(!
parseNumStr(pair.substr(0,split),start_angs[i])) {
377 cerr <<
"ERROR: Invalid start angle found." << endl;
382 if(!
parseNumStr(pair.substr(split),stop_angs[i])) {
383 cerr <<
"ERROR: Invalid stop angle found." << endl;
390 start_pos = areas.find(
"[", start_pos);
391 end_pos = areas.find(
"]", start_pos);
398 if(num_pairs > SickLD::SICK_MAX_NUM_MEASURING_SECTORS) {
399 cerr <<
"ERROR: Too many scan areas found (max " << SickLD::SICK_MAX_NUM_MEASURING_SECTORS <<
")" << endl;
405 cerr <<
"ERROR: No scan areas found! Check brackets in your config file." << endl;
420 string num_str = entry.substr(entry.find_first_not_of(
' '));
421 istringstream input_stream(num_str.c_str());
422 if(!(input_stream >> num)) {
423 cerr <<
"ERROR: Invalid angle value: " + num_str << endl;
void printConfig()
Prints the current Sick status/config.
string getFilename()
Prompts the user for config filename.
#define CONFIG_OPT_SCAN_RES_STR
bool parseScanAreasStr(string &scan_areas_str, double *start_angs, double *stop_angs, int &num_sectors)
void setConfig()
Attempts to set the desired config via the driver. Parses configuration file as well.
#define INVALID_OPTION_STRING
bool parseNumStr(const string &entry, double &num)
void sigintHandler(int signal)
int main(int argc, char *argv[])
#define DEFAULT_SICK_IP_ADDRESS
Default Sick LD INet 4 address.
#define CONFIG_OPT_SCAN_AREA_STR
Defines the SickLD class for working with the Sick LD-OEM/LD-LRS long range LIDARs.
bool readInto(T &var, const string &key) const
#define CONFIG_OPT_MOTOR_SPD_STR
int getUserOption(bool &is_null_input)