read control cycle from .robot file

This commit is contained in:
ROBOTIS-zerom
2016-12-14 17:19:52 +09:00
parent 0afd62afb3
commit 41a8e30731
4 changed files with 32 additions and 14 deletions

View File

@ -48,17 +48,23 @@
#define DYNAMIXEL "dynamixel"
#define SENSOR "sensor"
#define SESSION_CONTROL_INFO "control info"
#define SESSION_PORT_INFO "port info"
#define SESSION_DEVICE_INFO "device info"
#define SESSION_TYPE_INFO "type info"
#define SESSION_CONTROL_TABLE "control table"
#define DEFAULT_CONTROL_CYCLE 8 // milliseconds
namespace robotis_framework
{
class Robot
{
private:
int control_cycle_msec_;
public:
std::map<std::string, dynamixel::PortHandler *> ports_; // string: port name
std::map<std::string, std::string> port_default_device_; // port name, default device name
@ -70,6 +76,8 @@ public:
Sensor *getSensor(std::string path, int id, std::string port, float protocol_version);
Dynamixel *getDynamixel(std::string path, int id, std::string port, float protocol_version);
int getControlCycle();
};
}

View File

@ -76,6 +76,7 @@ static inline std::vector<std::string> split(const std::string &text, char sep)
}
Robot::Robot(std::string robot_file_path, std::string dev_desc_dir_path)
: control_cycle_msec_(DEFAULT_CONTROL_CYCLE)
{
if (dev_desc_dir_path.compare(dev_desc_dir_path.size() - 1, 1, "/") != 0)
dev_desc_dir_path += "/";
@ -106,7 +107,16 @@ Robot::Robot(std::string robot_file_path, std::string dev_desc_dir_path)
continue;
}
if (session == SESSION_PORT_INFO)
if (session == SESSION_CONTROL_INFO)
{
std::vector<std::string> tokens = split(input_str, '=');
if (tokens.size() != 2)
continue;
if (tokens[0] == "control_cycle")
control_cycle_msec_ = std::atoi(tokens[1].c_str());
}
else if (session == SESSION_PORT_INFO)
{
std::vector<std::string> tokens = split(input_str, '|');
if (tokens.size() != 3)
@ -485,3 +495,7 @@ Dynamixel *Robot::getDynamixel(std::string path, int id, std::string port, float
return dxl;
}
int Robot::getControlCycle()
{
return control_cycle_msec_;
}