Go to Post No really though, a robot game with rules similar to Risk. This would combine FIRST, Battlebots, and US Government... - Betty_Krocker [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2006, 18:34
RbtGal1351's Avatar
RbtGal1351 RbtGal1351 is offline
~La Reina de los Robots~
AKA: Stephanie
FRC #1351 (TKO)
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: San Jose, CA
Posts: 166
RbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to behold
Send a message via AIM to RbtGal1351 Send a message via MSN to RbtGal1351
Reading battery voltage in software

Hi,

Is it possible for the software to read the battery voltage? (The main battery)
I know that the battery voltage is known, because you can read it on the OI. But can I access it in code, and how?

I tried searching ifirobotics and here but couldn't find anything, just references to the OI.

Thanks,
~Stephanie
__________________
2004 Founding member and Arm leader, 2005 Lead programmer, 2006 Controls leader, 2007 Project Manager/President
Thanks for making FIRST such a great experience for me. I'm no longer on 1351, and I'm not currently planning to mentor team 97, but FIRST has meant so much in getting me to where I am now, in life and at MIT, class of 2011.
I met Billfred! He recognized me!
SVR 04: 11th seed - Highest Rookie Seed - Semifinalists w/ 1120 and 568 - GM Industrial Design Award
SVR 05: Semifinalists w/ 8 and 766
SVR 06: 6th seed - Quarterfinalists w/ 368 and 1072
Davis 06: 1st seed - Quarterfinalists w/ 649 and 100 - KPCB Entrepreneurship Award
SVR 07: 36th seed
David 07: 4th seed - Semifinalists w/ 1280 and 692 - Johnson and Johnson Sportsmanship Award
  #2   Spotlight this post!  
Unread 12-02-2006, 18:37
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,810
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Reading battery voltage in software

Look in ifi_aliases.h, line 300

Code:
#define battery_voltage	 rxdata.rc_main_batt*15.64/256
#define backup_voltage	 rxdata.rc_backup_batt*15.64/256
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #3   Spotlight this post!  
Unread 12-02-2006, 19:41
lkdjm's Avatar
lkdjm lkdjm is offline
Registered User
AKA: David Mazza
FRC #0564 (Digital Impact)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Middle Island, NY
Posts: 31
lkdjm will become famous soon enough
Send a message via AIM to lkdjm Send a message via Yahoo to lkdjm
Re: Reading battery voltage in software

Quote:
Originally Posted by Mark McLeod
Look in ifi_aliases.h, line 300

Code:
#define battery_voltage	 rxdata.rc_main_batt*15.64/256
#define backup_voltage	 rxdata.rc_backup_batt*15.64/256
cool, thanks
__________________
Longwood's Digital Impact

  #4   Spotlight this post!  
Unread 13-02-2006, 10:19
the_short1's Avatar
the_short1 the_short1 is offline
Head of Electronics
AKA: Kevin F.
FRC #1596 (Twin Saults International Instigators)
Team Role: Electrical
 
Join Date: Feb 2005
Rookie Year: 2005
Location: CANADA
Posts: 252
the_short1 is a name known to allthe_short1 is a name known to allthe_short1 is a name known to allthe_short1 is a name known to allthe_short1 is a name known to allthe_short1 is a name known to all
Send a message via MSN to the_short1
Re: Reading battery voltage in software

thanks! that will be handy, if battery is too slow then maybe limit max speed of motor / turn off conveyor automatically to favour drivign!
__________________
2005 GLR: 12th/58 Seed, Aliance: 1596, 910, 1447 (Semi Finalists) Website, Rookie All Star, Highest Rookie Seed, and 2 Peer Awards, my BIG thank you thread, PLEASE READ
2005 GTR: 11th/66 Seed, Aliance: 703, 1596, 1680 (Semi Finalists) Highest Rookie Seed & 1 Peer Awards
2005 Championship (Galileo): 36th/86 Seed Highest Galileo Match Score: 123:7 Thanks 447 and 121
2006 Website (Totally Revamped):Instigators1596.com
2006 GLR: 31st/61 Seed, Aliance: 835, 1213, 1596 (Quarter Finalists) Spirit & 3 peer awards, THX!
2006 Waterloo: 7th/31 Seed, Aliance: 1219, 1596, 912 (Semi Finalists) Spirit & 2 peer awards, THX!
2006 Waterloo: Aliance: 1596, 1680, 1114 Higest Match Score: (Q22) 128|32
  #5   Spotlight this post!  
Unread 16-02-2006, 03:01
RbtGal1351's Avatar
RbtGal1351 RbtGal1351 is offline
~La Reina de los Robots~
AKA: Stephanie
FRC #1351 (TKO)
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: San Jose, CA
Posts: 166
RbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to beholdRbtGal1351 is a splendid one to behold
Send a message via AIM to RbtGal1351 Send a message via MSN to RbtGal1351
Re: Reading battery voltage in software

thanks so much!
__________________
2004 Founding member and Arm leader, 2005 Lead programmer, 2006 Controls leader, 2007 Project Manager/President
Thanks for making FIRST such a great experience for me. I'm no longer on 1351, and I'm not currently planning to mentor team 97, but FIRST has meant so much in getting me to where I am now, in life and at MIT, class of 2011.
I met Billfred! He recognized me!
SVR 04: 11th seed - Highest Rookie Seed - Semifinalists w/ 1120 and 568 - GM Industrial Design Award
SVR 05: Semifinalists w/ 8 and 766
SVR 06: 6th seed - Quarterfinalists w/ 368 and 1072
Davis 06: 1st seed - Quarterfinalists w/ 649 and 100 - KPCB Entrepreneurship Award
SVR 07: 36th seed
David 07: 4th seed - Semifinalists w/ 1280 and 692 - Johnson and Johnson Sportsmanship Award
  #6   Spotlight this post!  
Unread 28-01-2007, 23:14
htwiz2002's Avatar
htwiz2002 htwiz2002 is offline
Htwizard
AKA: Anthony Takata Bawahawba
#1290
Team Role: Engineer
 
Join Date: Jan 2004
Location: Chandler, AZ
Posts: 23
htwiz2002 will become famous soon enough
Question Re: Reading battery voltage in software

Wait! What type of variable is it?!?! When I try to read it it outputs a number greater than 16k!
I'm building a terminal interface (for debugging) it outputs a really strange value when I do:
Code:
printf("%d",battery_voltage);
Can anyone help?
__________________
TsAuKpAeTrA (Anthony)
  #7   Spotlight this post!  
Unread 28-01-2007, 23:38
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Reading battery voltage in software

Quote:
Originally Posted by htwiz2002 View Post
Wait! What type of variable is it?!?! When I try to read it it outputs a number greater than 16k!
I'm building a terminal interface (for debugging) it outputs a really strange value when I do:
Code:
printf("%d",battery_voltage);
Can anyone help?
It's a float.
  #8   Spotlight this post!  
Unread 28-01-2007, 23:47
htwiz2002's Avatar
htwiz2002 htwiz2002 is offline
Htwizard
AKA: Anthony Takata Bawahawba
#1290
Team Role: Engineer
 
Join Date: Jan 2004
Location: Chandler, AZ
Posts: 23
htwiz2002 will become famous soon enough
Wink Re: Reading battery voltage in software

Quote:
Originally Posted by Abwehr View Post
It's a float.
So the printf replacement is "%f" ? (just because I'd rather set it now rather than try to remember it when I work on the code tomorrow...
__________________
TsAuKpAeTrA (Anthony)
  #9   Spotlight this post!  
Unread 28-01-2007, 23:59
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: Reading battery voltage in software

If I recall correctly the printf functions in our code don't support the %f sequence. If the decimal place does not matter to you, just cast the variable as an int when printing it out (i.e. (int)variable). If you do want the decimal places, do something like:

Code:
variabledeci = variable - (int)variable; 

variabledeci*=1000; 

printf("variable = %d.%03d", (int)variable, (int)variabledeci);
This stores the decimal portion of the variable in another one, then multiplies by 1000 to get the decimals in front of the decimal point, and then prints the whole thing out.
__________________
  #10   Spotlight this post!  
Unread 29-01-2007, 00:49
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: Reading battery voltage in software

Wrote this over the summer when playing around with the edu rc. It prints out a float
Code:
current_voltage = rxdata.rc_main_batt; 		// Store current voltage
	average_voltage += current_voltage;		// Add the current voltage to the average stack

	voltage_count++;							// Increase the average stack count
	
	if (voltage_count == 39)					      // If the stack is 40
	{
		average_voltage = (average_voltage / 40) * 0.038 + 0.05;	// Get the average and apply formula
		i = (int)average_voltage;							// Truncate decimals
		i2 = (int) ((average_voltage - i) * 1000);				// Subtract to get decimals only and then multiply by 1000
		printf("Average: %d.%d \n",i,i2);						// Print the two together to make it look like a decimal

		average_voltage = 0;									// Reset the stack
		voltage_count = 0;									// Rest the counter
	}

Last edited by bear24rw : 29-01-2007 at 00:51.
  #11   Spotlight this post!  
Unread 29-01-2007, 08:10
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: Reading battery voltage in software

Quote:
Originally Posted by bear24rw View Post
Wrote this over the summer when playing around with the edu rc. It prints out a float
Code:
current_voltage = rxdata.rc_main_batt;         // Store current voltage
    average_voltage += current_voltage;        // Add the current voltage to the average stack

    voltage_count++;                            // Increase the average stack count
    
    if (voltage_count == 39)                          // If the stack is 40
    {
        average_voltage = (average_voltage / 40) * 0.038 + 0.05;    // Get the average and apply formula
        i = (int)average_voltage;                            // Truncate decimals
        i2 = (int) ((average_voltage - i) * 1000);                // Subtract to get decimals only and then multiply by 1000
        printf("Average: %d.%d \n",i,i2);                        // Print the two together to make it look like a decimal

        average_voltage = 0;                                    // Reset the stack
        voltage_count = 0;                                    // Rest the counter
    }

The only problem that I see with that is, if your voltage is let's say 8.004, I believe that the way you are printing the variables would print 8.4.

If I recall correctly %03d forces three digits to be printed, which using the above example, would display 8.004.
__________________
  #12   Spotlight this post!  
Unread 29-01-2007, 16:27
bear24rw's Avatar
bear24rw bear24rw is offline
Team 11 Programming Captain
AKA: Max T
FRC #0011 (MORT)
Team Role: Programmer
 
Join Date: Sep 2005
Rookie Year: 2005
Location: Flanders, NJ
Posts: 385
bear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to beholdbear24rw is a splendid one to behold
Send a message via AIM to bear24rw
Re: Reading battery voltage in software

Quote:
Originally Posted by dhoizner View Post
The only problem that I see with that is, if your voltage is let's say 8.004, I believe that the way you are printing the variables would print 8.4.

If I recall correctly %03d forces three digits to be printed, which using the above example, would display 8.004.
lol true, i had 03 in there but i thought it was a mistake so i took it out before i posted. Nice catch
  #13   Spotlight this post!  
Unread 29-01-2007, 16:40
Joel J's Avatar
Joel J Joel J is offline
do you..
no team
 
Join Date: May 2001
Rookie Year: 2000
Location: San Jose, CA
Posts: 1,445
Joel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond reputeJoel J has a reputation beyond repute
Re: Reading battery voltage in software

I have an itchy finger that wants to change that alias to remove the float. Is this kosher? Would bad things happen?
__________________
Joel Johnson

Division By Zero (229) Alumni, 2003-2007
RAGE (173) Alumni, 1999-2003
  #14   Spotlight this post!  
Unread 29-01-2007, 17:27
htwiz2002's Avatar
htwiz2002 htwiz2002 is offline
Htwizard
AKA: Anthony Takata Bawahawba
#1290
Team Role: Engineer
 
Join Date: Jan 2004
Location: Chandler, AZ
Posts: 23
htwiz2002 will become famous soon enough
Re: Reading battery voltage in software

Quote:
Originally Posted by dhoizner View Post
The only problem that I see with that is, if your voltage is let's say 8.004, I believe that the way you are printing the variables would print 8.4.

If I recall correctly %03d forces three digits to be printed, which using the above example, would display 8.004.
Alright! I'll try it and see what happens.
Thank you very much!
__________________
TsAuKpAeTrA (Anthony)
  #15   Spotlight this post!  
Unread 29-01-2007, 22:27
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Re: Reading battery voltage in software

Quote:
Originally Posted by Joel J. View Post
I have an itchy finger that wants to change that alias to remove the float. Is this kosher? Would bad things happen?
I don't see why they would, unless any code depends on it (which you would find out about very quickly )

If you want to be safe, you can just take advantage of the global nature of the rxdata struct to get at the raw data:

Code:
if( rxdata.rc_main_batt < 127 )
    printf("HAMMER TIME!\n");

typedef struct  {     /* begin rx_data_record structure */


  ...
  unsigned char rc_main_batt, rc_backup_batt;
  ...

} rx_data_record;
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.
Closed Thread


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
battery voltage compensation Rickertsen2 Programming 5 17-10-2005 22:12
RC Circuits Melissa Nute Math and Science 3 25-01-2004 05:02
Battery Chargers Neal Probert Electrical 46 16-02-2003 22:31


All times are GMT -5. The time now is 02:42.

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