sim.setJointPosition is not working inside the callback function of subscriber in ROS.Please help me

Report crashes, strange behaviour, or apparent bugs
Post Reply
slgrajeshwar36172
Posts: 5
Joined: 06 Nov 2019, 04:34
Location: iit patna
Contact:

sim.setJointPosition is not working inside the callback function of subscriber in ROS.Please help me

Post by slgrajeshwar36172 »

Code: Select all

function sysCall_init()
        
    -- Get some handles:
    joint=sim.getObjectHandle('Joint')
    
    -- Enable an image publisher and subscriber:
    sub=simROS.subscribe('/joint_topic', 'std_msgs/Float64', 'joint_callback')
    simROS.subscriberTreatUInt8ArrayAsString(sub) -- treat uint8 arrays as strings (much faster, tables/arrays are kind of slow in Lua)
   
end


function joint_callback(msg)
    -- Apply the received image to the passive vision sensor that acts as an image container
    print(msg.data)
    --sim.setJointTargetVelocity(joint,msg.data)
    sim.setJointPosition(joint,(math.pi/180) *msg.data)
end


function sysCall_cleanup()
    simROS.shutdownSubscriber(sub)
end

sim.setJointPosition is not working inside the call back function but interesting thing is that sim.setJointTargetVelocity is working properly.
please help me
Thank you

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: sim.setJointPosition is not working inside the callback function of subscriber in ROS.Please help me

Post by coppelia »

Hello,

first, you do not need simROS.subscriberTreatUInt8ArrayAsString for that subscriber.

second, what do you mean with it is not working? Is there a message error? What is the behaviour? Of course, if your joint is in force/torque mode with position control enabled, then you can't use sim.setJointPosition. You'll have to use sim.setJointTargetPosition.

Cheers

slgrajeshwar36172
Posts: 5
Joined: 06 Nov 2019, 04:34
Location: iit patna
Contact:

Re: sim.setJointPosition is not working inside the callback function of subscriber in ROS.Please help me

Post by slgrajeshwar36172 »

coppelia wrote: 11 Nov 2019, 07:08 Hello,

first, you do not need simROS.subscriberTreatUInt8ArrayAsString for that subscriber.

second, what do you mean with it is not working? Is there a message error? What is the behaviour? Of course, if your joint is in force/torque mode with position control enabled, then you can't use sim.setJointPosition. You'll have to use sim.setJointTargetPosition.

Cheers
it is not working means
whenever i publish 60 to the topic it joint should move to 60 degree due to the command sim.setJointPosition but joint is not moving at all. Same problem is facing while using the sim.setJointTargetPosition and my joint is in force/torque mode with position control enabled. there is no error msg during the execution.
how can i use sim.setJointPosition in callback function???

sir i have used sim.setJointPosition in sysCall_actuation and it is working means it is going to desired position in force/torque mode with position control enabled.

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: sim.setJointPosition is not working inside the callback function of subscriber in ROS.Please help me

Post by coppelia »

Not sure what is going on. Are you using a non-threaded child script? Is the message arriving in the callback? (simply insert a print to check that)

Cheers

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

Re: sim.setJointPosition is not working inside the callback function of subscriber in ROS.Please help me

Post by fferri »

I tested sim.setJointPosition and it works fine also in a ROS callback.

If your joint doesn't move, you have research the cause in the joint mode and the resulting behaviour. Make sure to read and understand Joint types and operation.

Post Reply