diff --git a/src/examples/CMakeLists.txt b/src/examples/CMakeLists.txt index 39de6f4d4188bcfbc32f28d164d53f79e6a8dba7..84fb9f2eae1127ff64cb3ffe8ed1ef1be10bcc66 100644 --- a/src/examples/CMakeLists.txt +++ b/src/examples/CMakeLists.txt @@ -21,9 +21,3 @@ ADD_EXECUTABLE(test_dynamixel_bulk_read test_dynamixel_bulk_read.cpp) # edit the following line to add the necessary libraries TARGET_LINK_LIBRARIES(test_dynamixel_bulk_read dynamixel) - -# edit the following line to add the source code for the example and the name of the executable -ADD_EXECUTABLE(test_new_firmware test_new_firmware.cpp) - -# edit the following line to add the necessary libraries -TARGET_LINK_LIBRARIES(test_new_firmware dynamixel) diff --git a/src/examples/test_dynamixel_server_no_scan.cpp b/src/examples/test_dynamixel_server_no_scan.cpp index 7bce23afa085beefbe154b469f5e0322b6eabf4a..4f0ae53f600dffacdad3566e85bc29c520ccf21d 100644 --- a/src/examples/test_dynamixel_server_no_scan.cpp +++ b/src/examples/test_dynamixel_server_no_scan.cpp @@ -8,46 +8,69 @@ int main(int argc, char *argv[]) std::vector<int> devices; CDynamixel *dyn_motor; int num_buses=0; + int baudrate; //57600 or 100000 + bool found=false; + int first=0; + int last=5; + if(argc==3) + { + first = atoi(argv[1]); + last = atoi(argv[2]); + } num_buses=dyn_server->get_num_buses(); - std::cout << "Num. buses: " << num_buses << std::endl; + std::cout << "Found " << num_buses << " buses" << std::endl; if(num_buses>0) { - dyn_server->config_bus(0,1000000); - try{ - dyn_motor=dyn_server->get_device(13); - std::cout << "device 13 found!!!" << std::endl; - dyn_server->free_device(13); - }catch(CException &e){ - std::cout << "device 13 not found on bus 0" << std::endl; - } - try{ - dyn_motor=dyn_server->get_device(12); - std::cout << "device 12 found!!!" << std::endl; - dyn_server->free_device(12); - }catch(CException &e){ - std::cout << "device 12 not found on bus 0" << std::endl; - } - try{ - dyn_motor=dyn_server->get_device(1); - std::cout << "device 1 found!!!" << std::endl; - dyn_server->free_device(1); - }catch(CException &e){ - std::cout << "device 1 not found on bus 0" << std::endl; - } - try{ - dyn_motor=dyn_server->get_device(1); - std::cout << "device 1 found!!!" << std::endl; - dyn_server->free_device(1); - }catch(CException &e){ - std::cout << "device 1 not found on bus 0" << std::endl; - } - try{ - dyn_motor=dyn_server->get_device(1); - std::cout << "device 1 found!!!" << std::endl; - dyn_server->free_device(1); - }catch(CException &e){ - std::cout << "device 1 not found on bus 0" << std::endl; + for(int b=0; b<num_buses; b++) + { + if(found) + break; + + + baudrate = 57600; + dyn_server->config_bus(b,baudrate); + std::string serial = dyn_server->get_bus_serial(); + std::cout << "For bus with id " << b << ", serial "<< serial << std::endl; + std::cout << "Searching devices with baudrate " << baudrate << std::endl; + for(int i=first; i<=last; i++) + { + try + { + dyn_motor=dyn_server->get_device(i); + int id = (int)dyn_motor->get_id(); + std::cout << "- FOUND device "<< id << " with baudrate " << baudrate << " on bus with id " << b << " and serial "<< serial << std::endl; + dyn_server->free_device(i); + found=true; + break; + } + catch(CException &e) + { + std::cout << "- Device "<< i << " not found" << std::endl; + } + } + + if(found) + break; + + baudrate = 1000000; + std::cout << "Searching devices with baudrate " << baudrate << std::endl; + dyn_server->config_bus(b,baudrate); + for(int i=first; i<=last; i++) + { + try + { + dyn_motor=dyn_server->get_device(i); + std::cout << "- Device "<< i << " FOUND!!! on bus "<< b << " with baudrate " << baudrate << std::endl; + dyn_server->free_device(i); + found=true; + break; + } + catch(CException &e) + { + std::cout << "- Device "<< i << " not found" << std::endl; + } + } } } }