Ask Your Question
0

ROS not liking the way I try to access certain functions included in header file? [closed]

asked 2014-07-23 16:49:41 -0500

randylewis7 gravatar image

updated 2014-07-24 11:28:17 -0500

Hello, I am currently trying to transform a C++ demo program I have for controlling a motor and laser scanner into a ROS node that will accomplish basically the same thing (but within ROS instead).

However, I am encountering some errors I don't know how to solve when compiling. ROS gives me an error for every line that tries to access a function in the header classes via an object and a dot seperator, but only when the function in question returns a value (no error for void functions). For example, in the cpp file I am trying to build, I have the lines

sickInterface.startSingleMeasurement(); //no error
success = sickInterface.getNextMeasurement(timestamp, scanData); //error: expected primary expression before ')' token

(I have successfully included the sickLMS115Interface.h file, and created the sickInterface object with the line

CSickLMS115Interface sickInterface;

)

However, ROS appears to not like the dot seperator, since I get the error "expected primary expression before ')' " on lines that attempt to access a non void header function via an object with arguments inputted, and the error "expected primary expression before '.' " on lines attempting to do the same thing, but without inputting arguments. The program compiled and functioned correctly before I tried to convert it to ROS. Any ideas what I'm doing wrong?

Here's my code (sorry its really long):

CMakeLists.txt: http://pastebin.com/TewfkZWz Actual node: http://pastebin.com/af2UTXGT Compilation errors: http://pastebin.com/c3K4uUCG

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by randylewis7
close date 2014-07-24 14:05:25.995550

Comments

can you post your code to get more info.

bvbdort gravatar image bvbdort  ( 2014-07-23 17:06:33 -0500 )edit

Yes, please provide more of your code, including your CMakeLists.txt and the full output of your compilation commad (including the command itself) that leads to these errors. Use pastebin.com or gist.github.com and provide the link(s) in your question if the code / output is long.

demmeln gravatar image demmeln  ( 2014-07-23 18:02:24 -0500 )edit
randylewis7 gravatar image randylewis7  ( 2014-07-24 11:27:13 -0500 )edit

Update: to control for errors that could have introduced by modifying the code, I created another cpp file in my same project with the exact original code (not yet modified by me). Original code:http://pastebin.com/0AuteZeM New compiler errors with original code: http://pastebin.com/KJYdy1mS

randylewis7 gravatar image randylewis7  ( 2014-07-24 12:53:30 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-07-24 13:14:17 -0500

ahendrix gravatar image

It looks like you have a type name shadowing a local variable name:

On line 211, there is a commented-out declaration of a scanData variable of type TSickLMS511ScanData

On line 219, you declare a variable named data with type scanData

Line 423 assumes that scanData is a variable

edit flag offensive delete link more

Comments

Ahh, I see. While combing the two programs I neglected to notice that one of the variables in one had the same name as a class in the other.

randylewis7 gravatar image randylewis7  ( 2014-07-24 14:04:52 -0500 )edit
1

answered 2014-07-24 00:37:24 -0500

McMurdo gravatar image

What is the name of the class and that of the object?

Have you created an object before you try the members/member functions? This is one case where such a compiler error occurs.

ROS is not a compiler or IDE. So when you say, ROS doesn't like something, it can not be the case.

Essentially what you are doing when you say, "I converted it to ROS", is -

  1. Using a few ros functions/classes (with their prototypes in the headers),
  2. Linking in a few shared libraries with the definitions/implementations of these functions/classes.

From the point of view of c++, ROS is a library, and hence using ROS in a program can not create compilation errors that were not already present (except in the rarest of circumstances).

Have a great day.

edit flag offensive delete link more

Comments

I do create the object befor using it to access the functions, using the line CSickLMS115Interface sickInterface; However, I'll admit that I don't understand where the "CSick" part comes from, as the class imported is just called "sickLMS115Interface.h" without the sick CSick part (I am not the original author of this program.

randylewis7 gravatar image randylewis7  ( 2014-07-24 11:56:02 -0500 )edit

And ok, maybe its not ROS per se that's messing up the compilation, it just feels that way because this code compiled before I tried to turn it into a ROS node. In all likelihood what's happening is that I screwed up something when I moved the code/modified it somewhat. So I'm really just trying to figure out what I screwed up. Thanks!

randylewis7 gravatar image randylewis7  ( 2014-07-24 12:00:14 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-07-23 16:49:41 -0500

Seen: 310 times

Last updated: Jul 24 '14