Go to Post One of the most important resources of all: [URL="http://frc-manual.usfirst.org/"]The Manual[/URL] - lorem3k [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 23-02-2012, 15:58
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Time/timer function

Hello,

I am trying to include a time/timer function so that in a while loop I can keep track of how long it has been and still being able to run other code.

Also I would like to use it so that when I press a joystick button, the button is disable for say 1 second (so that it only registers 1 press and not registering from consistent pressing).

Could demonstrate how this function works?

Thanks,
Davis
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #2   Spotlight this post!  
Unread 23-02-2012, 16:02
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,015
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Time/timer function

Quote:
Originally Posted by DavisC View Post
I would like to use it so that when I press a joystick button, the button is disable for say 1 second (so that it only registers 1 press and not registering from consistent pressing).

Could demonstrate how this function works?
The boolean expression

(button_is_pressed && button_was_not_pressed_in_previous_iteration)

does what you want.

It's true only in the iteration immediately after the button is pressed, and doesn't become true again until the button is released and pressed again.


Reply With Quote
  #3   Spotlight this post!  
Unread 23-02-2012, 17:11
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Time/timer function

Thanks, that helps a lot!

Although I am still interested in learning how to use the time/timer feature.

I'm not sure if there is a specific function that can be used as a timer, or if I have to get the time off the cRIO (if possible) and do my own math.

Thanks!
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #4   Spotlight this post!  
Unread 23-02-2012, 17:16
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Time/timer function

I use this macro.
Code:
#define GetMsecTime()           (GetFPGATime()/1000)
__________________
Reply With Quote
  #5   Spotlight this post!  
Unread 23-02-2012, 20:43
DavisC DavisC is offline
Registered User
FRC #0539 (Titans)
Team Role: College Student
 
Join Date: Jul 2011
Rookie Year: 2010
Location: Virginia
Posts: 200
DavisC is just really niceDavisC is just really niceDavisC is just really niceDavisC is just really nice
Re: Time/timer function

So i just add the #define up with the includes and use the function wherever I need to and do the math from there.

Thanks.
__________________
FRC Team 539
Student Member: 2010 Breakaway - 2014 Aerial Assist
Mentor: 2015 Recycle Rush - present
Reply With Quote
  #6   Spotlight this post!  
Unread 23-02-2012, 20:54
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Time/timer function

Quote:
Originally Posted by DavisC View Post
So i just add the #define up with the includes and use the function wherever I need to and do the math from there.

Thanks.
That's right. Typically, it looks like this:
Code:
UINT32 startTime = GetMsecTime();
//
// Do something that you want to time.
//
printf("Elapsed time = %d msec\n", GetMsecTime() - startTime);
__________________
Reply With Quote
  #7   Spotlight this post!  
Unread 24-02-2012, 00:01
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: Time/timer function

There is also a Timer class, but I don't like it much. Remember to call the Start() method if you use it.
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 02:32.

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