CubePilot CubeOrange+ I2C2 with Lua and Arduino Problems

thanks jai for the information. what if i need to get a warning in the rc as “warning:return to home is not possible”. this is based on the battery voltage which drains non linearly. where the battery full voltage is 50.2v, first level voltage is 43.5, and the critical voltage 42.7v . this is mainly due to protect the drone from crashing. what should i do for this

RC? traditional RC or smart RC (comes with telemetry function)?

Siyi UniRC 7 pro, I can send text (gcs:send_text(6, …)) from the LUA script, and the RC receives it on the RC App.

Are you looking for this?

-- Returns true if any of the batteries being monitored have triggered a failsafe.
---@return boolean -- true if any battery has failsafed
function battery:has_failsafed() end

I’m working on a drone safety feature that monitors real-time battery voltage and calculates whether the drone can safely return to its home location. I’m using Mission Planner and a Skydroid T12 transmitter. The system estimates the returnable distance based on live battery data and GPS position, and it gives a warning if the drone flies too far to make it back safely. I’m currently testing it in simulation,i got on the simulation. will move to real-flight tests soon to ensure accurate behavior under nonlinear battery discharge conditions. Just i need i warning message in the skydroid t12 transmitter “warning:return to home not possible”. lets say my drone travells 7km from 50.2v to 42.7v. at the3.5km it should trigger a warning in rc.

Does T12 come with a built-in display? I do not think so. H16/12 maybe.

I think you need to monitor more, maybe mah as well.

-- Returns the full pack capacity (in milliamp hours) from the battery.
---@param instance integer -- battery instance
---@return integer -- capacity in milliamp hours
function battery:pack_capacity_mah(instance) end
-- Returns the remaining percentage of battery (from 0 to 100), or nil if energy monitoring is not available.
---@param instance integer -- battery instance
---@return integer|nil -- remaining capacity as a percentage of total capacity if available
function battery:capacity_remaining_pct(instance) end
-- Returns the used watt hours from the battery, or nil if energy monitoring is not available.
---@param instance integer -- battery instance
---@return number|nil -- consumed energy in watt hours if available
function battery:consumed_wh(instance) end
-- Returns the capacity (in milliamp hours) used from the battery, or nil if current monitoring is not available.
---@param instance integer -- battery instance
---@return number|nil -- consumed capacity in milliamp hours
function battery:consumed_mah(instance) end
-- Returns the current (in Amps) that is currently being consumed by the battery, or nil if current monitoring is not available.
---@param instance integer -- battery instance
---@return number|nil -- current in amps if available
function battery:current_amps(instance) end

ok jai i will go through the transmitter buitin messages. the above functions which you have sent i will add for the voltage,current and battery remaining%. what is the function for the distance to home. and i have simulated using the python script. i have attached


the output image.
instead of beyond this,you cant return home i will make it as “warning:return home is not possible”

@Jai.GAY @Yuri_Rage hiii, do you guys know how do i communicate hobbywing datalinkv2 and cube orange plus

I believe Datalink v2 is proprietary software with hardware for Hobbywing Motors.

DATALINK V2 is a communication device which integrates data collection, data storage and data transmission. It can
monitor the running status of power system in real time together with aircraft control equipment and record flight status.
DATALINK can analyze user’s fault data and monitor the operation status of aircraft, which greatly enhances safety and
reliability of flight.
FC can connect TX1 RX2/TX2 RX2 port to output DATALINK total integrated serial data to FC.

Are you looking for this?

thankyou it helped me.

hiii
@Yuri_Rage @Jai.GAY
i need to get data of my esc in the mission planner status tab. what i did is upload the script https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Scripting/drivers/Hobbywing_DataLink.lua

and connection according to https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Scripting/drivers/Hobbywing_DataLink.md

i powered up datalink v2 from the bec. parameters are changed according to the documentation.
but no luck i dint get any output .
i dont no what did i do wrong. i think the parameter esc_hw_poles=24 i did(according to the magnetic coil in the motor i counted it).
datalink v2 module was blinking slow green. according to the datasheet of datalink v2
can you help me through this

Start a new topic. This has nothing to do with I2C. I do not use that ESC, so I don’t know how to interface with it.

thankyou for the response @Yuri_Rage . i did start the new topic but there was no response so i txted here

Have you gotten Hobbywing technical support to involve. Could it be the set of cable connected wrongly? I believe there are 2 sets of cables.

thanks jai .I got the output

hii
@Jai.GAY @Yuri_Rage
I’m currently working on enhancing the stability and efficiency of my hexacopter drone by implementing real-time PID tuning.

Instead of relying on traditional one-time AutoTune, I’m using live ESC current data (read through ArduPilot’s telemetry) to monitor the motors’ load conditions during flight. Based on this feedback, I’m dynamically adjusting the PID values (specifically the P, I, and D terms for pitch, roll, and yaw) to optimize performance in real-time.

This allows the drone to:

Respond better to varying flight conditions (like wind or payload changes)
Prevent oscillations or over-correction
Improve motor efficiency and reduce power consumption

I’m exploring to implement like:

  1. Using Lua scripting on the Cube Orange+ to directly adjust PID parameters during flight.
    Can you help me with the lua script.

is this the correct way which i can get exact tunning of PID? Can you help me through this

This is my mail shreyashankar1405@gmail.com . you can contact me through this.

Thanks and regards
shreya

The best solution is to tune it correctly (using the documented methods on the wiki) at least once.
Then use that as a starting point.
And use system identification to build a mathematical model of the system, then you can use different optimization criteria on that model depending on your flight phase requirements, and you can change your model based on changes to your system, like weight changes, inertia changes and so on.

Starting at an incorrect point and changing the PIDs without having a digital model (aka. digital twin) of the system is a long shot in the dark.

2 Likes

Can you guide me step by step

I already did that. I wrote ArduPilot methodic configurator software (free and open source) to semi-automate the tuning of any arducopter, big or small. That webpage contains step-by-step youtube videos.

And we wrote instructions on how to use system identification to build a mathematical model of your vehicle and there is also this webtool.

1 Like

okay i will go through it