Service not found error

I’m pasting my code here. services_quiz in ROS basics in 5 days course.

#! /usr/bin/env python

import rospy

from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageRequest

import rospkg

rospy.init_node(“service_srevices_quiz_client”)

rospy.wait_for_service("/move_bb8_in_square_custom")

move_bb8_in_square_service_client = rospy.ServiceProxy("/move_bb8_in_square_custom", BB8CustomServiceMessage)

move_bb8_in_square_request_object = BB8CustomServiceMessageRequest()

move_bb8_in_square_request_object.side = 1.5

if (move_bb8_in_square_request_object.side == 1.5):

move_bb8_in_square_requset_object.repetitions = 2

move_bb8_in_square_request_object.side = 2.5

if (move_bb8_in_square_request_object.side == 2.5):

move_bb8_in_square_request_object.repetitions = 1

rospy.loginfo (“Doing service call”)

result = move_bb8_in_square_service_client(move_bb8_in_square_request_object)

rospy.loginfo(str(result))

rospy.loginfo(“END of Service call…”)

This is code for client and similar way I’m mentioning server code. I’m also getting an error saying robot is not moving enough.

#! /usr/bin/env python

import rospy

from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageResponse

def callback(request):

rospy.info("Service has been called")

if (request.side >= 1 and request.side < 2):

    while (request.repetitions > 0):

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        request.repetitions = request.repetitions - 1

if (request.side >= 2):

    while (request.repetitions > 0):

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0 

        move.angular.z = 0.1

        move.angular.z = 0

        pub.publish(move)

        move.linear.x = request.side/sqrt(request.side)

        move.linear.x = 0

        move.angular.z = 0.1

        move.angular.z = 0 

        pub.publish(move)

        request.repetitions = request.repetitions - 1

rospy.loginfo("ServiceFinished")

response = BB8CustomServiceMessageResponse()

response.success = True

return response

rospy.init_node(“service_services_quiz_server”)

my_service = rospy.Service("/move_bb8_in_square_custom", BB8CustomServiceMessage, callback)

pub = rospy.Publisher("/cmd_vel", Twist, queue_size = 1)

move = Twist()

rospy.loginfo(“Service Ready”)

rospy.spin()

Please tell the error because compilation error is not happening after submission of the task it is shown on screen, but on screen it is showing service command not found while executing the code

Hi,

Please share a git or something that make more clear the code so that we can test it. Because formated like that , it could be anything, even indentation errors.

1 Like

I am not sure but just check your client launch file has the same rospy.init_node(“service_srevices_quiz_client”) name you made a spelling mistake that’s fine as long it’s the same.