I build a custome Battery minitor that sence two battery from input and give output of current and battery voltage over serial
Please suggest me how to Add this in battery Monitor
My data stream is
// 1747995445,50.15,0.54,50.39,1.23,0.00,1.82,42.86,43.15,43.68,43.89,0,1
// Log data structure
typedef struct PACKED batlog_t {
double date_time; // Date and time 24hr format
double voltage_drone; // Voltage of the drone
double voltage_main; // Voltage of the main
double voltage_batt; // Voltage of the battery
double current_drone; // Current of the drone
double current_main; // Current of the main
double current_batt; // Current of the battery
double temp_board[2]; // Temperature of the board front & back
double temp_ntc[2]; // Temperature of the NTC 1 & 2
char mains_status; // Mains status
char batt_status; // Batt status
} batlog_t;
Why reinvent the wheel ?
Use a monitor chip that is already supported (INA2XX, LTC2946, AD7091R5 or any SMBus compatible one…)
But if you must use the serial port, you can write a LUA script that reads from the serial port and update the battery state… there is an example in the lua drivers folder for a CAN battery monitor ardupilot/libraries/AP_Scripting/drivers/BattMon_ANX.lua at master · ArduPilot/ardupilot · GitHub
Some other approaches:
ideally your custom battery monitor would send DroneCAN messages over CAN instead of using Serial. This would make your solution compaible with Ardupilot and would be much more flexible (could react to relay messages.. etc).
What microcontroller do you have on board?
You could use a library we have made, which makes this super easy to do. GitHub - BeyondRobotix/Arduino-DroneCAN: DroneCAN support for Arduino on STM32!
Other ideas:
modify AP periph and include a serial driver for your protocol, then that would forward on CAN messages to Ardupilot
Write a driver in Ardupilot. You can figure it out from the Ardupilot Github if you look in the battery library