Skip to content

Commit 69b4b5f

Browse files
authored
Merge pull request #38 from ROBOTIS-GIT/master
Merge for sync kinetic-devel and master branch
2 parents f14a1fc + c42dadf commit 69b4b5f

File tree

5 files changed

+64
-14
lines changed

5 files changed

+64
-14
lines changed

robotis_controller/include/robotis_controller/robotis_controller.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ class RobotisController : public Singleton<RobotisController>
9595
void initializeSyncWrite();
9696

9797
public:
98-
static const int CONTROL_CYCLE_MSEC = 8; // 8 msec
99-
10098
bool DEBUG_PRINT;
10199
Robot *robot_;
102100

robotis_controller/src/robotis_controller/robotis_controller.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void RobotisController::initializeSyncWrite()
6161
if (gazebo_mode_ == true)
6262
return;
6363

64-
ROS_INFO("FIRST BULKREAD");
64+
//ROS_INFO("FIRST BULKREAD");
6565
for (auto& it : port_to_bulk_read_)
6666
it.second->txRxPacket();
6767
for(auto& it : port_to_bulk_read_)
@@ -72,15 +72,15 @@ void RobotisController::initializeSyncWrite()
7272
{
7373
if (++error_count > 10)
7474
{
75-
ROS_ERROR("[RobotisController] bulk read fail!!");
75+
ROS_ERROR("[RobotisController] first bulk read fail!!");
7676
exit(-1);
7777
}
7878
usleep(10 * 1000);
7979
result = it.second->txRxPacket();
8080
} while (result != COMM_SUCCESS);
8181
}
8282
init_pose_loaded_ = true;
83-
ROS_INFO("FIRST BULKREAD END");
83+
//ROS_INFO("FIRST BULKREAD END");
8484

8585
// clear syncwrite param setting
8686
for (auto& it : port_to_sync_write_position_)
@@ -603,7 +603,7 @@ void RobotisController::initializeDevice(const std::string init_file_path)
603603

604604
void RobotisController::gazeboTimerThread()
605605
{
606-
ros::Rate gazebo_rate(1000 / CONTROL_CYCLE_MSEC);
606+
ros::Rate gazebo_rate(1000 / robot_->getControlCycle());
607607

608608
while (!stop_timer_)
609609
{
@@ -662,7 +662,7 @@ void RobotisController::msgQueueThread()
662662
ros::ServiceServer joint_module_server = ros_node.advertiseService("/robotis/get_present_joint_ctrl_modules",
663663
&RobotisController::getCtrlModuleCallback, this);
664664

665-
ros::WallDuration duration(CONTROL_CYCLE_MSEC / 1000.0);
665+
ros::WallDuration duration(robot_->getControlCycle() / 1000.0);
666666
while(ros_node.ok())
667667
callback_queue.callAvailable(duration);
668668
}
@@ -679,8 +679,8 @@ void *RobotisController::timerThread(void *param)
679679

680680
while (!controller->stop_timer_)
681681
{
682-
next_time.tv_sec += (next_time.tv_nsec + CONTROL_CYCLE_MSEC * 1000000) / 1000000000;
683-
next_time.tv_nsec = (next_time.tv_nsec + CONTROL_CYCLE_MSEC * 1000000) % 1000000000;
682+
next_time.tv_sec += (next_time.tv_nsec + controller->robot_->getControlCycle() * 1000000) / 1000000000;
683+
next_time.tv_nsec = (next_time.tv_nsec + controller->robot_->getControlCycle() * 1000000) % 1000000000;
684684

685685
controller->process();
686686

@@ -1429,7 +1429,7 @@ void RobotisController::addMotionModule(MotionModule *module)
14291429
}
14301430
}
14311431

1432-
module->initialize(CONTROL_CYCLE_MSEC, robot_);
1432+
module->initialize(robot_->getControlCycle(), robot_);
14331433
motion_modules_.push_back(module);
14341434
motion_modules_.unique();
14351435
}
@@ -1451,7 +1451,7 @@ void RobotisController::addSensorModule(SensorModule *module)
14511451
}
14521452
}
14531453

1454-
module->initialize(CONTROL_CYCLE_MSEC, robot_);
1454+
module->initialize(robot_->getControlCycle(), robot_);
14551455
sensor_modules_.push_back(module);
14561456
sensor_modules_.unique();
14571457
}
@@ -1731,7 +1731,7 @@ void RobotisController::setJointCtrlModuleThread(const robotis_controller_msgs::
17311731
for(std::list<MotionModule *>::iterator _stop_m_it = _stop_modules.begin(); _stop_m_it != _stop_modules.end(); _stop_m_it++)
17321732
{
17331733
while((*_stop_m_it)->isRunning())
1734-
usleep(CONTROL_CYCLE_MSEC * 1000);
1734+
usleep(robot_->getControlCycle() * 1000);
17351735
}
17361736

17371737
// disable module(s)
@@ -1946,7 +1946,7 @@ void RobotisController::setCtrlModuleThread(std::string ctrl_module)
19461946
for (auto stop_m_it = stop_modules.begin(); stop_m_it != stop_modules.end(); stop_m_it++)
19471947
{
19481948
while ((*stop_m_it)->isRunning())
1949-
usleep(CONTROL_CYCLE_MSEC * 1000);
1949+
usleep(robot_->getControlCycle() * 1000);
19501950
}
19511951

19521952
// disable module(s)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[device info]
2+
model_name = OPEN-CR
3+
device_type = sensor
4+
5+
[control table]
6+
# addr | item name | length | access | memory | min value | max value | signed
7+
0 | model_number | 2 | R | EEPROM | 0 | 65535 | N
8+
2 | version_of_firmware | 1 | R | EEPROM | 0 | 254 | N
9+
3 | ID | 1 | RW | EEPROM | 0 | 252 | N
10+
4 | baudrate | 1 | RW | EEPROM | 0 | 252 | N
11+
5 | return_delay_time | 1 | RW | EEPROM | 0 | 254 | N
12+
16 | status_return_level | 1 | RW | EEPROM | 0 | 2 | N
13+
24 | torque_enable | 1 | RW | RAM | 0 | 1 | N
14+
25 | LED | 1 | RW | RAM | 0 | 7 | N
15+
26 | LED_RGB | 2 | RW | RAM | 0 | 32767 | N
16+
28 | buzzer | 2 | RW | RAM | 0 | 65535 | N
17+
30 | button | 1 | R | RAM | 0 | 15 | N
18+
31 | present_voltage | 1 | R | RAM | 50 | 250 | N
19+
32 | gyro_x | 2 | R | RAM | -32800 | 32800 | Y
20+
34 | gyro_y | 2 | R | RAM | -32800 | 32800 | Y
21+
36 | gyro_z | 2 | R | RAM | -32800 | 32800 | Y
22+
38 | acc_x | 2 | R | RAM | -32768 | 32768 | Y
23+
40 | acc_y | 2 | R | RAM | -32768 | 32768 | Y
24+
42 | acc_z | 2 | R | RAM | -32768 | 32768 | Y
25+
44 | roll | 2 | R | RAM | 0 | 4096 | N
26+
46 | pitch | 2 | R | RAM | 0 | 4096 | N
27+
48 | yaw | 2 | R | RAM | 0 | 4096 | N
28+
50 | imu_control | 1 | RW | RAM | 0 | 255 | N
29+
30+

robotis_device/include/robotis_device/robot.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,23 @@
4848
#define DYNAMIXEL "dynamixel"
4949
#define SENSOR "sensor"
5050

51+
#define SESSION_CONTROL_INFO "control info"
5152
#define SESSION_PORT_INFO "port info"
5253
#define SESSION_DEVICE_INFO "device info"
5354

5455
#define SESSION_TYPE_INFO "type info"
5556
#define SESSION_CONTROL_TABLE "control table"
5657

58+
#define DEFAULT_CONTROL_CYCLE 8 // milliseconds
59+
5760
namespace robotis_framework
5861
{
5962

6063
class Robot
6164
{
65+
private:
66+
int control_cycle_msec_;
67+
6268
public:
6369
std::map<std::string, dynamixel::PortHandler *> ports_; // string: port name
6470
std::map<std::string, std::string> port_default_device_; // port name, default device name
@@ -70,6 +76,8 @@ class Robot
7076

7177
Sensor *getSensor(std::string path, int id, std::string port, float protocol_version);
7278
Dynamixel *getDynamixel(std::string path, int id, std::string port, float protocol_version);
79+
80+
int getControlCycle();
7381
};
7482

7583
}

robotis_device/src/robotis_device/robot.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static inline std::vector<std::string> split(const std::string &text, char sep)
7676
}
7777

7878
Robot::Robot(std::string robot_file_path, std::string dev_desc_dir_path)
79+
: control_cycle_msec_(DEFAULT_CONTROL_CYCLE)
7980
{
8081
if (dev_desc_dir_path.compare(dev_desc_dir_path.size() - 1, 1, "/") != 0)
8182
dev_desc_dir_path += "/";
@@ -106,7 +107,16 @@ Robot::Robot(std::string robot_file_path, std::string dev_desc_dir_path)
106107
continue;
107108
}
108109

109-
if (session == SESSION_PORT_INFO)
110+
if (session == SESSION_CONTROL_INFO)
111+
{
112+
std::vector<std::string> tokens = split(input_str, '=');
113+
if (tokens.size() != 2)
114+
continue;
115+
116+
if (tokens[0] == "control_cycle")
117+
control_cycle_msec_ = std::atoi(tokens[1].c_str());
118+
}
119+
else if (session == SESSION_PORT_INFO)
110120
{
111121
std::vector<std::string> tokens = split(input_str, '|');
112122
if (tokens.size() != 3)
@@ -485,3 +495,7 @@ Dynamixel *Robot::getDynamixel(std::string path, int id, std::string port, float
485495
return dxl;
486496
}
487497

498+
int Robot::getControlCycle()
499+
{
500+
return control_cycle_msec_;
501+
}

0 commit comments

Comments
 (0)