ERROR: service [/thruster_state] responded with an error: service cannot process request: handler returned invalid value: Invalid number of arguments, args should be ['success', 'message'] args are(False,)

asked 2020-05-19 22:25:23 -0500

updated 2020-05-20 03:13:37 -0500

gvdhoorn gravatar image

I'm running the code below and getting the error stated above. I'm I'm calling the service with rosservice call /thruster_state "data: false"

 #!/usr/bin/env python 
import rospy
from std_msgs.msg import String
from std_srvs.srv import SetBool

state = False
flag = 0
def thrusterstate(req):
    if req.data:
        global flag
        global state
        flag = 1
        state = True
        return True,"thruster is on"

     global flag
     global state
     flag = 1
     state = False
     return False,"thruster is off"


if __name__=="__main__":
    rospy.init_node("task2pynode")
    rospy.loginfo("Service Server started")
    service = rospy.Service ("/thruster_state",SetBool,thrusterstate)
    pub = rospy.Publisher("/thruster_message",String,queue_size = 10)
    rate = rospy.Rate(1)
    while not rospy.is_shutdown():
        msg = String()
        global state
        global flag
        if flag == 1:
            if state:
                msg.data = "ON"
            else:
                msg.data = "OFF"
            pub.publish(msg)
            rate.sleep()
        flag = 0
        rospy.spin()

I'm calling the service with rosservice call /thruster_state "data: false"

edit retag flag offensive close merge delete