Skip to content

Commit b376449

Browse files
committed
Added joint_nums and PID as user input
1 parent da53eb5 commit b376449

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/machine.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@ def execute(self, userdata):
134134
# define state ChangePID
135135
class ChangePID(smach.State):
136136
def __init__(self):
137-
smach.State.__init__(self, outcomes=['changed', 'not_changed'], input_keys=['joint_num','P', 'I', 'D'])
137+
smach.State.__init__(self, outcomes=['changed', 'not_changed'], input_keys=['joint_nums','PID'])
138138

139139
def execute(self, userdata):
140140
rospy.wait_for_service('SetPID')
141141
try:
142142
set_PID = rospy.ServiceProxy('SetPID', SetPID)
143-
response = set_PID(userdata.joint_num, userdata.P, userdata.I, userdata.D)
143+
P,I,D = userdata.PID
144+
for joint_num in userdata.joint_nums:
145+
response = set_PID(joint_num, P, I, D)
144146
return 'changed'
145147
except rospy.ServiceException as e:
146148
rospy.logwarn("Service call failed:{0}".format(e))
@@ -164,6 +166,8 @@ def main():
164166
# Create a SMACH state machine
165167
sm = smach.StateMachine(outcomes=['stop'])
166168
sm.userdata.tool_id = -1
169+
sm.userdata.joint_nums = [1,2,3]
170+
sm.userdata.PID = [0,0,0]
167171
sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
168172
sis.start()
169173
# Open the container
@@ -190,10 +194,6 @@ def main():
190194
# smach.StateMachine.add('MOVEGIVE', MoveGive(),
191195
# transitions={'reached':'CHANGEPID'})
192196

193-
sm.userdata.P = 0
194-
sm.userdata.I = 0
195-
sm.userdata.D = 0
196-
197197
smach.StateMachine.add('CHANGEPID', ChangePID(),
198198
transitions={'changed':'OPENGRIPPER', 'notchanged': 'CHANGEPID'})
199199
smach.StateMachine.add('OPENGRIPPER', OpenGripper(),

0 commit comments

Comments
 (0)