How can I use my own srv in RosInterface

Typically: "How do I... ", "How can I... " questions
segger

How can I use my own srv in RosInterface

Post by segger »

Hi,
I'm now use the latest version that is V3_3_1. And I want to create a service client. The function "simExtRosInterface_serviceClient" need two parameters, and the second one is “topic type”. And here is my question, can this "topic type" be the type of our own? And how can I use it? Because I want to use the self defined rossrv.

Thanks!

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

Re: How can I use my own srv in RosInterface

Post by coppelia »

Hello,

you can add additional messages in file v_repExtRosInterface/meta/messages.txt. Then you will have to recompile the package.

Cheers

segger

Re: How can I use my own srv in RosInterface

Post by segger »

Thanks a lot! I've add my own service type into the RosInterface.
But here's another question: how to get the data from ROS?

Now, I've create a srv file like this:

Code: Select all

float64[6] q
---
float64[36] InvJac
And in V-REP script, I use "serviceClientHandle=simExtRosInterface_serviceClient('/get_inv_jacobian', 'vrep_ros_interface/GetInvJacobian')" to create a service client, (the "get_inv_jacobian" is the name of a ROS server which is already running ), then I use "j_v['q']={0.1, 0.2, 0.3, 0.4, 0.5, 0.6}" to assign the value of request, then use "clientCallResult=simExtRosInterface_call(serviceClientHandle,j_v)" to call the service. When doing this, the service server can get the request and run as it should do. But I can't get the response in V-REP. I've tried "j_v['InvJac']", "j_v['InvJac[1]']" etc, none of them can get the response I want.

Thanks!

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

Re: How can I use my own srv in RosInterface

Post by fferri »

Hello,
thanks for reporting this issue.

There was a bug, which now has been fixed.

If you don't want to wait for the next release, you can simply pull latest changes from v_repExtRosInterface.git and v_repStubsGen.git and recompile the RosInterface plugin by yourself.

By the way, the service response is written in the return argument of the call, so the correct code would be:

Code: Select all

serviceClientHandle=simExtRosInterface_serviceClient('/get_inv_jacobian', 'vrep_ros_interface/GetInvJacobian')
request={q={0.1, 0.2, 0.3, 0.4, 0.5, 0.6}}
response=simExtRosInterface_call(serviceClientHandle,request)
inv_jac=response.InvJac

segger

Re: How can I use my own srv in RosInterface

Post by segger »

Thank you for reply, but when I run the code:

Code: Select all

serviceClientHandle=simExtRosInterface_serviceClient('/get_inv_jacobian', 'vrep_ros_interface/GetInvJacobian')
request={q={0.1, 0.2, 0.3, 0.4, 0.5, 0.6}}
response=simExtRosInterface_call(serviceClientHandle,request)
inv_jac=response.InvJac
V-REP returns an error: " Lua runtime error: [string "SCRIPT Jaco"]:1127: attempt to index global 'response' (a boolean value) ".

Actually, the README.txt from https://github.com/fferri/v_repExtRosInterface is not very clear for me, and when I build the ROS plugin, I can't compile it at step 2) (maybe step 3?): "Compile the plugin using catkin tools". Thus, I use the command "catkin_make", but I get error: " Cannot find source file: generated/stubs.cpp ". So I copy the file stubs.h and stubs.cpp from the V-REP_PRO_EDU_V3_3_1_64_Linux/programming/ros_packages/v_repExtRosInterface into the directory respectively. After change a little in CMakeLists.txt, I can use the " catkin_make " to build the libv_repExtRosInterface.so.
Is that OK? Or is this the reason I can't use response=simExtRosInterface_call(serviceClientHandle,request). And how can I build the ROS plugin successfully the way in that README.txt.

Thank you!

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

Re: How can I use my own srv in RosInterface

Post by coppelia »

Hello,

you should use:

Code: Select all

catkin build
as described here.

You will have to install the catking build tools however.

Once that is done, you can compile with catkin build.
The easiest would be to use a script that fetches the source from the 2 repositories, maybe something like:

Code: Select all

#!/bin/bash

cd ~/Documents/v_rep/programming/ros_packages
rm -r -f ~/Documents/v_rep/programming/ros_packages/v_repExtRosInterface
git clone https://github.com/fferri/v_repExtRosInterface.git

source /opt/ros/indigo/setup.bash
rm -r -f ~/catkin_ws/*
mkdir ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ..
catkin_make
source devel/setup.bash
cp -r ~/Documents/v_rep/programming/ros_packages/* ~/catkin_ws/src/

cd ~/python-packages
rm -r -f ~/python-packages/*
git clone https://github.com/fferri/v_repStubsGen.git
export PYTHONPATH=$PYTHONPATH:~/python-packages
export PATH=$PATH:~/saxon/bin
cd ~/catkin_ws

#VERBOSE=1 catkin build -v -p1 -j1 --no-status
#catkin build -p1 -j1
catkin build

cp -r ~/catkin_ws/devel/lib/libv_repExtRosInterface.so ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/devel/lib/libv_repExtRos.so ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/devel/lib/libv_repExtRosSkeleton.so ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/src/ros_bubble_rob/bin/rosBubbleRob ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/src/ros_bubble_rob2/bin/rosBubbleRob2 ~/Documents/v-repLinuxItems64/variousCompiledItems/
Make sure to adjust above script to your own folder naming.

See also this file in order to install the other required items. This file applies to another project, but the tempita and SAXON items are also required.

If you compiled the source files contained in programming/ros_packages, then not all items are required, since it is a simplified version to avoid annoying the user who just wants to compile the package without modifying it.

Cheers

kleinash
Posts: 112
Joined: 28 Sep 2014, 09:58

Re: How can I use my own srv in RosInterface

Post by kleinash »

Using catkin build rather I get these issues - which I am working on, but if you have seen this before please let me know.

Errors << vrep_plugin_skeleton:make /home/ashley/catkin_ws/logs/vrep_plugin_skeleton/build.make.001.log
/usr/bin/ld: cannot find -lroslib
/usr/bin/ld: cannot find -lrospack
collect2: error: ld returned 1 exit status
make[2]: *** [/home/ashley/catkin_ws/devel/.private/vrep_plugin_skeleton/lib/libv_repExtRosSkeleton.so] Error 1
make[1]: *** [CMakeFiles/v_repExtRosSkeleton.dir/all] Error 2
make: *** [all] Error 2
cd /home/ashley/catkin_ws/build/vrep_plugin_skeleton; catkin build --get-env vrep_plugin_skeleton | catkin env -si /usr/bin/make --jobserver-fds=6,7 -j; cd -
........................................................................................................
Failed << vrep_plugin_skeleton:make [ Exited with code 2 ]
Failed <<< vrep_plugin_skeleton [ 1.2 seconds ]
Abandoned <<< ros_bubble_rob [ Unrelated job failed ]
Abandoned <<< vrep_plugin [ Unrelated job failed ]

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

Re: How can I use my own srv in RosInterface

Post by coppelia »

It seems you have not correctly installed ROS and/or the catkin build tools..

Cheers

kleinash
Posts: 112
Joined: 28 Sep 2014, 09:58

Re: How can I use my own srv in RosInterface

Post by kleinash »

Nope - it's my system rather. I am on 16.04, which cannot install indigo. I need to hop over to 14.04 and start again.

kleinash
Posts: 112
Joined: 28 Sep 2014, 09:58

Re: How can I use my own srv in RosInterface

Post by kleinash »

Everything is working and running as expected - thank you again for such an easy to use succinct system.


May I ask what these last commands are all about? :

cp -r ~/catkin_ws/devel/lib/libv_repExtRosInterface.so ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/devel/lib/libv_repExtRos.so ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/devel/lib/libv_repExtRosSkeleton.so ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/src/ros_bubble_rob/bin/rosBubbleRob ~/Documents/v-repLinuxItems64/variousCompiledItems/
cp -r ~/catkin_ws/src/ros_bubble_rob2/bin/rosBubbleRob2 ~/Documents/v-repLinuxItems64/variousCompiledItems/

Post Reply