ros client not working

Typically: "How do I... ", "How can I... " questions
Post Reply
Hrithik Verma
Posts: 22
Joined: 07 Sep 2020, 21:20
Contact:

ros client not working

Post by Hrithik Verma »

I'm using a custom ros service data:

Code: Select all

rossrv show beginner_tutorials/AddTwoInts
int64 a
int64 b
---
int64 sum
I'm able to make server work perfectly fine (tested with terminal):

Code: Select all

function sysCall_init()
    -- do some initialization here
    sev = simROS.advertiseService('/add_server', 'beginner_tutorials/AddTwoInts', 'add_number')
end
function sysCall_cleanup()
    -- do some clean-up here
    simROS.shutdownServiceServer(sev)
end
function add_number(req)
    ans = req.a + req.b
    print(ans)
    p={sum=ans}
    return p
end

But problem client is not working. As soon as I hit play entire simulation just get stuck

Code: Select all

function sysCall_init()
    -- do some initialization here
    client = simROS.serviceClient('/add_server', 'beginner_tutorials/AddTwoInts')
    print(client)
    if client then
     values = {a=1,b=5}
     result=simROS.call(client, values)
    end
end
As soon as I hit play entire simulation just get stuck. after I do ctrl+c everything stop and I get error in the terminal.
7: failed to call service beginner_tutorials/AddTwoInts (in function 'simROS.call@simExtROS')
stack traceback:
[C]: in function 'simROS.call'
[string "Dummy@childScript"]:7: in function 'sysCall_init'
[Dummy@childScript:error] 22: non-existent object handle (in function 'simROS.shutdownServiceServer@simExtROS')
stack traceback:
[C]: in function 'simROS.shutdownServiceServer'
[string "Dummy@childScript"]:22: in function 'sysCall_cleanup'
I'm not sure how to write the "values" in simROS.call(). Let me know what is the write way to make ros client.
Thanks in advance !!!

fferri
Posts: 1230
Joined: 09 Sep 2013, 19:28

Re: ros client not working

Post by fferri »

Yes, that is the correct way of calling a ROS service from CoppeliaSim. If calling service fails maybe the service name or type are not correct.
Check with rosservice list etc...

I tested with the rospy_tutorials package, and calling the AddTwoInts service works as expected.

Code: Select all

function sysCall_init()
    client=simROS.serviceClient('/add_two_ints','rospy_tutorials/AddTwoInts')
    if client then print(simROS.call(client,{a=1,b=2})) end
end

function sysCall_cleanup()
    if client then simROS.shutdownServiceClient(client) end
end
prints:

Code: Select all

{
    sum=3,
}

Post Reply