MyCustomServiceMessage object attribute is read only


in Services in ROS: Servers & Messages I created a service that its message is

int32 duration
bool success

when calling the service I get a message

service [/move_bb8_in_circle_custom] responded with an error: b"error processing request: 'MyCustomServiceMessageResponse' object attribute 'success' is read-only"

How can it be fixed?


#! /usr/bin/env python

import rospy

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

from my_custom_srv_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageResponse # you import the service message python classes 

from std_msgs.msg import Int32  

from geometry_msgs.msg import Twist 

#rospy.init_node('move robot node')

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

var = Twist()

def my_callback(request):

    print("My_callback has been called")


    res = MyCustomServiceMessageResponse()

    var.linear.x = -0.5

    var.angular.z = 0.5

    if request.duration > 5.0:

        var.linear.x = -0

        var.angular.z = 0

        res.success = True


        res.success = False



    return res # the service Response class, in this case EmptyResponse

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


my_service = rospy.Service('/move_bb8_in_circle_custom', MyCustomServiceMessage , my_callback) # create the Service called my_service with the defined callback

rospy.spin() # maintain the service open.

Hi @NahumL welcome to the community,
Would you show your script so we can have a better look to help you?

I updated with the code.

Have you compiled your package and sourced using source devel/setup.bash?

I built the package and used source devel/setup.bash

@bayodesegun @u1802520 this is happening when I use this message also in other packages

Did you compile with sudo? I suggest you remove the build and devel folders and try recompiling:

cd ~/catkin_ws
rm -rf build/ devel/
catkin build
source devel/setup.bash

Hi @NahumL

In my case, to avoid this error, I had to do cd ~/catkin_ws and source devel/setup.bash in every terminal I used.