Skip to content
Snippets Groups Projects
Commit 20538f19 authored by Fernando Herrero's avatar Fernando Herrero
Browse files

dynamixel: modified test_dynamixel_server_no_scan, to iterate through buses...

dynamixel: modified test_dynamixel_server_no_scan, to iterate through buses and try 57600 and 1000000 baudrates
parent 7353771a
No related branches found
No related tags found
No related merge requests found
...@@ -21,9 +21,3 @@ ADD_EXECUTABLE(test_dynamixel_bulk_read test_dynamixel_bulk_read.cpp) ...@@ -21,9 +21,3 @@ ADD_EXECUTABLE(test_dynamixel_bulk_read test_dynamixel_bulk_read.cpp)
# edit the following line to add the necessary libraries # edit the following line to add the necessary libraries
TARGET_LINK_LIBRARIES(test_dynamixel_bulk_read dynamixel) 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)
...@@ -8,46 +8,69 @@ int main(int argc, char *argv[]) ...@@ -8,46 +8,69 @@ int main(int argc, char *argv[])
std::vector<int> devices; std::vector<int> devices;
CDynamixel *dyn_motor; CDynamixel *dyn_motor;
int num_buses=0; 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(); 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) if(num_buses>0)
{ {
dyn_server->config_bus(0,1000000); for(int b=0; b<num_buses; b++)
try{ {
dyn_motor=dyn_server->get_device(13); if(found)
std::cout << "device 13 found!!!" << std::endl; break;
dyn_server->free_device(13);
}catch(CException &e){
std::cout << "device 13 not found on bus 0" << std::endl; baudrate = 57600;
} dyn_server->config_bus(b,baudrate);
try{ std::string serial = dyn_server->get_bus_serial();
dyn_motor=dyn_server->get_device(12); std::cout << "For bus with id " << b << ", serial "<< serial << std::endl;
std::cout << "device 12 found!!!" << std::endl; std::cout << "Searching devices with baudrate " << baudrate << std::endl;
dyn_server->free_device(12); for(int i=first; i<=last; i++)
}catch(CException &e){ {
std::cout << "device 12 not found on bus 0" << std::endl; try
} {
try{ dyn_motor=dyn_server->get_device(i);
dyn_motor=dyn_server->get_device(1); int id = (int)dyn_motor->get_id();
std::cout << "device 1 found!!!" << std::endl; std::cout << "- FOUND device "<< id << " with baudrate " << baudrate << " on bus with id " << b << " and serial "<< serial << std::endl;
dyn_server->free_device(1); dyn_server->free_device(i);
}catch(CException &e){ found=true;
std::cout << "device 1 not found on bus 0" << std::endl; break;
} }
try{ catch(CException &e)
dyn_motor=dyn_server->get_device(1); {
std::cout << "device 1 found!!!" << std::endl; std::cout << "- Device "<< i << " not found" << std::endl;
dyn_server->free_device(1); }
}catch(CException &e){ }
std::cout << "device 1 not found on bus 0" << std::endl;
} if(found)
try{ break;
dyn_motor=dyn_server->get_device(1);
std::cout << "device 1 found!!!" << std::endl; baudrate = 1000000;
dyn_server->free_device(1); std::cout << "Searching devices with baudrate " << baudrate << std::endl;
}catch(CException &e){ dyn_server->config_bus(b,baudrate);
std::cout << "device 1 not found on bus 0" << std::endl; 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;
}
}
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment