Reading joint angles using Ros

Typically: "How do I... ", "How can I... " questions
Post Reply
shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Reading joint angles using Ros

Post by shadowzone »

Hello i was trying to read joint angles using ros
First i created a topic in syscall init in a non-threaded child script after playing a bit with controlled with ros scene example

Code: Select all

if simROS then
print("<font color='#0F0'>ROS interface was found.</font>@html")

ab1SensorTopicHandler=simROS.advertise('/'..'bc1sensortopic','std_msgs/Float32')

end
then tried to publish on this topic using the following code

Code: Select all

function sysCall_sensing()
    a = {} 
    rrhip=sim.getObjectHandle("bc1")
    value=sim.getJointPosition(rrhip)

    a[1]=value
    print(a[1])
    

    print(ab1SensorTopicHandler)
    simROS.publish(ab1SensorTopicHandler,value)
end
and i got the following error saying float 32 expected a table

Code: Select all

Lua runtime error: [string "CHILD SCRIPT body_respondable"]:55: read__std_msgs__Float32: expected a table (simROS.publish @ 'RosInterface' plugin)
stack traceback:
    [C]: in function 'publish'
    [string "CHILD SCRIPT body_respondable"]:55: in function  
so i defined a table and tried replacing "Value" in ros.pubblish with 'a[1]' and 'a' but i still get the same error
I'm fairly new to ros and lua

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

Re: Reading joint angles using Ros

Post by fferri »

shadowzone wrote: 23 Feb 2020, 14:36 Hello i was trying to read joint angles using ros
First i created a topic in syscall init in a non-threaded child script after playing a bit with controlled with ros scene example

Code: Select all

if simROS then
print("<font color='#0F0'>ROS interface was found.</font>@html")

ab1SensorTopicHandler=simROS.advertise('/'..'bc1sensortopic','std_msgs/Float32')

end
then tried to publish on this topic using the following code

Code: Select all

function sysCall_sensing()
    a = {} 
    rrhip=sim.getObjectHandle("bc1")
    value=sim.getJointPosition(rrhip)

    a[1]=value
    print(a[1])
    

    print(ab1SensorTopicHandler)
    simROS.publish(ab1SensorTopicHandler,value)
end
and i got the following error saying float 32 expected a table

Code: Select all

Lua runtime error: [string "CHILD SCRIPT body_respondable"]:55: read__std_msgs__Float32: expected a table (simROS.publish @ 'RosInterface' plugin)
stack traceback:
    [C]: in function 'publish'
    [string "CHILD SCRIPT body_respondable"]:55: in function  
so i defined a table and tried replacing "Value" in ros.pubblish with 'a[1]' and 'a' but i still get the same error
I'm fairly new to ros and lua
std_msgs/Float32 needs a 'data' field. Change your code to:

Code: Select all

function sysCall_sensing()
    rrhip=sim.getObjectHandle("bc1")
    value=sim.getJointPosition(rrhip)
    local msg={}
    msg.data=value    
    simROS.publish(ab1SensorTopicHandler,msg)
end

shadowzone
Posts: 16
Joined: 17 Feb 2020, 22:49

Re: Reading joint angles using Ros

Post by shadowzone »

fferri wrote: 24 Feb 2020, 09:44
shadowzone wrote: 23 Feb 2020, 14:36 Hello i was trying to read joint angles using ros
First i created a topic in syscall init in a non-threaded child script after playing a bit with controlled with ros scene example

Code: Select all

if simROS then
print("<font color='#0F0'>ROS interface was found.</font>@html")

ab1SensorTopicHandler=simROS.advertise('/'..'bc1sensortopic','std_msgs/Float32')

end
then tried to publish on this topic using the following code

Code: Select all

function sysCall_sensing()
    a = {} 
    rrhip=sim.getObjectHandle("bc1")
    value=sim.getJointPosition(rrhip)

    a[1]=value
    print(a[1])
    

    print(ab1SensorTopicHandler)
    simROS.publish(ab1SensorTopicHandler,value)
end
and i got the following error saying float 32 expected a table

Code: Select all

Lua runtime error: [string "CHILD SCRIPT body_respondable"]:55: read__std_msgs__Float32: expected a table (simROS.publish @ 'RosInterface' plugin)
stack traceback:
    [C]: in function 'publish'
    [string "CHILD SCRIPT body_respondable"]:55: in function  
so i defined a table and tried replacing "Value" in ros.pubblish with 'a[1]' and 'a' but i still get the same error
I'm fairly new to ros and lua
std_msgs/Float32 needs a 'data' field. Change your code to:

Code: Select all

function sysCall_sensing()
    rrhip=sim.getObjectHandle("bc1")
    value=sim.getJointPosition(rrhip)
    local msg={}
    msg.data=value    
    simROS.publish(ab1SensorTopicHandler,msg)
end
thanks it works now ^^

Post Reply