Go to Post Sounds like a silly idea... so of course I'm in. - George1902 [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 10-02-2017, 20:51
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Post Help! Timer Function in WPIlib.h

I found this inside of the WPI libary
PHP Code:
[url="http://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1Timer.html#a5f16e8da27d2a5a5242dead46de05d97"]http://first.wpi.edu/FRC/roborio/release/docs/cpp/classfrc_1_1Timer.html#a5f16e8da27d2a5a5242dead46de05d97[/url] 
I put the line
Code:
Timer::Timer();
into the code.
Timer::Timer() means
PHP Code:
Create a new timer object.

Create a new timer object and reset the time to zeroThe timer is initially not running and must be started
When I built the code in eclipse, it came back with this error >
Code:
error: cannot declare member function 'frc::Timer::Timer' within 'Robot'
  Timer::Timer();
               ^
I don't know why its doing this. If you know please tell.

Thx.
Reply With Quote
  #2   Spotlight this post!  
Unread 10-02-2017, 21:56
AustinShalit's Avatar
AustinShalit AustinShalit is offline
Registered User
AKA: אוסטין
no team (WPILib Suite Developer)
 
Join Date: Dec 2013
Rookie Year: 2008
Location: Los Angeles/Worcester/Israel
Posts: 154
AustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of light
Re: Help! Timer Function in WPIlib.h

Try using this instead: frc::Timer()
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 10-02-2017, 22:22
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Help! Timer Function in WPIlib.h

Quote:
Originally Posted by AustinShalit View Post
Try using this instead: frc::Timer()
Error
PHP Code:
expected unqualified-id before ')' token 
Reply With Quote
  #4   Spotlight this post!  
Unread 10-02-2017, 23:00
AustinShalit's Avatar
AustinShalit AustinShalit is offline
Registered User
AKA: אוסטין
no team (WPILib Suite Developer)
 
Join Date: Dec 2013
Rookie Year: 2008
Location: Los Angeles/Worcester/Israel
Posts: 154
AustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of lightAustinShalit is a glorious beacon of light
Re: Help! Timer Function in WPIlib.h

Timer is not a function. It is an object. This should work:
Code:
#include <IterativeRobot.h>
#include <Timer.h>

class Robot: public frc::IterativeRobot {
public:
	void RobotInit() {
		timer = new frc::Timer();
	}

private:
	frc::Timer* timer;
};

START_ROBOT_CLASS(Robot)
And a more complete example:
https://github.com/wpilibsuite/Eclip.../src/Robot.cpp
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 10-02-2017, 23:16
charlier999's Avatar
charlier999 charlier999 is offline
Registered User
FRC #1662 (Raptor Force Engineering)
Team Role: Programmer
 
Join Date: Feb 2017
Rookie Year: 2013
Location: Lodi, CA
Posts: 19
charlier999 is an unknown quantity at this point
Re: Help! Timer Function in WPIlib.h

PHP Code:
double Timer::Get()const 
also a object that needs to be declared? If so how?
Thx.
Reply With Quote
  #6   Spotlight this post!  
Unread Yesterday, 18:30
Pay Me $2's Avatar
Pay Me $2 Pay Me $2 is offline
Registered User
AKA: La-Ya
FRC #4159 (CardinalBotics)
Team Role: Programmer
 
Join Date: Jan 2017
Rookie Year: 2017
Location: San Francisco, CA
Posts: 4
Pay Me $2 is an unknown quantity at this point
Re: Help! Timer Function in WPIlib.h

If you have a timer defined, you can Get() what its time is. For example,

Code:
timer = new frc::Timer();

timer.Reset();
timer.Start();


double time = timer.Get();
Reply With Quote
  #7   Spotlight this post!  
Unread Today, 00:17
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is online now
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 162
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Help! Timer Function in WPIlib.h

Almost ... in C/C++, the use of pointers to objects versus actual objects themselves makes a confusing difference of the use of '.' (objects) or the use of '->' (pointer to an object). So, with all that said, what's the rule? Here's an example of using a pointer as was intended above...
Code:
frc::Timer *pTimer; // Note the use of 'p' notation just to let the reader know this is a pointer...

pTimer = new frc::Timer;
// Now let's use the timer (it's a pointer so we use '->' and not '.'
pTimer->Reset();
pTimer->Start();

double timenow = pTimer->Get();
// Then eventually in your destructor you'd delete the pointer to "clean up"
delete pTimer;
The same piece of code but done with an object and NOT a pointer to an object would be...
Code:
frc::Timer MyTimer; // Note no 'p' preceeding - it's a real object - not a pointer. So there's no need to 'new' it either...

// Now let's use the timer (it's an object so we use '.')
MyTimer.Reset();
MyTimer.Start();

double timenow = MyTimer.Get();
// No need to delete. It'll go away when it goes out of scope.
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
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


All times are GMT -5. The time now is 00:41.

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