Hi
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?
thanks
code:
#! /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
else:
res.success = False
pub.publish(var)
return res # the service Response class, in this case EmptyResponse
#return MyServiceResponse(len(request.words.split()))
rospy.init_node('service_server')
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.