I’m doing the exam and I’m facing an issue I cannot solve by myself.
the problem is with task 2b, that requires creating a custom message.
my code is
#! /usr/bin/env python
import rospy
from std_msgs.msg import Empty as EmptyMsg
#from std_msgs.msg import Empty
from std_srvs.srv import EmptyResponse
from std_srvs.srv import Empty
from path_exam.srv import MyCustomServiceMessage, MyCustomServiceMessageResponse
#from std_msgs.msg import Empty as EmptyMsg
from geometry_msgs.msg import Twist
def my_callback(request):
i = 0
while i<5:
rospy.loginfo("taking off")
takeoff_pub.publish(takeoff_cmd)
rate.sleep()
i += 1
vel_cmd.linear.x = 1
j = 0
while j<5:
rospy.loginfo("moving foward")
vel_pub.publish(vel_cmd)
rate.sleep()
j += 1
vel_cmd.linear.x = 0
vel_pub.publish(vel_cmd)
rate.sleep()
k = 0
while k<5:
rospy.loginfo("landing")
landind_pub.publish(landing_cmd)
rate.sleep()
k += 1
response = MyCustomServiceMessageResponse()
#response.length = "The drone has moved 5 meters."
response.length = "The drone has moved 5 meters."
response.success = True
return response
# for the takeoff
takeoff_pub = rospy.Publisher('/drone/takeoff', EmptyMsg, queue_size=1)
takeoff_cmd = EmptyMsg()
# for the landing
landind_pub = rospy.Publisher('/drone/land', EmptyMsg, queue_size=1)
landing_cmd = EmptyMsg()
# for the movement
vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
vel_cmd = Twist()
rospy.init_node('service_client')
rate = rospy.Rate(1)
my_service = rospy.Service('/my_service' ,Empty, my_callback)
rospy.spin()
and my custom messages are
---
bool success
string length
when the callback function is completed and the responses written I get the error
ERROR: service [/my_service] responded with an error: service cannot process request: handler returned invalid value: Invalid number of arguments, args should be [] args are(success: True
length: "The drone has moved 5 meters.",)
I’ve tried using a float and a bool as responses but the problem persists.
what am I doing wrong?