Robotics StackExchange | Archived questions

I write a service client code. But I always take same error. I send codes. Please help. Error processing request: 'geriSayRequest' object has no attribute 'sonuc'

This is service code:

import rospy
from temizlik_robotu_pkg.srv import *
def servisCevapCB(istek):
    print(istek.sayi)
    istek.sonuc=1
    return istek

def servisSayma():
    rospy.init_node("servis_geri_say_nd")
    rospy.Service("geri_say", geriSay, servisCevapCB)
    rospy.spin()

servisSayma()

And this is client code:

import rospy
from temizlik_robotu_pkg.srv import *

def client():
    rospy.init_node("client_geri_say_nd")
    rospy.wait_for_service("geri_say")
    servis=rospy.ServiceProxy("geri_say", geriSay)

try:
    gelen_cevap=servis(5)

    print("sonuc: " +gelen_cevap.sonuc)
except rospy.ServiceException:
    print("servisde hata var")

client()

and this is .srv file:

int32 sayi
---

int32 sonuc

Asked by afkocamaz on 2023-06-28 10:41:18 UTC

Comments

Answers

Inside the service callback, you are passed a geriSayRequest object. The callback is expected to return a geriSayResponse object, so you must create one and fill in the field.

Asked by Mike Scheutzow on 2023-06-28 17:03:30 UTC

Comments