service state request callback function, error: Invalid number of arguments
Hi,
I created a service with the following definition and i called it navigation.srv:
float64 srvtype
float64 wayPointX
float64 wayPointY
float64 wayPointZ
float64 LDFlag
---
std_msgs/String navResponse
Then I used the service state machine provided from smach and following the tutorials:
import roslib;
import rospy
import actionlib
import smach
import smach_ros
import time
from std_msgs.msg import String
from sensor_msgs.msg import RegionOfInterest
from geometry_msgs.msg import PoseStamped
from kuri_msgs.srv import navigation
from kuri_msgs.msg import Object
from sensor_msgs.msg import NavSatFix
from nav_msgs.msg import Odometry
from smach_ros import ServiceState
FixPoseX = 0
FixPoseY = 0
FixPoseZ = 10
class Ch1():
rospy.init_node('ch1_state_machine')
sm = smach.StateMachine(outcomes=['Done'])
with sm:
def exploration_request_cb (userdata,request):
exploration_request = navigation().Request
exploration_request.srvtype=1
exploration_request.wayPointX = FixPoseX
exploration_request.wayPointY = FixPoseY
exploration_request.wayPointZ = FixPoseZ
exploration_request.LDFlag = 0
return exploration_request
smach.StateMachine.add('EXPLORATION',
ServiceState('controller_service',
navigation,
request = exploration_request_cb),
transitions={'succeeded':'MARKER_DETECTION' , 'aborted':'Done', 'preempted':'EXPLORATION'})
### MORE STATES HERE
sis = smach_ros.IntrospectionServer('server_name', sm, '/SM_ROOT')
sis.start()
# Execute SMACH plan
outcome = sm.execute()
rospy.spin()
sis.stop()
if __name__ == '__main__':
Ch1()
The Service the I am using to be called ( I am also having a problem in sending back a response is as follow)
when I run the state machine it says that it is waiting for the service then I run the service the output is the following:
import roslib
import rospy
from kuri_msgs.msg import *
from kuri_msgs.srv import navigation
from kuri_msgs.srv import navigationResponse
from geometry_msgs.msg import PoseStamped
from nav_msgs.msg import Odometry
class ControllerService:
def __init__(self):
print 'Starting Service 1'
self.s = rospy.Service('controller_service', navigation , self.pos_vel_controller)
def pos_vel_controller(self , req):
self.landFlagDone = req.LDFlag
if req.srvtype == 1 :
x = req.wayPointX
y = req.wayPointY
z = req.wayPointZ
if self.landFlagDone >0:
#######################3 How to return a response here ???????????????????
return 'succeeded'
else:
return 'aborted'
def main(args):
rospy.init_node('Controller_Service')
Controller = ControllerService()
try:
rospy.spin()
except KeyboardInterrupt:
print "Shutting down"
if __name__ == '__main__':
main(sys.argv)
In the service terminal Killed
In the state machine terminal
TypeError: Invalid number of arguments, args should be ['srvtype', 'wayPointX', 'wayPointY', 'wayPointZ', 'LDFlag'] args are(<function exploration_request_cb at 0x7f0f3fae6140>,)
What is the mistake in this code and how can I fix it ?