Example 6.8, Exercise 6.3 "Has no attribute 'duration'"

Hello Everyone, please help!
I have been working through the services section of ROS in 5 Days. I am currently stuck with an error that MyCustomServiceMessage has no attribute ‘duration’. I have remdade the package, ensured catkin_make was succesful, even by compiling individual packages and I have sourced my workspace on every shell. To no prevail!

Here is my_custom_srv_msg_pkg
srv/MyCustomServiceMessage.srv

int32 duration  
---
bool success 

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(my_custom_srv_msg_pkg)


## 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
  MyCustomServiceMessage.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}
)```

package.xml
<?xml version="1.0"?>

my_custom_srv_msg_pkg

0.0.0

The my_custom_srv_msg_pkg 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>

```

Here is my bb8_move_custom_service_server.py

#! /usr/bin/env python

import rospy

# you import the service message python classes generated from Empty.srv.

from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest, MyCustomServiceMessageResponse

from geometry_msgs.msg import Twist

def my_callback(request):

    move = Twist()

    move.linear.x = 0

    move.angular.z = 0

    pub.publish(move)

    print("My_callback has been called")

    # the service Response class, in this case EmptyResponse

    return MyCustomServiceMessageResponse()

    # return MyServiceResponse(len(request.words.split()))

rospy.init_node('bb8_service_server')

# create the Service called my_service with the defined callback

my_service = rospy.Service(

    '/move_bb8_in_circle_custom', MyCustomServiceMessage, my_callback)

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

rospy.spin()  # maintain the service open.

I have been so focused on getting the custom service working I haven’t even explored BB8 control yet. Any suggestions greatly appreciated! thank you!

I changed the CMakeList and Package files within the same package as the service server python file and now it works, I think. I am not sure if this was the fix

2 Likes

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