ROS service quiz

Hello, when I am doing my service quiz, I named the service message as MyCustomServiceMessage.srv instead of BB8CustomServiceMessage.srv. Everything works okay, but when the grader told me that I needed to use the name BB8CustomServiceMessage, I changed the name, but the arguments went wrong. Where did I miss to change?

image

Here is the code


Since you changed the service name, you probably need to recompile for the system to find it

In addition, make sure you create the message inside the services_quiz package itself. Don’t import from another package.

Hello @roalgoal and @bayodesegun.

I have recomile it using catkin_make and source devel/setup.bash. But the issue is still there.

The message is in side the services_quiz as shown below

Did you remember to change the name of the service added in CMakeLists.txt?

Yes. @roalgoal Here is my CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)

project(services_quiz)

Here is where all the packages needed to COMPILE the messages of topics, services and actions go.

It’s only getting its paths, and not really importing them to be used in the compilation.

It’s only for further functions in CMakeLists.txt to be able to find those packages.

In package.xml you have to state them as build

find_package(catkin REQUIRED COMPONENTS

std_msgs

message_generation

)

Generate services in the ‘srv’ folder

In this function will be all the action messages of this package ( in the action folder ) to be compiled.

You can state that it gets all the actions inside the action directory: DIRECTORY action

Or just the action messages stated explicitly: FILES my_custom_action.action

In your case you only need to do one of two things, as you wish.

add_service_files(

FILES

BB8CustomServiceMessage.srv

)

Here is where the packages needed for the action messages compilation are imported.

generate_messages(

DEPENDENCIES

std_msgs

)

State here all the packages that will be needed by someone that executes something from your package.

All the packages stated here must be in the package.xml as exec_depend

catkin_package(

CATKIN_DEPENDS rospy

)

include_directories(

${catkin_INCLUDE_DIRS}

)

<?xml version="1.0"?>

services_quiz

0.0.0

The services_quiz package

user

TODO

<buildtool_depend>catkin</buildtool_depend>

<build_depend>rospy</build_depend>

<build_depend>std_msgs</build_depend>

<build_depend>message_generation</build_depend>

<build_export_depend>rospy</build_export_depend>

<exec_depend>rospy</exec_depend>

<build_export_depend>std_msgs</build_export_depend>

<exec_depend>std_msgs</exec_depend>

<build_export_depend>message_runtime</build_export_depend>

<exec_depend>message_runtime</exec_depend>

This is my pkg. Would you mind taking a look at it?

Error message again

This is strange that it worked with a certain name but not the other. The issue probably lies in a sourcing problem. I would just create a new package from scratch since you know it has worked before.

@roalgoal Thank you so much, I figured out what is my problem now. My old oject request was from BB8CustomServiceMessage():requestobject = BB8CustomServiceMessage() # Create an object of type EmptyRequest When I changed to BB8CustomServiceMessageRequest() everything works now!

@roalgoal Hello Gonzalez, I think I meet the requirement but the autograder said it is not. What should be the problem? The task finished within 2 mins 47 secsdemo

Here is my code

Client

#! /usr/bin/env python
import rospkg
import rospy
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageRequest


rospy.init_node('service_move_bb8_in_square_custom_client') # Initialise a ROS node with the name service_client
rospy.wait_for_service('/move_bb8_in_square_custom') # Wait for the service client /move_bb8_in_circle_custom to be running
move_bb8_in_square_service_client = rospy.ServiceProxy('/move_bb8_in_square_custom', BB8CustomServiceMessage) # Create the connection to the service
requestobject = BB8CustomServiceMessageRequest() # Create an object of type EmptyRequest


"""
# BB8CustomServiceMessage
float64 side       # The distance of each side of the circle
int32 repetitions    # The number of times BB-8 has to execute the circle movement when the service is called
---
bool success         # Did it achieve it?
"""

requestobject.side = 4
requestobject.repetitions = 2

rospy.loginfo("Doing Service Call...")
result = move_bb8_in_square_service_client(requestobject) # Send through the connection the path to the trajectory file to be executed
rospy.loginfo(str(result)) # Print the result given by the service called

rospy.loginfo("END of Service call...")

Server

#! /usr/bin/env python

#! /usr/bin/env python

import rospy
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageResponse
from geometry_msgs.msg import Twist

def my_callback(request):
    my_response = BB8CustomServiceMessageResponse()
    sides = request.side
    reps = request.repetitions
    moveBB8(reps, sides)
    my_response.success = True
    return my_response.success

def straight(sides):
    wait_time = float(sides/2)
    move.linear.x = 0.5
    pub.publish(move)
    rospy.sleep(wait_time)
    move.linear.x = 0.0
    pub.publish(move)
    rospy.sleep(wait_time)

def rotate():
    move.angular.z = 0.195
    pub.publish(move)
    rospy.sleep(8)
    move.angular.z = 0
    pub.publish(move)
    rospy.sleep(1)

def moveBB8(reps, sides):
    i = 0
    j = 1
    while i < reps:    
        while j < 4:
            straight(sides)
            rotate()
            j+=1
        i+=1
        j=0

    while i == reps:    
        while j < 4:
            straight(sides)
            straight(sides)
            rotate()
            j+=1
        i+=1
        j=0

rospy.init_node('bb8_square') 

pub = rospy.Publisher('/cmd_vel', Twist, queue_size=3)
move = Twist()
my_service = rospy.Service('/move_bb8_in_square_custom', BB8CustomServiceMessage , my_callback) 
rospy.wait_for_service('/move_bb8_in_square_custom')

rate = rospy.Rate(10)

rospy.spin()

What does the grader say you got wrong?

Make sure all the terminals are killed before running the grader, and go through the instructions to make sure you didn’t miss something like a file name.

1 Like

@roalgoal Hi. So sorry for the late reply. Today I resubmitted again and grader gave 10 now. Everything GOOD. Thank you for your kind help!

This topic was automatically closed after 23 hours. New replies are no longer allowed.