current_sink.lua
otii.clear()
local example_profile = {{
current = 0.008, duration = 0.320, }, {
current = 0.003, duration = 0.968, }, {
resistance = 4.7, duration = 10.0, }, {
power = 0.5, duration = 10.0, }}
local max_iterations = 100
local min_voltage = 2.0
local project = otii.get_active_project()
if not project then
project = otii.create_project()
assert(project, "cannot create project")
end
local devices = otii.get_devices("Arc")
assert(#devices > 0, "No available devices")
local arc = otii.open_device(devices[1].id)
assert(arc, "Cannot open device")
function cleanup()
project:enable_main_power(false)
arc:enable_battery_profiling(false)
project:stop()
arc:set_power_regulation("voltage")
arc:close()
end
otii.on_stop(cleanup)
arc:set_power_regulation("current")
arc:set_range("high")
arc:set_battery_profile(example_profile)
project:start()
arc:enable_battery_profiling(true)
project:enable_main_power(true)
local iteration = -1
while true do
local battery_data = arc:wait_for_battery_data(60000)
if battery_data.iteration ~= iteration then
if battery_data.iteration >= max_iterations then
break
end
iteration = battery_data.iteration
otii.writeln(string.format("Iteration %d", iteration + 1))
end
otii.writeln(battery_data.voltage)
if battery_data.voltage < min_voltage then
otii.writeln("Voltage (" .. tostring(battery_data.voltage) .. ") below cut off voltage (" .. tostring(min_voltage) .. "), stop measurement")
break
end
end
cleanup()