Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 8 of 8
  1. #1
    Senior Pilot
    Join Date
    Nov 2010
    Location
    Atlanta, GA
    Posts
    1,798
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    0

    Battery Monitor code

    Ok, it's late and I"m going to bed, but this just doesn't look right... It's the warning level in the current code...this code below comes from batterymonitor.h. The autoDescent value get's added to the throttle over in the flightcontrol.h code.

    But unless I'm just missing it...

    The logic is...
    if autoDescent == 0 as it is the first time, then set it to -50, then if it's not zero and it meets the current time check, set it to 50!!! wouldn't that add 50 to throttle for each time it triggers during the warning section? What am I missing?

    Then to make things even more strange, it zero's out the autoDescent when the time is greater than 1200...

    maybe I need an explanation on how these darn timing loops work? It would seem the first check is if more than 1000 milliseconds have passed since the last check, then if more that 1100 milliseconds have passed set autoDescent to 50, turn on the LED and turn on the buzzer. I get that, it blinks the led and beeps the buzzer, but what a positive 50 to autoDescent during this beeping? I would figure it should be -50.

    Like I said, it's late and I'm tired...

    Code:
      void lowBatteryEvent(byte level) {
        long currentTime = millis()- previousTime;
        if (level == OK) {
          digitalWrite(BUZZERPIN, LOW);
          autoDescent = 0;
          //holdAltitude = 0;
        }
        if (level == WARNING) {
          if ((autoDescent == 0) && (currentTime > 1000)) {
            autoDescent = -50;
          }
          if (currentTime > 1100) {
            autoDescent = 50;
            digitalWrite(LED2PIN, HIGH);
            digitalWrite(BUZZERPIN, HIGH);
          }
          if (currentTime > 1200) {
            previousTime = millis();
            autoDescent = 0;
            digitalWrite(LED2PIN, LOW);
            digitalWrite(BUZZERPIN, LOW);
          }
        }
    Alan
    Last edited by aadamson; 02-06-2011 at 02:27 PM.

  2. #2
    Senior Pilot
    Join Date
    Jan 2011
    Location
    Suffolk County NY , USA
    Posts
    647
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    0
    Quote Originally Posted by aadamson View Post

    But unless I'm just missing it...

    wouldn't that add 50 to throttle for each time it triggers during the warning section? What am I missing?

    Like I said, it's late and I'm tired...

    Alan
    = is an assignment operator .. in order to "add 50" it would have to be like .. a = a + 50 ..

    "a = 50" just sets a to 50 .. no math involved.

  3. #3
    Senior Pilot
    Join Date
    Nov 2010
    Location
    Atlanta, GA
    Posts
    1,798
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    0
    Quote Originally Posted by kevo View Post
    = is an assignment operator .. in order to "add 50" it would have to be like .. a = a + 50 ..

    "a = 50" just sets a to 50 .. no math involved.
    Oh, I'm quite aware of that, the *math* is over in flightcontrol.h where autoDescent gets added to the throttle (added in that if it's set to -50, it would get subtracted, if it's set to 50 it get's added)

    specifically this code
    Code:
     throttle = receiver.getData(THROTTLE) + autoDescent;

  4. #4
    Moderator AeroQuad Technologist Honk's Avatar
    Join Date
    Apr 2010
    Location
    Stockholm
    Posts
    5,442
    Blog Entries
    2
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    1
    Mikro did that for the V2 hardware to get the quad to frequently (and quite gently according to him) wiggle up and down a bit while in WARNING level, then continuous descent while at ALARM level. He said it worked. Maybe some new bug came on to it? But serial-print debug it to be sure.

    Personally I think we should use only one "lowBatteryEvent" for every hardware setup.
    Smart people don't need a signature.
    http://thechive.files.wordpress.com/...rd-signs-3.jpg

  5. #5
    Senior Pilot
    Join Date
    Nov 2010
    Location
    Atlanta, GA
    Posts
    1,798
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    0
    Quote Originally Posted by Honk View Post
    Mikro did that for the V2 hardware to get the quad to frequently (and quite gently according to him) wiggle up and down a bit while in WARNING level, then continuous descent while at ALARM level. He said it worked. Maybe some new bug came on to it? But serial-print debug it to be sure.

    Personally I think we should use only one "lowBatteryEvent" for every hardware setup.
    Ya me too ... I just got the new changes to the git loaded up and am working thru this and one other thing, then hopefully off to test some software and hardware changes and get my little one flying a bit better...

  6. #6
    Senior Pilot
    Join Date
    Nov 2010
    Location
    Atlanta, GA
    Posts
    1,798
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    0
    Ya, this is broken big time... what it does as is...

    a) when in warning, it subtracts 50 from throttle then adds it back and it does that once a second - wow, would that be annoying or what, and not very predictive for what is going on.

    b) and ALARM is even worse, it won't do anything, it just sets autoDescent to -1 so it just subtracts 1 from the current throttle only. When Altitude hold mode is enabled and on, it probably has more dramatic effects as it subtracts .2meters from the hold altitude

    But neither case if very functional at the moment.... working on a fix now...need to go see how the functionality was *intended* to work.

  7. #7
    Senior Pilot
    Join Date
    Nov 2010
    Location
    Atlanta, GA
    Posts
    1,798
    Downloads
    0
    Uploads
    0
    Reputation Points (Add)
    0
    Quote Originally Posted by aadamson View Post
    Ya, this is broken big time... what it does as is...

    a) when in warning, it subtracts 50 from throttle then adds it back and it does that once a second - wow, would that be annoying or what, and not very predictive for what is going on.

    b) and ALARM is even worse, it won't do anything, it just sets autoDescent to -1 so it just subtracts 1 from the current throttle only. When Altitude hold mode is enabled and on, it probably has more dramatic effects as it subtracts .2meters from the hold altitude

    But neither case if very functional at the moment.... working on a fix now...need to go see how the functionality was *intended* to work.
    I guess for now, I'm going to leave the warning functionality, what it does is blip the throttle a -50 to +50 offset, 100 throttle values, once per second.

    The problem with the ALARM code is specific to the 1.8 shield platform, because it shares BUZZERPIN with LED2PIN, autoDescent gets set back to 0 (zero) each second, as the blink logic occurs for the to blink the LEDs in ALARM mode... - this means this ALARM function *WILL NOT* work correctly on a 1.8 with the code as is...

    One option would be to comment out this line in batterymonitor.h

    Code:
          if (digitalRead(BUZZERPIN) == LOW) autoDescent = 0; // intialize autoDescent to zero if first time in ALARM state
    The other would be to come up with some LED/BUZZER blink logic that didn't require setting autoDescent to zero.

  8. #8
    Administrator AeroQuad Founder Mikro's Avatar
    Join Date
    Jun 2009
    Posts
    3,238
    Downloads
    4
    Uploads
    7
    Reputation Points (Add)
    9
    Alan, the increase/decrease in throttle is intentional. When the batt monitor is in WARNING mode it causes the quad to fly with a "heartbeat". It's a visual indicator to let you know batteries are running low. I definitely understand there may be a preference with some of you to just go with LED indicators, but from a practical standpoint, if you are at the park during daylight flying all over the place, it is REALLY hard to see if the LED's are blinking or not. I copied this behavior from the X-3D BL guys (I think they are now known as Asctec).

    I was realizing this the other night, that I didn't see the heartbeat function with the v1.8 shield. I realized that the buzzer pin didn't apply to the v1.8 shield, so instead of adding another #ifdef, thought I could cheat by just setting all the LED functions to pin 12. That is definitely a bug... I'll just add the #ifdef for now and we can make everything correct with a future v3.0 release.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •