Skip to content

Commit fdf3809

Browse files
authored
Merge pull request #2 from dash-robotics/feature/dynamic_gains
Feature/dynamic gains
2 parents 4f11f0b + 23e39a1 commit fdf3809

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
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
{

scripts/ik_control.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from std_msgs.msg import Float64
1313
from std_msgs.msg import Empty
1414
from trac_ik_python.trac_ik import IK
15-
# import camera_forward_kinematics
15+
# import camera_forward_kinematics
1616
import tf
1717
import PRM
1818

@@ -29,6 +29,7 @@
2929
IK_POSITION_TOLERANCE = 0.01
3030
IK_ORIENTATION_TOLERANCE = np.pi/9
3131
current_joint_state = None
32+
MIN_CLOSING_GAP = 0.002
3233

3334

3435
def home_arm(pub):
@@ -56,8 +57,10 @@ def set_arm_joint(pub, joint_target):
5657

5758
def get_joint_state(data):
5859
global current_joint_state
60+
global current_gripper_state
5961
# if len(data.position) == 9:
60-
current_joint_state = data.position[0:5]
62+
current_gripper_state = data.positions[7:9]
63+
current_joint_state = data.positions[0:5]
6164

6265
def open_gripper(pub):
6366
empty_msg = Empty()
@@ -106,14 +109,14 @@ def compute_ik(ik_solver, target_pose, current_joint):
106109
def main():
107110
rospy.init_node('IK_Control', anonymous=True)
108111
global current_joint_state
109-
112+
110113
rad_from_deg = np.pi/180.
111114
deg_from_rad = 180./np.pi
112115

113116
ik_solver = IK(ARM_BASE_LINK, GRIPPER_LINK)
114117
# ck = camera_forward_kinematics.camerakinematics()
115118

116-
# Describing the publisher subscribers
119+
# Describing the publisher subscribers
117120
rospy.Subscriber('/joint_states', JointState, get_joint_state)
118121

119122
arm_pub = rospy.Publisher(ROSTOPIC_SET_ARM_JOINT, JointState, queue_size=1)
@@ -129,7 +132,7 @@ def main():
129132
#home_joint = [0.0, 0.0, 1.22, -0.142, 0.0]
130133
set_arm_joint(arm_pub, home_joint)
131134
close_gripper(gripper_close_pub)
132-
set_camera_angles(pan_pub, tilt_pub, rad_from_deg*0., rad_from_deg*40.0) #, ck)
135+
set_camera_angles(pan_pub, tilt_pub, rad_from_deg*0., rad_from_deg*40.0) #, ck)
133136

134137
rospy.sleep(10)
135138

@@ -143,11 +146,11 @@ def main():
143146
break
144147
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException) as e:
145148
print(e)
146-
149+
147150
O = tf.transformations.euler_from_quaternion(Q)
148151
Q = tf.transformations.quaternion_from_euler(0, np.pi/2, O[2])
149152
Q1 = tf.transformations.quaternion_from_euler(0, np.pi/2, O[2]+np.pi/2)
150-
153+
151154
poses = [Pose(Point(P[0], P[1], P[2]+0.20), Quaternion(Q[0], Q[1], Q[2], Q[3])),
152155
Pose(Point(P[0], P[1], P[2]+0.15), Quaternion(Q[0], Q[1], Q[2], Q[3])),
153156
Pose(Point(P[0], P[1], P[2]+0.25), Quaternion(Q[0], Q[1], Q[2], Q[3])),
@@ -187,9 +190,12 @@ def main():
187190
if itr == 0 or itr == 3:
188191
open_gripper(gripper_open_pub)
189192
rospy.sleep(4)
190-
if itr == 1:
193+
if itr == 1:
191194
close_gripper(gripper_close_pub)
192195
rospy.sleep(4)
196+
# Use the following condition to detect if the object is grasped or not
197+
if(np.abs(current_gripper_state[0]) < MIN_CLOSING_GAP and np.abs(current_gripper_state[1] < MIN_CLOSING_GAP)):
198+
state = "Not grabbed"
193199
rospy.sleep(4)
194200
itr += 1
195201

@@ -225,4 +231,4 @@ def main():
225231

226232
# q = tf.transformations.quaternion_from_euler(0, 90, 0)
227233
# poses = [Pose(Point(0.3, 0.000, 0.25), Quaternion(q[0], q[1], q[2], q[3])),
228-
# Pose(Point(0.3, 0.000, 0.10), Quaternion(q[0], q[1], q[2], q[3]))]
234+
# Pose(Point(0.3, 0.000, 0.10), Quaternion(q[0], q[1], q[2], q[3]))]

0 commit comments

Comments
 (0)