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,)
I'm running the code below and getting the error stated above.
#!/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"
Unrelated to your question, but a problem you might run into at some point:
rospy.spin()
is not meant to be used inwhile not rospy.is_shutdown()
. You already haverate.sleep()
, bring that outside the if-block