![]() |
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 |
Re: Reading battery voltage in software
Look in ifi_aliases.h, line 300
Code:
#define battery_voltage rxdata.rc_main_batt*15.64/256 |
Re: Reading battery voltage in software
Quote:
|
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!
|
Re: Reading battery voltage in software
thanks so much!
|
Re: Reading battery voltage in software
:yikes: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); |
Re: Reading battery voltage in software
Quote:
|
Re: Reading battery voltage in software
Quote:
|
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; |
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 |
Re: Reading battery voltage in software
Quote:
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. |
Re: Reading battery voltage in software
Quote:
|
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?
|
Re: Reading battery voltage in software
Quote:
Thank you very much! |
Re: Reading battery voltage in software
Quote:
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:
|
Re: Reading battery voltage in software
Quote:
|
Re: Reading battery voltage in software
Holy cow! I know it's possible (it sounds possible), but I never knew there was such a thing in the code. Thanks!
|
Re: Reading battery voltage in software
I have, in the past, used the main battery voltage to formulaicly modify the multiplier on the P term in the PID for the wheel motors (rate control). Worked great!
Also have used it to make power limits on non-servo systems vary to have the same power output (mechanical) regardless of lower battery voltage. I.e., 25% power limits that stay constant regardless of battery voltage. -q |
| All times are GMT -5. The time now is 17:35. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi