Skip to content

Commit

Permalink
AP_Scripting: add bindings for the AP_TemperatureSensor
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Sep 22, 2024
1 parent 0020cf5 commit 83c9b32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3140,6 +3140,14 @@ function BattMonitorScript_State_ud:voltage(value) end
---@param value boolean
function BattMonitorScript_State_ud:healthy(value) end

-- The temperature library provides access to information about the currently connected temperature sensors on the vehicle.
temperature_sensor = {}

-- Returns the temperature from this sensor in degrees Celsius
---@param instance integer -- temperature instance
---@return number|nil -- temperature if available
function temperature_sensor:get_temperature(instance) end

-- The battery library provides access to information about the currently connected batteries on the vehicle.
battery = {}

Expand Down
18 changes: 18 additions & 0 deletions libraries/AP_Scripting/examples/temperature_sensor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--[[
simple example of reading a temperature sensor
--]]

local MAV_SEVERITY = {EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFO=6, DEBUG=7}

--[[
main update function, called at 1Hz
--]]
function update()
local temperature_C = temperature_sensor:get_temperature(0)
gcs:send_text(MAV_SEVERITY.INFO, string.format("Temperature: %f", temperature_C))
return update, 1000
end

-- start running update loop
return update, 1000

6 changes: 6 additions & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -977,3 +977,9 @@ singleton AP_VisualOdom depends HAL_VISUALODOM_ENABLED
singleton AP_VisualOdom rename visual_odom
singleton AP_VisualOdom method healthy boolean
singleton AP_VisualOdom method quality int8_t

-- ----AP_TemperatureSensor Library----
include AP_TemperatureSensor/AP_TemperatureSensor.h
singleton AP_TemperatureSensor depends AP_TEMPERATURE_SENSOR_ENABLED
singleton AP_TemperatureSensor rename temperature_sensor
singleton AP_TemperatureSensor method get_temperature boolean float'Null uint8_t'skip_check

0 comments on commit 83c9b32

Please sign in to comment.