Skip to content

Commit ab80f04

Browse files
committed
Set Drive_Mode on position control startup
1 parent f5c012e commit ab80f04

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

external/dynamixel-workbench/dynamixel_workbench_controllers/src/position_control.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
/* Authors: Taehun Lim (Darby) */
1818

19+
#include <stdexcept>
20+
#include <string>
21+
1922
#include "dynamixel_workbench_controllers/position_control.h"
2023

2124
PositionControl::PositionControl()
@@ -85,8 +88,28 @@ void PositionControl::initMsg()
8588
// Setting some placeholder I-D gains now, there are default P gains
8689
for (int index = 0; index < dxl_cnt_; index++)
8790
{
88-
dxl_wb_->itemWrite(dxl_id_[index], "Position_I_Gain", 5);
89-
dxl_wb_->itemWrite(dxl_id_[index], "Position_D_Gain", 50);
91+
bool write_pos_i_gain = dxl_wb_->itemWrite(dxl_id_[index], "Position_I_Gain", 5);
92+
bool write_pos_d_gain = dxl_wb_->itemWrite(dxl_id_[index], "Position_D_Gain", 50);
93+
bool write_drive_mode = dxl_wb_->itemWrite(dxl_id_[index], "Drive_Mode", 0);
94+
95+
// Assert the values have actually been written
96+
if (!write_pos_i_gain)
97+
{
98+
throw std::runtime_error(std::string("Could not write register \"Position_I_Gain\" for servo " +
99+
std::to_string(index)).c_str());
100+
}
101+
102+
if (!write_pos_d_gain)
103+
{
104+
throw std::runtime_error(std::string("Could not write register \"Position_D_Gain\" for servo " +
105+
std::to_string(index)).c_str());
106+
}
107+
108+
if (!write_drive_mode)
109+
{
110+
throw std::runtime_error(std::string("Could not write register \"Drive_Mode\" for servo " +
111+
std::to_string(index)).c_str());
112+
}
90113
}
91114

92115

0 commit comments

Comments
 (0)