Go to Post Why not go the safer route? Use the robots to play Magic the Gathering. - kamocat [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-01-2009, 11:36
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
define a new class(C++)

hello, i'v been trying to define a new class of my own in c++
and i dont know why but the Windriver isnt recognizing my class..

where i need to put the H and the Cpp files?

do i need to define the class in the Windriver somehow?


tnanks alot
Reply With Quote
  #2   Spotlight this post!  
Unread 28-01-2009, 15:37
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
hello, i'v been trying to define a new class of my own in c++ and i dont know why but the Windriver isnt recognizing my class..
where i need to put the H and the Cpp files?
do i need to define the class in the Windriver somehow?
tnanks alot
Please elaborate on what you mean when you say Windriver isn't recognizing your class.
Have you created a downloadable kernel module project?
If so, have added the .h and .cpp file(s) to that project?
If so, have you built the containing project?
You haven't given enough information about what you've tried and how you went about things.
Reply With Quote
  #3   Spotlight this post!  
Unread 28-01-2009, 17:44
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
Re: define a new class(C++)

My code is working , i dont have any problems while downloading the code to
the robot ,

When you say to add the H and Cpp files , you mean copy them to the directory? or that i need to make another proccess in the WindRiver to add them?

and yes , i can build my project , the Windriver isnt recognize the class
unlike the Jaguar or the PWM classes for example...

hope you understand... thanks anyway..
Reply With Quote
  #4   Spotlight this post!  
Unread 28-01-2009, 17:57
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
add the H and Cpp files , you mean copy them to the directory?
OK, what you need to do is drag the files from a Windows explorer window and drop them right onto the project in the Workbench Project Navigator view.
They will then become part of your project and will be compiled and linked with it.
Make sure to drop the files on the top of the project -- not somewhere in the middle. The best thing to do is collapse the project so you can't see any of what's inside. That way, you can't miss with dragging and dropping.

Here's a snippet from the Eclipse documentation (which should be avaliable to you by using Help->Help Contents in Workbench)

Importing files

Files can be imported into the Workbench either by :

* dragging and dropping from the file system, or
* copying and pasting from the file system, or
* Using the Import wizard.

Using drag and drop or copy/paste to import files relies on operating system support that is not necessarily available on all platforms. If the platform you are using does not have this support, you can always use the Import wizard.

Last edited by gvarndell : 28-01-2009 at 18:29. Reason: extra info
Reply With Quote
  #5   Spotlight this post!  
Unread 28-01-2009, 18:02
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: define a new class(C++)

Your question is still a little confusing. Do you see the files that you created in the tree on the left? If not, follow the instructions below.

If you're creating files from scratch, right click on the project and go to add new file (don't remember the exact command). This will add an empty file to your project directory.

If you already created the files, you can copy them into your project directory just like you would any other file (via Windows Explorer, shell, etc). You will then need to right click on the project and go to refresh in order for the files to show up in the tree.

If the files are in the source tree, does the compiler attempt to build them? If you intentionally add a syntax error does the compiler catch it? If not, check the build target in the tree (I think it's green) and check to see if it is picking up all files in your project.

Are you adding a #include or forward declaration in the files that use the classes?

If there are compiler errors that you are getting, it would be helpful for you to post them here. That way people will be able to help you pinpoint your problem.
Reply With Quote
  #6   Spotlight this post!  
Unread 29-01-2009, 09:33
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
Re: define a new class(C++)

I tried to drugg the files to the project and right , my class suddenly is being recognize by the code, but now the class i'v belt is not recognize the other classes like PWM or DigitalInput and so on (thats the errors that i get)
Reply With Quote
  #7   Spotlight this post!  
Unread 29-01-2009, 09:49
gvarndell's Avatar
gvarndell gvarndell is offline
Software Engineer
AKA: Addi's and Georgie's Dad
FRC #1629 (GaCo)
Team Role: Parent
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Grantsville, Maryland
Posts: 350
gvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond reputegvarndell has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
I tried to drugg the files to the project and right , my class suddenly is being recognize by the code, but now the class i'v belt is not recognize the other classes like PWM or DigitalInput and so on (thats the errors that i get)
You have transitioned from Workbench problem to basic C++ programming problem. I'll have to let others help you with that but I would suggest providing more information than you have. People tend to not help when it's too much work.
Reply With Quote
  #8   Spotlight this post!  
Unread 29-01-2009, 14:40
Pancake Pancake is offline
Registered User
FRC #0991 (The Dukes)
Team Role: Photography
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Phoenix
Posts: 11
Pancake is an unknown quantity at this point
Re: define a new class(C++)

Typically, there's two files, the header file and the CPP file.

Example Header
Code:
// Camera.h
#ifndef CAMERA_H
#define CAMERA_H

class Camera
{
public:
    void doSometing();
};

#endif
Then make a .cpp file with the same name as the header file:
Code:
// Camera.cpp

#include "Camera.h"

void Camera::doSomething()
{
    printf("Doing something...");
}
Now when you get to the robot code, all you need to do is simply include the "Camera.h" file:

Code:
//MyRobot.cpp
#include "Camera.h"

class MyRobot : public SimpleRobot
{
    /* Code ommited for simplicity */
    void Autonomous()
    {
        Camera c();
        c.doSomething();
    }
};

START_ROBOT_CLASS(MyRobot);
Hope this example helps...
__________________
Team Webmaster
Reply With Quote
  #9   Spotlight this post!  
Unread 29-01-2009, 16:01
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
Re: define a new class(C++)

Make sure that you put in the proper include files at the top of your class source files. For example, look your example robot code as provided by WPI and look at the top of the file. There are #include files there. Make sure that you have enough includes to recognize the wpi library. The simplest is to #include "WPILib.h"
Reply With Quote
  #10   Spotlight this post!  
Unread 29-01-2009, 17:46
nadavsen2 nadavsen2 is offline
Registered User
FRC #2231
 
Join Date: Jan 2009
Location: israel
Posts: 31
nadavsen2 is an unknown quantity at this point
Re: define a new class(C++)

i didnt put those lines

#ifndef CAMERA_H
#define CAMERA_H

and the #endif..

what is this macro? or its not macro?

and why in the OperatorControl you access you class by typing
Camera c();

and not
Camera *c;
c = new Camera();

?
Reply With Quote
  #11   Spotlight this post!  
Unread 29-01-2009, 18:08
wt200999's Avatar
wt200999 wt200999 is online now
Texas Instruments
AKA: Will Toth
FRC #3005 (Robochargers)
Team Role: Mentor
 
Join Date: Mar 2006
Rookie Year: 2004
Location: Dallas, Texas
Posts: 325
wt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud ofwt200999 has much to be proud of
Send a message via MSN to wt200999
Re: define a new class(C++)

http://www.cplusplus.com/doc/tutorial/

(or any other C++ tutorial/book)
__________________
Programming in LabVIEW? Try VI Snippets!

FIRST LEGO League 2004 - 2005
FRC Team 870 Student 2006 - 2009
FRC Team 3005 Mentor 2013 -
Reply With Quote
  #12   Spotlight this post!  
Unread 29-01-2009, 18:14
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by nadavsen2 View Post
i didnt put those lines

#ifndef CAMERA_H
#define CAMERA_H

and the #endif..

what is this macro? or its not macro?
It's called a header guard. You can read about it here or here

Quote:
why in the OperatorControl you access you class by typing
Camera c();

and not
Camera *c;
c = new Camera();
In the end both of those do the same thing, instantiate a Camera called c. Which one you use depends on how you plan to use it. If you're only using it in that location and you don't need to pass it around, you can use the non-pointer version. If you plan to be passing the object around, or it is an attribute of a class you'll want to use the pointer approach.

Last edited by Dave Scheck : 29-01-2009 at 18:16.
Reply With Quote
  #13   Spotlight this post!  
Unread 01-11-2010, 23:05
ehlochbr ehlochbr is offline
Registered User
FRC #2990
 
Join Date: Nov 2010
Location: Salem, OR
Posts: 37
ehlochbr is an unknown quantity at this point
Re: define a new class(C++)

I'm having a similar problem as described above. I'm trying to get the Logitech Gamepad to work with our robot. I've found the .h and .cpp files I need. I've included the .h file in the WPILib and included the reference (#include) at the top of my source program. Do I need to do something with the .cpp file? If so, what?

Windriver will build my project just fine and download it to the robot. The problem is that the robot doesn't recognize the code. It acts like there isn't anything there. The only thing I can think of is that I must be doing something wrong with the gamepad files. Please help!

Thanks,
Eric
Reply With Quote
  #14   Spotlight this post!  
Unread 02-11-2010, 09:32
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: define a new class(C++)

Quote:
Originally Posted by ehlochbr View Post
I'm having a similar problem as described above. I'm trying to get the Logitech Gamepad to work with our robot. I've found the .h and .cpp files I need. I've included the .h file in the WPILib
I'll need more information to confirm, but I think your problem comes with the above statement.

I'm assuming that you took the gamepad .cpp and .h and put it in the WPILib directory, included it in your robot cpp file, built it and it failed at runtime. This is actually what I would expect because when you built, the compiler was able to find the gamepad.h file in the WPILib directory so it appeared to build fine. When the robot tried to run one of the gamepad specific members/methods, it failed because the gamepad class was never compile. Why? Because when you build your robot project, WPILib doesn't get rebuilt. Want proof? Go into your cpp file, take out a semicolon, and rebuild. You won't get an error.

In general I suggest not modifying WPILib directly or adding to it because if they come out with a new release, you will need to go in and make your change again.

The easy way to approach this problem is to take your gamepad files (both cpp and h) and put them directly in your project directory (you may need to right click on your project name and refresh the file list if you add it through Windows). When you rebuild your project, it will build up the gamepad files since it knows to build all cpp files.

Give that a shot and let us know how it goes
Reply With Quote
  #15   Spotlight this post!  
Unread 02-11-2010, 10:17
ehlochbr ehlochbr is offline
Registered User
FRC #2990
 
Join Date: Nov 2010
Location: Salem, OR
Posts: 37
ehlochbr is an unknown quantity at this point
Re: define a new class(C++)

When you say to include the files in my project directory, I'm assuming you mean import the files. For example, now I have MyRobot.cpp, Gamepad.h, & Gamepad.cpp (along with other folders and stuff) underneath my main project in windriver.

If this isn't what you meant then can you please elaborate on how to include the files in my directory without saving them in the WPILib folder?

Also, I see your point about changing the WPILib folder and took the files out.

I really appreciate your help. I just started helping out this year and I'm trying to catch up.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
define irswitch? Lilor Programming 3 10-02-2008 19:21
Define Happiness Elgin Clock Chit-Chat 17 30-04-2007 21:59
Define A Wedge T3_1565 Rules/Strategy 18 11-01-2007 21:22
Define FIRST slickguy2007 General Forum 24 13-10-2006 08:24
**FIRST EMAIL**/FIRST Announces New Class of Senior Mentors. Billfred FIRST E-Mail Blast Archive 1 23-12-2004 13:32


All times are GMT -5. The time now is 14:24.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi