[NXT-G] Battery Block question

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
pavementpilot
Posts: 30
Joined: 07 Apr 2011, 16:42
Location: Vernon BC Canada
Contact:

[NXT-G] Battery Block question

Post 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 Formula (600000 / [Battery Level]) with output to [Move] (CB forward with power value from Formula. In the Formula, 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?
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: [NXT-G] Battery Block question

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
pavementpilot
Posts: 30
Joined: 07 Apr 2011, 16:42
Location: Vernon BC Canada
Contact:

Re: [NXT-G] Battery Block question

Post 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.
Attachments
MoCoCrawler.zip
(405.63 KiB) Downloaded 323 times
The definition of insanity is doing a repeated task over and over again, but expecting a different outcome everytime
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: [NXT-G] Battery Block question

Post 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 413 times
Battery Level 1-1.zip
Guy Ziv's battery level block.
(113.62 KiB) Downloaded 400 times
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: [NXT-G] Battery Block question

Post 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.
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
pavementpilot
Posts: 30
Joined: 07 Apr 2011, 16:42
Location: Vernon BC Canada
Contact:

Re: [NXT-G] Battery Block question

Post by pavementpilot »

Thanks for the explanation h-g-t.
The definition of insanity is doing a repeated task over and over again, but expecting a different outcome everytime
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: [NXT-G] Battery Block question

Post 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
A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
bungeshea
Posts: 207
Joined: 14 Aug 2011, 08:45
Location: Australia
Contact:

Re: [NXT-G] Battery Block question

Post 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 Formula (600000 / [Battery Level]) with output to [Move] (CB forward with power value from Formula. In the Formula, 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.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: [NXT-G] Battery Block question

Post 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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
bungeshea
Posts: 207
Joined: 14 Aug 2011, 08:45
Location: Australia
Contact:

Re: [NXT-G] Battery Block question

Post 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 :roll:
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 7 guests