Controlling Panda robot joint through ROS message

Typically: "How do I... ", "How can I... " questions
Post Reply
mvish7
Posts: 7
Joined: 18 Oct 2018, 14:29

Controlling Panda robot joint through ROS message

Post by mvish7 » 22 Oct 2018, 09:06

Hello,
I'm a beginner in ROS and VREP as well. My task is to control revolute joint of a robot model in vrep from a ROS message. I have following questions (which are absolutely very basic).

1. Which ROS messages i should be sending to control the angle of joint??(I have searched about joint_state_publisher topic, is it appropriate?)
2. How can i write a subscriber node in child script of a joint which receives joint angles and applies it to joints? Are there any tutorials regarding same?

Thank you for reading,i'll appreciate any kind of help.

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

Re: Controlling Panda robot joint through ROS message

Post by fferri » 22 Oct 2018, 12:52

You can use whatever message you like.

If you need to only transmit one float value, std_msgs/Float32 might suffice.

A standard ROS message used for joints is sensor_msgs./JointState.

There is a tutorial in the V-REP manual, which includes also creating a subscriber and listening for data.

Basically you need to define a function which will be called by the subscriber:

Code: Select all

function subscriber_callback(msg)
    sim.setJointTargetPosition(jointHandle, msg.data)
end
and add in sysCall_init():

Code: Select all

subscriber=simROS.subscribe('/joint_pos','std_msgs/Float32','subscriber_callback')

mvish7
Posts: 7
Joined: 18 Oct 2018, 14:29

Re: Controlling Panda robot joint through ROS message

Post by mvish7 » 22 Oct 2018, 15:50

Thank you for inputs.
Now i have created all the framework and I'm getting below error in vrep simulation.

--------------------------------------------------------------------------------
Error: [string -unknown location]:?: ros_callback__sensor_msgs__JointState: simCallScriptFunctionEx: error (subscriber_callback)
Lua runtime error: [string "CHILD SCRIPT panda_joint_2"]:14: One of the function's argument type is not correct. (sim.setJointTargetPosition)
stack traceback:
[C]: in function 'setJointTargetPosition'
[string "CHILD SCRIPT panda_joint_2"]:14: in function <[string "CHILD SCRIPT panda_joint_2"]:13>
Error: [string -unknown location]:?: ros_callback__sensor_msgs__JointState: simCallScriptFunctionEx: error (subscriber_callback)
Simulation stopped.
------------------------------------------------------------------------------------

please find below images.
1. child script written in vrep
[img][https://imageshack.com/a/img924/8664/bH8fji.png]

2. ros node for publishing sensor?msg
[img][/https://imageshack.com/a/img921/9684/aFl31v.png]

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

Re: Controlling Panda robot joint through ROS message

Post by fferri » 22 Oct 2018, 16:15

joint_state.velocity is an array.

Perhaps you wanted to do sim.setJointTargetPosition(j2_handle, joint_state.velocity[1]).

P.S. Please copy & paste your code, do not post screenshots of code.

mvish7
Posts: 7
Joined: 18 Oct 2018, 14:29

Re: Controlling Panda robot joint through ROS message

Post by mvish7 » 22 Oct 2018, 16:49

Hello,
using joint_state velocity as an array solved my error but there is no movement of joint to which child script is attached to.
I have also verified that rosInterface node is active(by rosnode list) and state_publisher also echos velocity field as follows:

Code: Select all

header: 
  seq: 380
  stamp: 
    secs: 1540218552
    nsecs: 749214928
  frame_id: ''
name: [joint_2]
position: []
velocity: [2.0545]
effort: []
this is the current code

Code: Select all

function sysCall_init()
    -- Get joint handles:
    j2_handle=sim.getObjectHandle('panda_joint_2')
    
    -- Enable subscriber:
    sub=simROS.subscribe('/joint_state', 'sensor_msgs/JointState', 'subscriber_callback')
    simROS.subscriberTreatUInt8ArrayAsString(sub)
end

function subscriber_callback(joint_state)
    sim.setJointTargetPosition(j2_handle,joint_state.velocity[1])
end

function sysCall_cleanup()
    simROS.shutdownSubscriber(sub)
end
i have also edited the subscriber_callback function as follows still there is no joint movement.

Code: Select all

function subscriber_callback(joint_state)
    local t=sim.getSimulationTime()
    sim.setJointTargetPosition(j2_handle, 0*math.pi*math.sin(joint_state.velocity[1]*t))
end

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

Re: Controlling Panda robot joint through ROS message

Post by fferri » 22 Oct 2018, 17:00

Probably some incorrect setting on the joint.

See Joint types and operation.

mvish7
Posts: 7
Joined: 18 Oct 2018, 14:29

Re: Controlling Panda robot joint through ROS message

Post by mvish7 » 23 Oct 2018, 12:39

Hello there,
Apologies as i'm posting the screen shot link once again as its about joint settings.
Below link shows the joint settings i'm having. From this i haven't got any clue about why the joint movement isn't working?



[img][https://imageshack.com/a/img922/686/52ucJd.png]

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

Re: Controlling Panda robot joint through ROS message

Post by fferri » 23 Oct 2018, 12:54

If you want to control the joint in position, enable the control loop.

Post Reply