Skip to content

Commit 5404d7f

Browse files
committed
Made changes related to setpid values using service call
1 parent 4f11f0b commit 5404d7f

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

external/dynamixel-workbench-msgs/dynamixel_workbench_msgs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ add_service_files(
4747
WheelCommand.srv
4848
GetDynamixelInfo.srv
4949
DynamixelCommand.srv
50+
SetPID.srv
5051
)
5152

5253
generate_messages(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This message is used to set PID for different joints
2+
3+
uint8 joint_num #Possible values: joint_1_id : 1, joint_2_1_id: 2, joint_2_2_id: 3, joint_3_id: 4 joint_4_id: 5, joint_5_id: 6 , gripper: 7, pan: 8, tilt: 9
4+
uint8 P
5+
uint8 I
6+
uint8 D
7+
---
8+
bool result

external/dynamixel-workbench/dynamixel_workbench_controllers/include/dynamixel_workbench_controllers/position_control.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <dynamixel_workbench_toolbox/dynamixel_workbench.h>
3232
#include <dynamixel_workbench_msgs/DynamixelStateList.h>
3333
#include <dynamixel_workbench_msgs/JointCommand.h>
34+
#include <dynamixel_workbench_msgs/SetPID.h>
3435

3536
// Probably should make these constexpr
3637
#define GRIPPER_OPEN_MOTOR_POS -1.147412
@@ -66,6 +67,7 @@ class PositionControl
6667

6768
// ROS Service Server
6869
ros::ServiceServer joint_command_server_;
70+
ros::ServiceServer set_pid_server_;
6971

7072
// ROS Service Client
7173

@@ -128,6 +130,7 @@ class PositionControl
128130
void initServer();
129131
// bool jointCommandMsgCallback(dynamixel_workbench_msgs::JointCommand::Request &req,
130132
// dynamixel_workbench_msgs::JointCommand::Response &res);
133+
bool setPIDMsgCallback(dynamixel_workbench_msgs::SetPID::Request &req,dynamixel_workbench_msgs::SetPID::Response &res);
131134
void goalJointPositionCallback(const sensor_msgs::JointState::ConstPtr &msg);
132135
void gripperCloseCallback(const std_msgs::Empty::ConstPtr &msg);
133136
void gripperOpenCallback(const std_msgs::Empty::ConstPtr &msg);

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ void PositionControl::initSubscriber()
280280
void PositionControl::initServer()
281281
{
282282
// joint_command_server_ = node_handle_.advertiseService("joint_command", &PositionControl::jointCommandMsgCallback, this);
283+
set_pid_server_ = node_handle_.advertiseService("SetPID", &PositionControl::setPIDMsgCallback, this);
283284
}
284285

285286
void PositionControl::dynamixelStatePublish()
@@ -512,29 +513,15 @@ void PositionControl::controlLoop()
512513
cameraStatePublish();
513514
}
514515

515-
// bool PositionControl::jointCommandMsgCallback(dynamixel_workbench_msgs::JointCommand::Request &req,
516-
// dynamixel_workbench_msgs::JointCommand::Response &res)
517-
// {
518-
// int32_t goal_position = 0;
519-
// int32_t present_position = 0;
520-
521-
// if (req.unit == "rad")
522-
// {
523-
// goal_position = dxl_wb_->convertRadian2Value(req.id, req.goal_position);
524-
// }
525-
// else if (req.unit == "raw")
526-
// {
527-
// goal_position = req.goal_position;
528-
// }
529-
// else
530-
// {
531-
// goal_position = req.goal_position;
532-
// }
533-
534-
// bool ret = dxl_wb_->goalPosition(req.id, goal_position);
516+
bool PositionControl::setPIDMsgCallback(dynamixel_workbench_msgs::SetPID::Request &req,dynamixel_workbench_msgs::SetPID::Response &res)
517+
{
518+
int joint_num = req.joint_num;
519+
dxl_wb_arm_->itemWrite(dxl_id_arm_[joint_num], "Position_P_Gain", req.P);
520+
dxl_wb_arm_->itemWrite(dxl_id_arm_[joint_num], "Position_I_Gain", req.I);
521+
dxl_wb_arm_->itemWrite(dxl_id_arm_[joint_num], "Position_D_Gain", req.D);
535522

536-
// res.result = ret;
537-
// }
523+
res.result = true;
524+
}
538525

539526
void PositionControl::goalJointPositionCallback(const sensor_msgs::JointState::ConstPtr& msg)
540527
{

0 commit comments

Comments
 (0)