PlayUAV / PlayuavOSD

A Graphical OSD for FPV
http://en.playuav.com
GNU General Public License v3.0
67 stars 60 forks source link

Added current consumed from mavlink protocol #13

Closed SamuelBrucksch closed 8 years ago

SamuelBrucksch commented 8 years ago

I added the message that reads the consumed current so it can be displayed instead of the % value. This was requested here: http://fpv-community.de/showthread.php?66113-PlayUavOSD-Full-Graphics-OSD-auf-STM32-basis&p=849878&viewfull=1#post849878

Link to message definition: https://github.com/mavlink/mavlink/blob/master/message_definitions/v1.0/common.xml#L2767

In Config tool we need to set BattConsumed_InMah to 1 for mAh or 0 for %. This setting needs to be added to cofig tool.

Its untested as i do not have a APM/Pixhawk with me. Can you please test it? osd_battery_consumed_in_mah will be -1 if AP does not support current consumed reading.

Also i'm not sure with this part: sprintf(tmp_str, "%d/", osd_battery_remaining_A); -> sprintf(tmp_str, "%dmAh", osd_battery_consumed_in_mah);

There is no '%' char, do you add that somewhere else in the code? If yes that needs to be disabled in case of consumed mAh.

SamuelBrucksch commented 8 years ago

We might have to check for battery id if using multiple batteries.

SamuelBrucksch commented 8 years ago

Added parameter in config tool: https://github.com/PlayUAV/OSDTool/pull/1

ghost commented 8 years ago

I really want to add the item "current consumed in mah" to OSD. I think it is more useful than other battery information. However, ardupilot doesn't provide the item with MAVLink. I cannot find "MAVLINK_MSG_ID_BATTERY_STATUS" used in ardupilot master code(plane, copter and rover). To confirm, I have tested it on APM2 and px4-fmuv2 with firmware 3.2.1(quad) and there was no "current consumed in mah" information during flight (it kept zero).

The good news is that the ardupilot code has the "current consumed in mah" capacity. Please see the function "current_total_mah" in AP_BattMonitor library. I used it to show "current consumed in mah" at APM Plus project, see line 939 at "https://github.com/PlayUAV/ardupilot/blob/CopterOSD-3.2.1/ArduCopter/ArduCopter.pde".

Hope developers of ardupilot can add this useful information to mavlink.

BTW, it would be nice to add a new parameter at the end of the osdconfig.h file, so it won't break the existing parameters.

MPC561 commented 8 years ago

I´m wondering. It should be inside as it is used, and shown, in MinimOSD extra and there it works. At least with Extra OSD R726. In the Mavlink V1.0 libary in the mavlink_msg_sys_status.h you can find following line: static inline int16_t mavlink_msg_sys_status_get_current_battery(const mavlink_message_t* msg) { return _MAV_RETURN_int16_t(msg, 16); }

SamuelBrucksch commented 8 years ago

Thats the current you currently draw, this is about total consumed current.

           <field type="int16_t" name="current_battery">Battery current, in 10*milliamperes (1 = 10 milliampere), -1: autopilot does not measure the current</field>
MPC561 commented 8 years ago

Ok,

I followed the extra OSD code to this message. Seems that in extra OSD firmware they use the current to calculate the mAh consumed. In principle a simple Integral means that simply every calculation cycle the current is written into a buffer starting with arming and based on the calculation cycle it´s transfered with a formula into the mAh which can be displayed.

In extra OSD it seems following code is used: mah_used += (osd_curr_A * 10.0 * (millis() - dt) / 3600000.0);

Maybe this code with modifications can be overtaken into PlayUAVOSD.

Greets, Joerg

ghost commented 8 years ago

Hi Samuel, I have added current consumed as an independent item to give user more choice. And replaced the primary item "BattConsumed_XXX" to "BattRemaining_XXX", also added your code about "MAVLINK_MSG_ID_BATTERY_STATUS" message to osdmavlink.c for future using.