Page 1 of 1
[NXT-G] Battery Block question
Posted: 24 Apr 2011, 02:52
by pavementpilot
The battery block has a compare value setting and a numerical output. What does the compare < or > do? I have block of code that reads [Battery Level] (< 6000mV) into a
(600000 / [Battery Level]) with output to [Move] (CB forward with power value from
. In the
, the 600000 is 100% power times 6000mV.
So this being said, what I am doing is running the motors at 6V instead of what ever the batteries are giving out. Should I have the compare at < or > and what is the difference between the two?
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 03:58
by mattallen37
I do not seem to have that block... < and > are likely comparing the voltage to another value. It probably outputs a logic state that you can use to determine something. An example would be to feed the logic into a loop, so that it loops until the voltage drops below a certain level.
Also, the motor speed control uses PWM, not analog voltage. Even at 1%, you are still powering them with the same voltage as with 100%. PWM % just determines the duty cycle, not voltage.
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 07:39
by pavementpilot
Here is the program. Take a look at the way it supplies data. What I am trying to do is limit the motor to 6V. How do I set the Battery Level block. It is using a comparison but outputing a number. I have checked it using the display block with #totext.
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 08:34
by h-g-t
This how I used it :-
- RelayShutterd.zip
- Factoring motor power using Guy Ziv's battery block (.png file).
- (52.15 KiB) Downloaded 414 times
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 11:16
by h-g-t
As pointed out by matallen37, this method is not reducing the voltage but it does ensure that the motor is being supplied with a reasonably steady output.
If you just set a power level, the speed of the motor will drop off as the battery runs down. This method just starts off with reduced power and increases the required percentage to compensate for the reduction in voltage.
It would be far better, of course, to monitor the rotational speed and continually adjust the power level to try and keep the speed constant. This is just a simple way of getting some consistency where the robot will be required to do something repetitive and timing (not speed) is important. I thought of monitoring but was concerned that it might lead to 'hunting' as the power level was continually increased and decreased. It also takes a lot more programming.
If anyone has devised a way of doing it using PID or continual monitoring I would be very pleased to hear from them. Especially if they can supply some working NXC code or NXT-G blocks!
To answer (at last!) the original question, one could use the compare function to operate a switch block which would increment/ decrement the power percentage depending on whether the voltage was above or below the required level. This would achieve the same effect as the code example I supplied but would require a loop to keep changing the value until it was acceptable. It would have to be carefully designed to ensure the loop does not become infinite (especially if using NXT-G 2 with floating point arithmetic). If the power is being set as in the code example then there is no need to use the compare elements in the block.
Alternatively, the compare outputs could be used to operate a switch block in addition to the the code to issue a visual or audible warning when the battery level drops to an unacceptably low voltage (or is too low to begin with).
I used the battery level block in a short program which just displayed the battery voltage on the screen for 10 seconds or until it was switched off. Takes up little space but is handy because you can get an exact readout of the battery condition at any time.
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 15:37
by pavementpilot
Thanks for the explanation h-g-t.
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 17:20
by h-g-t
In the unlikely event that anyone is interested, here are my battery level display files. I keep a copy of the NXC version on my brick so I can check the battery level at any time.
- Batt_Level NXC.zip
- NXC file to display battery voltage. Works until stopped.
- (316 Bytes) Downloaded 435 times
- Battery Voltage.zip
- NXT-G block to display battery voltage. Press right arrow to terminate.
- (90.44 KiB) Downloaded 450 times
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 22:01
by bungeshea
pavementpilot wrote:The battery block has a compare value setting and a numerical output. What does the compare < or > do? I have block of code that reads [Battery Level] (< 6000mV) into a
(600000 / [Battery Level]) with output to [Move] (CB forward with power value from
. In the
, the 600000 is 100% power times 6000mV.
So this being said, what I am doing is running the motors at 6V instead of what ever the batteries are giving out. Should I have the compare at < or > and what is the difference between the two?
If you are just using the battery level output, then it will not make any difference what you set the trigger point or the > or < to be. That function is only to be used with the Yes/No plug. For example, if you write > 15000 that tells you if the battery level is less then 1500 mVolts. It does not affect the battery level output at all.
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 22:09
by mattallen37
studbrickmaster wrote:... if you write > 15000 that tells you if the battery level is less then 1500 mVolts...
Uh, not quite. If you were to write >15000, it would be true only if the battery level was
greater than
15,000 mV (15 volts, which can never happen). The H-Bridges are rated for a max voltage of about 10.5v, and IIRC, at ~12.5v, the atmega shuts down the NXT.
Re: [NXT-G] Battery Block question
Posted: 24 Apr 2011, 22:25
by bungeshea
mattallen37 wrote:studbrickmaster wrote:... if you write > 15000 that tells you if the battery level is less then 1500 mVolts...
Uh, not quite. If you were to write >15000, it would be true only if the battery level was
greater than
15,000 mV (15 volts, which can never happen). The H-Bridges are rated for a max voltage of about 10.5v, and IIRC, at ~12.5v, the atmega shuts down the NXT.
Yeah, well it was just an example