Skip to content
Snippets Groups Projects
Commit 3cdf3407 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added support to get dynamixel converters from the serial number instead of...

Added support to get dynamixel converters from the serial number instead of the usb index, which is more robust.
Previous API using the usb index is still supported.
parent a8cf47a8
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ CDynamixelServer::CDynamixelServer()
this->comm_dev=NULL;
this->bus_info.baud_rate=-1;
this->bus_info.bus_id=-1;
this->bus_info.serial="";
}
CDynamixelServer::CDynamixelServer(const CDynamixelServer& object)
......@@ -86,7 +87,10 @@ void *CDynamixelServer::scan_thread(void *param)
while(!end)
{
try{
serial=ftdi_server->get_serial_number(dyn_server->bus_info.bus_id);
if(dyn_server->bus_info.bus_id!=-1)
serial=ftdi_server->get_serial_number(dyn_server->bus_info.bus_id);
else
serial=dyn_server->bus_info.serial;
dyn_server->comm_dev=ftdi_server->get_device(serial);
for(freq=0;freq<9;freq++)
{
......@@ -153,6 +157,26 @@ void CDynamixelServer::config_bus(int bus_id, int baudrate)
// this->set_baudrate(baudrate);
}
void CDynamixelServer::config_bus(std::string &bus_id, int baudrate)
{
TFTDIconfig ftdi_config;
// set the desired bus identifier
this->set_bus_id(bus_id);
// set the desired baudrate for the bus
/* reconfigure the communciations device */
ftdi_config.word_length=8;
ftdi_config.stop_bits=1;
ftdi_config.parity=0;
ftdi_config.read_timeout = 1000;
ftdi_config.write_timeout = 1000;
ftdi_config.latency_timer = 1;
ftdi_config.baud_rate=baudrate;
this->comm_dev->config(&ftdi_config);
this->bus_info.baud_rate=baudrate;
// this->set_baudrate(baudrate);
}
int CDynamixelServer::get_num_buses(void)
{
CFTDIServer *ftdi_server=CFTDIServer::instance();
......@@ -184,6 +208,11 @@ int CDynamixelServer::get_bus_id(void)
return this->bus_info.bus_id;
}
std::string &CDynamixelServer::get_bus_serial(void)
{
return this->bus_info.serial;
}
void CDynamixelServer::set_bus_id(int bus_id)
{
CFTDIServer *ftdi_server=CFTDIServer::instance();
......@@ -207,13 +236,45 @@ void CDynamixelServer::set_bus_id(int bus_id)
serial=ftdi_server->get_serial_number(bus_id);
this->comm_dev=ftdi_server->get_device(serial);
this->bus_info.bus_id=bus_id;
this->bus_info.serial=serial;
}
}
}
void CDynamixelServer::set_bus_id(std::string &bus_id)
{
CFTDIServer *ftdi_server=CFTDIServer::instance();
if(bus_id.size()==0)
{
/* handle exception */
throw CDynamixelServerException(_HERE_,"Invalid bus serial number");
}
else
{
if(this->comm_dev!=NULL)
{
this->comm_dev->close();
delete this->comm_dev;
this->comm_dev=NULL;
}
this->comm_dev=ftdi_server->get_device(bus_id);
if(this->comm_dev==NULL)
{
/* handle exception */
throw CDynamixelServerException(_HERE_,"No device found with the given serial number");
}
else
{
this->bus_info.bus_id=-1;
this->bus_info.serial=bus_id;
}
}
}
void CDynamixelServer::start_scan(void)
{
if(this->bus_info.bus_id==-1)
if(this->bus_info.bus_id==-1 && this->bus_info.serial.size()==0)
{
/* handle exceptions */
throw CDynamixelServerException(_HERE_,"No bus has been selected.");
......@@ -233,12 +294,13 @@ void CDynamixelServer::stop_scan(void)
this->event_server->set_event(this->stop_scan_event_id);
this->thread_server->end_thread(this->scan_thread_id);
this->bus_info.bus_id=-1;
this->bus_info.serial="";
}
}
bool CDynamixelServer::is_scan_done(void)
{
if(this->bus_info.bus_id!=-1)
if(this->bus_info.bus_id!=-1 || this->bus_info.serial.size()>0)
{
if(this->state==dyn_scan_done)
return true;
......@@ -302,7 +364,7 @@ CDynamixel *CDynamixelServer::get_device(int dev_id)
unsigned int i=0;
this->dynamixel_access.enter();
if(this->bus_info.bus_id==-1)
if(this->bus_info.bus_id==-1 && this->bus_info.serial.size()==0)
{
this->dynamixel_access.exit();
/* handle exceptions */
......
......@@ -47,6 +47,7 @@ typedef struct
{
int baud_rate;
int bus_id;
std::string serial;
}TBus_info;
typedef struct
......@@ -154,6 +155,11 @@ class CDynamixelServer
*
*/
void set_bus_id(int bus_id);
/**
* \brief
*
*/
void set_bus_id(std::string &bus_id);
public:
/**
* \brief
......@@ -165,6 +171,11 @@ class CDynamixelServer
*
*/
void config_bus(int bus_id,int baudrate);
/**
* \brief
*
*/
void config_bus(std::string &bus_id,int baudrate);
/**
* \brief
*
......@@ -180,6 +191,11 @@ class CDynamixelServer
*
*/
int get_bus_id(void);
/**
* \brief
*
*/
std::string &get_bus_serial(void);
/**
* \brief
*
......
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