Skip to content

Commit 1c0e7d2

Browse files
committed
resolved merge conflicts
2 parents 15d8319 + b376449 commit 1c0e7d2

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

scripts/machine.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from controller import Controller
99
from geometry_msgs.msg import PoseStamped
10+
from dynamixel_workbench_msgs.srv import SetPID
1011

1112
# Initialize controller
1213
ctrl = Controller()
@@ -133,12 +134,19 @@ def execute(self, userdata):
133134
# define state ChangePID
134135
class ChangePID(smach.State):
135136
def __init__(self):
136-
smach.State.__init__(self, outcomes=['changed'])
137+
smach.State.__init__(self, outcomes=['changed', 'not_changed'], input_keys=['joint_nums','PID'])
137138

138139
def execute(self, userdata):
139-
## Service call to change the PID values
140-
rospy.loginfo('Executing state ChangePID')
141-
return 'changed'
140+
rospy.wait_for_service('SetPID')
141+
try:
142+
set_PID = rospy.ServiceProxy('SetPID', SetPID)
143+
P,I,D = userdata.PID
144+
for joint_num in userdata.joint_nums:
145+
response = set_PID(joint_num, P, I, D)
146+
return 'changed'
147+
except rospy.ServiceException as e:
148+
rospy.logwarn("Service call failed:{0}".format(e))
149+
return 'not_changed'
142150

143151
# define state OpenGripper
144152
class OpenGripper(smach.State):
@@ -158,6 +166,8 @@ def main():
158166
# Create a SMACH state machine
159167
sm = smach.StateMachine(outcomes=['stop'])
160168
sm.userdata.tool_id = -1
169+
sm.userdata.joint_nums = [1,2,3]
170+
sm.userdata.PID = [0,0,0]
161171
sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
162172
sis.start()
163173
# Open the container
@@ -183,8 +193,9 @@ def main():
183193
transitions={'foundIK':'CHANGEPID'})
184194
# smach.StateMachine.add('MOVEGIVE', MoveGive(),
185195
# transitions={'reached':'CHANGEPID'})
196+
186197
smach.StateMachine.add('CHANGEPID', ChangePID(),
187-
transitions={'changed':'OPENGRIPPER'})
198+
transitions={'changed':'OPENGRIPPER', 'notchanged': 'CHANGEPID'})
188199
smach.StateMachine.add('OPENGRIPPER', OpenGripper(),
189200
transitions={'opened':'IDLE'})
190201

0 commit comments

Comments
 (0)