Ask Your Question
0

How to use C in ROS Or Create Own ROS Package for Existing Code

asked 2014-12-30 03:22:21 -0600

KDROS gravatar image

Hello Everyone,

I stuck in one problem, I have done lots of work in different lets say C and Matlab, I can convert Matlab program to C. The main problem is How to create Own ROS package such that it can use all existing code, plz tell me in detail (coz i am newbie). How to call C program in ROS or How can I convert C into ROS program easily. I got one answer somewhere, we can cal from system(), but how I dont know.

Plz Help me Its urgent.

edit retag flag offensive close merge delete

Comments

gvdhoorn gravatar imagegvdhoorn ( 2014-12-30 03:30:05 -0600 )edit

Also:

Plz Help me Its urgent

Is not likely to get you any replies sooner.

gvdhoorn gravatar imagegvdhoorn ( 2014-12-30 03:31:11 -0600 )edit

GVDHOOM- I can understand, I guess same problem posted by my colleague also. It will be better if u would give answer rather than finding duplicate questions

KDROS gravatar imageKDROS ( 2014-12-31 05:18:23 -0600 )edit

It will be better if u would give answer rather than finding duplicate questions

Please understand that this is all people supporting you in their 'free' time. Moderators are here to make sure the site stays usable, and posting duplicate questions is not acceptable.

gvdhoorn gravatar imagegvdhoorn ( 2014-12-31 07:12:22 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2014-12-31 07:09:45 -0600

gvdhoorn gravatar image

updated 2014-12-31 07:13:19 -0600

Calling 'C from C++' is a bit of a non-issue: both are compilable by C++ compilers, provided you take proper care (symbol mangling, etc). This is also not very ROS specific. If you're using Matlab code generators, you should be able to call into that code from a C++ based ROS wrapper. Some links:

But again, this is not very ROS specific.

Now if you have an actual binary, that is a different matter. As you wrote in the How to create ROS package for Existing C code, you can execute those using system(). I can see two issues with that:

  1. Why system() is evil.
  2. Overhead: this is already mentioned by the link under point 1, but as you've tagged your question with opencv2, I'm assuming you'll want to do image processing, where processing latency is often undesirable. Starting, executing and stopping a binary for every frame is not going to be very efficient.

A third might be that you're not really integrating with ROS that way, and besides basic input-output wrapping you won't be able to access any of the nice things ROS can offer.

Btw: Mathworks has released an official ROS support package for Matlab 2012b and up. You might be interested in that as well.

edit flag offensive delete link more

Comments

Thanx gvdhoom, U guided me in right direction. Yes I am using image processing 3D construction, I have done coding in C for that and motion control but Now I want to use everything in ROS, then what should I do? I have to pass input also for motion control command and 3D constructions

KDROS gravatar imageKDROS ( 2015-01-01 03:25:29 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-12-30 03:22:21 -0600

Seen: 2,755 times

Last updated: Dec 31 '14