Gathiyo / arducopter

Automatically exported from code.google.com/p/arducopter
0 stars 0 forks source link

Battery remaining scaling incorrect for MAVLINK 1.0 #430

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Arducoper 2.6
What steps will reproduce the problem?
1. View "battery remaining percentage" value on missionplanner

What is the expected output? What do you see instead?
Data is incorrect

What version of the product are you using? On what operating system?
AC 2.6

Please provide any additional information below.
The base of the problem is the scaling of battery_remaining in GCSMAVLINK.PDE. 
MAVLINK 1.0 transfers this data in an int8, not a uint16 like it was in 0.9.  
The calculation for battery_remaining has a multiply by 1000, so overflows the 
int8 and provides incorrect results. Need to multiply by 100 instead.   

However, it also appears that the mission planner (1.1.92, Mav 1.0)has the 
proper scaling, because for small values of battery_remaining (that don't 
overflow the int8) the value comes through as a factor of 10 too low.

Original issue reported on code.google.com by AndrewJF...@gmail.com on 17 Jun 2012 at 1:00

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
While someone is in the gcs_mavlink.pde code, it would also be worthwhile 
adding the code to transfer motor current via mavlink. The Arduplane 
gcs_mavlink.pde code already has this, so could just copy over the code. 

Original comment by AndrewJF...@gmail.com on 23 Jun 2012 at 1:38

GoogleCodeExporter commented 8 years ago
Confirmed the fix. Arducopter and ArdupilotMissionPlanner work fine with the 
changes below.  I also checked the Arduplane code and gcs_mavlink looks O.K. 
(already multiplying by 100), but haven't tested it.

Andrew

Arducopter - gcs_mavlink.pde
Was:
      uint16_t battery_remaining = 1000.0 * (float)(g.pack_capacity - current_total1)/(float)g.pack_capacity; //Mavlink scaling 100% = 1000
New:
      uint16_t battery_remaining = 100.0 * (float)(g.pack_capacity - current_total1)/(float)g.pack_capacity; //Mavlink scaling 100% = 100

ArdupilotmegaPlanner - CurrentState.cs
Was:
       _battery_remaining = value / 1000;

New:
       _battery_remaining = value / 100

Original comment by AndrewJF...@gmail.com on 23 Jun 2012 at 1:39

GoogleCodeExporter commented 8 years ago
To implement the changes in arducopter gcs_mavlink.pde to work the same was as 
in arduplane the new code is as shown below. Tested in 2.6 and it works fine. 
The "load" parameter is not calculated in arducopter, so just left it at zero.:

  uint16_t battery_current = -1;
    uint8_t  battery_remaining = -1;

    if (current_total1 != 0 && g.pack_capacity != 0) {
        battery_remaining = (100.0 * (g.pack_capacity - current_total1) / g.pack_capacity);
    }
    if (current_total1 != 0) {
        battery_current = current_amps1 * 100;
    }

    if (g.battery_monitoring == 3) {
        /*setting a out-of-range value.
        It informs to external devices that
        it cannot be calculated properly just by voltage*/
        battery_remaining = 150;
    }

    mavlink_msg_sys_status_send(
        chan,
        control_sensors_present,
        control_sensors_enabled,
        control_sensors_health,
        0,                      // Load not yet calculated in Arducopter
        battery_voltage1 * 1000, // mV
        battery_current,        // in 10mA units
        battery_remaining,      // in %
        0, // comm drops %,
        0, // comm drops in pkts,
        0, 0, 0, 0);

Original comment by AndrewJF...@gmail.com on 23 Jun 2012 at 2:09

GoogleCodeExporter commented 8 years ago
A fix has just been added to the code base by Andreas. 

Original comment by AndrewJF...@gmail.com on 25 Jun 2012 at 1:11

GoogleCodeExporter commented 8 years ago

Original comment by jasonshort on 26 Jun 2012 at 5:51