mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
Merged in f5soh/librepilot/LP-612_temp_ntc_sensor (pull request #532)
LP-612 Temperature module Approved-by: Lalanne Laurent <f5soh@free.fr> Approved-by: Paul Jewell <teulupaul@gmail.com>
This commit is contained in:
commit
e4a08179e0
43
flight/modules/Temperature/inc/temperature.h
Normal file
43
flight/modules/Temperature/inc/temperature.h
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||||
|
* @{
|
||||||
|
* @addtogroup TemperatureModule Temperature Module
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file temperature.h
|
||||||
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2019.
|
||||||
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Module to read the temperature periodically from NTC or LM35 sensors.
|
||||||
|
*
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
#ifndef TEMPERATURE_H
|
||||||
|
#define TEMPERATURE_H
|
||||||
|
|
||||||
|
#include "openpilot.h"
|
||||||
|
|
||||||
|
int32_t TemperatureInitialize(void);
|
||||||
|
|
||||||
|
#endif // TEMPERATURE_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
* @}
|
||||||
|
*/
|
175
flight/modules/Temperature/temperature.c
Normal file
175
flight/modules/Temperature/temperature.c
Normal file
@ -0,0 +1,175 @@
|
|||||||
|
/**
|
||||||
|
******************************************************************************
|
||||||
|
* @addtogroup OpenPilotModules OpenPilot Modules
|
||||||
|
* @{
|
||||||
|
* @addtogroup TemperatureModule Temperature Module
|
||||||
|
* @brief Measures the temperature from external sensor.
|
||||||
|
* Updates the TemperatureState object
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file temperature.c
|
||||||
|
* @author The LibrePilot Project, http://www.librepilot.org Copyright (C) 2019.
|
||||||
|
* The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||||
|
* @brief Module to read the temperature periodically from NTC or LM35 sensors.
|
||||||
|
*
|
||||||
|
* @see The GNU Public License (GPL) Version 3
|
||||||
|
*
|
||||||
|
*****************************************************************************/
|
||||||
|
/*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output object: TemperatureState
|
||||||
|
*
|
||||||
|
* This module will periodically generate information on the temperature state.
|
||||||
|
*
|
||||||
|
* UAVObjects are automatically generated by the UAVObjectGenerator from
|
||||||
|
* the object definition XML file.
|
||||||
|
*
|
||||||
|
* Modules have no API, all communication to other modules is done through UAVObjects.
|
||||||
|
* However modules may use the API exposed by shared libraries.
|
||||||
|
* See the OpenPilot wiki for more details.
|
||||||
|
* http://www.openpilot.org/OpenPilot_Application_Architecture
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "openpilot.h"
|
||||||
|
|
||||||
|
#include "temperaturestate.h"
|
||||||
|
#include "temperaturesettings.h"
|
||||||
|
#include "hwsettings.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Configuration
|
||||||
|
//
|
||||||
|
#define SAMPLE_PERIOD_MS 500
|
||||||
|
|
||||||
|
#ifndef PIOS_ADC_NTCTEMPERATURE_PIN
|
||||||
|
#define PIOS_ADC_NTCTEMPERATURE_PIN -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef PIOS_ADC_LM35TEMPERATURE_PIN
|
||||||
|
#define PIOS_ADC_LM35TEMPERATURE_PIN -1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int8_t ntcTemperatureADCPin = PIOS_ADC_NTCTEMPERATURE_PIN; // ADC pin for temperature (ntc)
|
||||||
|
static int8_t lm35TemperatureADCPin = PIOS_ADC_LM35TEMPERATURE_PIN; // ADC pin for temperature (lm35)
|
||||||
|
|
||||||
|
// Private functions
|
||||||
|
static void onTimer(UAVObjEvent *ev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialise the module, called on startup
|
||||||
|
* \returns 0 on success or -1 if initialisation failed
|
||||||
|
*/
|
||||||
|
int32_t TemperatureInitialize(void)
|
||||||
|
{
|
||||||
|
bool temperatureEnabled;
|
||||||
|
|
||||||
|
HwSettingsOptionalModulesData optionalModules;
|
||||||
|
|
||||||
|
HwSettingsOptionalModulesGet(&optionalModules);
|
||||||
|
|
||||||
|
#ifdef MODULE_TEMPERATURE_BUILTIN
|
||||||
|
temperatureEnabled = true;
|
||||||
|
optionalModules.Temperature = HWSETTINGS_OPTIONALMODULES_ENABLED;
|
||||||
|
HwSettingsOptionalModulesSet(&optionalModules);
|
||||||
|
#else
|
||||||
|
if (optionalModules.Temperature == HWSETTINGS_OPTIONALMODULES_ENABLED) {
|
||||||
|
temperatureEnabled = true;
|
||||||
|
} else {
|
||||||
|
temperatureEnabled = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t adcRouting[HWSETTINGS_ADCROUTING_NUMELEM];
|
||||||
|
HwSettingsADCRoutingArrayGet(adcRouting);
|
||||||
|
|
||||||
|
// Determine if the temperature sensors are routed to ADC pins
|
||||||
|
for (int i = 0; i < HWSETTINGS_ADCROUTING_NUMELEM; i++) {
|
||||||
|
if (adcRouting[i] == HWSETTINGS_ADCROUTING_NTCTEMPERATURE) {
|
||||||
|
ntcTemperatureADCPin = i;
|
||||||
|
}
|
||||||
|
if (adcRouting[i] == HWSETTINGS_ADCROUTING_LM35TEMPERATURE) {
|
||||||
|
lm35TemperatureADCPin = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't enable module if no ADC pins are routed to the sensors
|
||||||
|
if (ntcTemperatureADCPin < 0 && lm35TemperatureADCPin < 0) {
|
||||||
|
temperatureEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start module
|
||||||
|
if (temperatureEnabled) {
|
||||||
|
TemperatureStateInitialize();
|
||||||
|
|
||||||
|
static UAVObjEvent ev;
|
||||||
|
|
||||||
|
memset(&ev, 0, sizeof(UAVObjEvent));
|
||||||
|
EventPeriodicCallbackCreate(&ev, onTimer, SAMPLE_PERIOD_MS / portTICK_RATE_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MODULE_INITCALL(TemperatureInitialize, 0);
|
||||||
|
static void onTimer(__attribute__((unused)) UAVObjEvent *ev)
|
||||||
|
{
|
||||||
|
static TemperatureSettingsData temperatureSettings;
|
||||||
|
static TemperatureStateData temperatureData;
|
||||||
|
|
||||||
|
TemperatureSettingsGet(&temperatureSettings);
|
||||||
|
TemperatureStateGet(&temperatureData);
|
||||||
|
|
||||||
|
#ifdef PIOS_INCLUDE_ADC
|
||||||
|
// calculate the temperature (ntc)
|
||||||
|
if (ntcTemperatureADCPin >= 0) {
|
||||||
|
float ntc_resistance = 0;
|
||||||
|
|
||||||
|
if (temperatureSettings.NtcVoltageDivider == TEMPERATURESETTINGS_NTCVOLTAGEDIVIDER_NTCTOGROUND) {
|
||||||
|
ntc_resistance = temperatureSettings.NtcSerialResistor / ((temperatureSettings.NtcVoltageReference / PIOS_ADC_PinGetVolt(ntcTemperatureADCPin)) - 1);
|
||||||
|
} else if (temperatureSettings.NtcVoltageDivider == TEMPERATURESETTINGS_NTCVOLTAGEDIVIDER_NTCTOVREF) {
|
||||||
|
ntc_resistance = temperatureSettings.NtcSerialResistor * ((temperatureSettings.NtcVoltageReference / PIOS_ADC_PinGetVolt(ntcTemperatureADCPin)) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
float steinhart = ntc_resistance / temperatureSettings.NtcNominalValue;
|
||||||
|
steinhart = logf(steinhart);
|
||||||
|
steinhart /= temperatureSettings.NtcBetaCoeff;
|
||||||
|
steinhart += 1.0f / (temperatureSettings.NtcNominalTemperature + 273.15f);
|
||||||
|
steinhart = 1.0f / steinhart;
|
||||||
|
temperatureData.Temperature1 = steinhart - 273.15f;
|
||||||
|
} else {
|
||||||
|
temperatureData.Temperature1 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate the temperature (lm35)
|
||||||
|
if (lm35TemperatureADCPin >= 0) {
|
||||||
|
temperatureData.Temperature2 = (PIOS_ADC_PinGetVolt(lm35TemperatureADCPin) / temperatureSettings.Lm35Sensitivity);
|
||||||
|
} else {
|
||||||
|
temperatureData.Temperature2 = 0;
|
||||||
|
}
|
||||||
|
#else /* ifdef PIOS_INCLUDE_ADC */
|
||||||
|
temperatureData.Temperature1 = 0;
|
||||||
|
temperatureData.Temperature2 = 0;
|
||||||
|
#endif /* PIOS_INCLUDE_ADC */
|
||||||
|
|
||||||
|
TemperatureStateSet(&temperatureData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
@ -54,6 +54,7 @@ MODULES += Telemetry
|
|||||||
MODULES += Notify
|
MODULES += Notify
|
||||||
|
|
||||||
OPTMODULES += AutoTune
|
OPTMODULES += AutoTune
|
||||||
|
OPTMODULES += Temperature
|
||||||
OPTMODULES += ComUsbBridge
|
OPTMODULES += ComUsbBridge
|
||||||
OPTMODULES += UAVOHottBridge
|
OPTMODULES += UAVOHottBridge
|
||||||
OPTMODULES += UAVOMSPBridge
|
OPTMODULES += UAVOMSPBridge
|
||||||
|
@ -122,6 +122,8 @@ UAVOBJSRCFILENAMES += waypointactive
|
|||||||
UAVOBJSRCFILENAMES += poilocation
|
UAVOBJSRCFILENAMES += poilocation
|
||||||
UAVOBJSRCFILENAMES += poilearnsettings
|
UAVOBJSRCFILENAMES += poilearnsettings
|
||||||
UAVOBJSRCFILENAMES += mpugyroaccelsettings
|
UAVOBJSRCFILENAMES += mpugyroaccelsettings
|
||||||
|
UAVOBJSRCFILENAMES += temperaturesettings
|
||||||
|
UAVOBJSRCFILENAMES += temperaturestate
|
||||||
UAVOBJSRCFILENAMES += txpidsettings
|
UAVOBJSRCFILENAMES += txpidsettings
|
||||||
UAVOBJSRCFILENAMES += txpidstatus
|
UAVOBJSRCFILENAMES += txpidstatus
|
||||||
UAVOBJSRCFILENAMES += hottbridgesettings
|
UAVOBJSRCFILENAMES += hottbridgesettings
|
||||||
|
@ -53,6 +53,7 @@ MODULES += Telemetry
|
|||||||
MODULES += Notify
|
MODULES += Notify
|
||||||
|
|
||||||
OPTMODULES += AutoTune
|
OPTMODULES += AutoTune
|
||||||
|
OPTMODULES += Temperature
|
||||||
OPTMODULES += ComUsbBridge
|
OPTMODULES += ComUsbBridge
|
||||||
OPTMODULES += UAVOMSPBridge
|
OPTMODULES += UAVOMSPBridge
|
||||||
OPTMODULES += UAVOMavlinkBridge
|
OPTMODULES += UAVOMavlinkBridge
|
||||||
|
@ -122,6 +122,8 @@ UAVOBJSRCFILENAMES += waypointactive
|
|||||||
UAVOBJSRCFILENAMES += poilocation
|
UAVOBJSRCFILENAMES += poilocation
|
||||||
UAVOBJSRCFILENAMES += poilearnsettings
|
UAVOBJSRCFILENAMES += poilearnsettings
|
||||||
UAVOBJSRCFILENAMES += mpugyroaccelsettings
|
UAVOBJSRCFILENAMES += mpugyroaccelsettings
|
||||||
|
UAVOBJSRCFILENAMES += temperaturesettings
|
||||||
|
UAVOBJSRCFILENAMES += temperaturestate
|
||||||
UAVOBJSRCFILENAMES += txpidsettings
|
UAVOBJSRCFILENAMES += txpidsettings
|
||||||
UAVOBJSRCFILENAMES += txpidstatus
|
UAVOBJSRCFILENAMES += txpidstatus
|
||||||
UAVOBJSRCFILENAMES += hottbridgesettings
|
UAVOBJSRCFILENAMES += hottbridgesettings
|
||||||
|
@ -54,6 +54,7 @@ MODULES += Telemetry
|
|||||||
MODULES += Notify
|
MODULES += Notify
|
||||||
|
|
||||||
OPTMODULES += AutoTune
|
OPTMODULES += AutoTune
|
||||||
|
OPTMODULES += Temperature
|
||||||
OPTMODULES += ComUsbBridge
|
OPTMODULES += ComUsbBridge
|
||||||
OPTMODULES += UAVOMSPBridge
|
OPTMODULES += UAVOMSPBridge
|
||||||
OPTMODULES += UAVOMavlinkBridge
|
OPTMODULES += UAVOMavlinkBridge
|
||||||
|
@ -122,6 +122,8 @@ UAVOBJSRCFILENAMES += waypointactive
|
|||||||
UAVOBJSRCFILENAMES += poilocation
|
UAVOBJSRCFILENAMES += poilocation
|
||||||
UAVOBJSRCFILENAMES += poilearnsettings
|
UAVOBJSRCFILENAMES += poilearnsettings
|
||||||
UAVOBJSRCFILENAMES += mpugyroaccelsettings
|
UAVOBJSRCFILENAMES += mpugyroaccelsettings
|
||||||
|
UAVOBJSRCFILENAMES += temperaturesettings
|
||||||
|
UAVOBJSRCFILENAMES += temperaturestate
|
||||||
UAVOBJSRCFILENAMES += txpidsettings
|
UAVOBJSRCFILENAMES += txpidsettings
|
||||||
UAVOBJSRCFILENAMES += txpidstatus
|
UAVOBJSRCFILENAMES += txpidstatus
|
||||||
UAVOBJSRCFILENAMES += takeofflocation
|
UAVOBJSRCFILENAMES += takeofflocation
|
||||||
|
@ -152,6 +152,8 @@ UAVOBJS = \
|
|||||||
$${UAVOBJ_XML_DIR}/systemstats.xml \
|
$${UAVOBJ_XML_DIR}/systemstats.xml \
|
||||||
$${UAVOBJ_XML_DIR}/takeofflocation.xml \
|
$${UAVOBJ_XML_DIR}/takeofflocation.xml \
|
||||||
$${UAVOBJ_XML_DIR}/taskinfo.xml \
|
$${UAVOBJ_XML_DIR}/taskinfo.xml \
|
||||||
|
$${UAVOBJ_XML_DIR}/temperaturesettings.xml \
|
||||||
|
$${UAVOBJ_XML_DIR}/temperaturestate.xml \
|
||||||
$${UAVOBJ_XML_DIR}/txpidsettings.xml \
|
$${UAVOBJ_XML_DIR}/txpidsettings.xml \
|
||||||
$${UAVOBJ_XML_DIR}/txpidstatus.xml \
|
$${UAVOBJ_XML_DIR}/txpidstatus.xml \
|
||||||
$${UAVOBJ_XML_DIR}/velocitydesired.xml \
|
$${UAVOBJ_XML_DIR}/velocitydesired.xml \
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,DebugConsole,Disabled,MAVLink" defaultvalue="Disabled"/>
|
<field name="USB_VCPPort" units="function" type="enum" elements="1" options="USBTelemetry,ComBridge,DebugConsole,Disabled,MAVLink" defaultvalue="Disabled"/>
|
||||||
<field name="RadioAuxStream" units="function" type="enum" elements="1" options="DebugConsole,Disabled,MAVLink,ComBridge" defaultvalue="Disabled"/>
|
<field name="RadioAuxStream" units="function" type="enum" elements="1" options="DebugConsole,Disabled,MAVLink,ComBridge" defaultvalue="Disabled"/>
|
||||||
|
|
||||||
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,CameraControl,GPS,Fault,Altitude,Airspeed,TxPID,Battery,Overo,MagBaro,OsdHk,AutoTune" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
<field name="OptionalModules" units="" type="enum" elementnames="CameraStab,CameraControl,GPS,Fault,Altitude,Airspeed,TxPID,Battery,Temperature,Overo,MagBaro,OsdHk,AutoTune" options="Disabled,Enabled" defaultvalue="Disabled"/>
|
||||||
<field name="ADCRouting" units="" type="enum" elementnames="adc0,adc1,adc2,adc3,adc4,adc5,adc6,adc7" options="Disabled,BatteryVoltage,BatteryCurrent,AnalogAirspeed,Generic" defaultvalue="Disabled"/>
|
<field name="ADCRouting" units="" type="enum" elementnames="adc0,adc1,adc2,adc3,adc4,adc5,adc6,adc7" options="Disabled,BatteryVoltage,BatteryCurrent,AnalogAirspeed,NTCTemperature,LM35Temperature,Generic" defaultvalue="Disabled"/>
|
||||||
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
|
<field name="DSMxBind" units="" type="uint8" elements="1" defaultvalue="0"/>
|
||||||
<field name="SBusMode" units="" type="enum" elements="1" options="Normal,Non Inverted" defaultvalue="Normal"/>
|
<field name="SBusMode" units="" type="enum" elements="1" options="Normal,Non Inverted" defaultvalue="Normal"/>
|
||||||
<field name="WS2811LED_Out" units="" type="enum" elements="1" options="ServoOut1,ServoOut2,ServoOut3,ServoOut4,ServoOut5,ServoOut6,FlexiIOPin3,FlexiIOPin4,Disabled" defaultvalue="Disabled"
|
<field name="WS2811LED_Out" units="" type="enum" elements="1" options="ServoOut1,ServoOut2,ServoOut3,ServoOut4,ServoOut5,ServoOut6,FlexiIOPin3,FlexiIOPin4,Disabled" defaultvalue="Disabled"
|
||||||
|
16
shared/uavobjectdefinition/temperaturesettings.xml
Normal file
16
shared/uavobjectdefinition/temperaturesettings.xml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<xml>
|
||||||
|
<object name="TemperatureSettings" singleinstance="true" settings="true" category="Sensors">
|
||||||
|
<description>Temperature sensor configuration.</description>
|
||||||
|
<field name="Lm35Sensitivity" units="V/C" type="float" elements="1" defaultvalue="0.01"/>
|
||||||
|
<field name="NtcVoltageReference" units="V" type="float" elements="1" defaultvalue="3.3"/>
|
||||||
|
<field name="NtcSerialResistor" units="Ohms" type="uint32" elements="1" defaultvalue="10000"/>
|
||||||
|
<field name="NtcNominalValue" units="Ohms" type="uint32" elements="1" defaultvalue="100000"/>
|
||||||
|
<field name="NtcNominalTemperature" units="C" type="uint16" elements="1" defaultvalue="25"/>
|
||||||
|
<field name="NtcBetaCoeff" units="K" type="uint16" elements="1" defaultvalue="4000"/>
|
||||||
|
<field name="NtcVoltageDivider" units="" type="enum" elements="1" options="NTCtoGround,NTCtoVref" defaultvalue="NTCtoGround"/>
|
||||||
|
<access gcs="readwrite" flight="readwrite"/>
|
||||||
|
<telemetrygcs acked="true" updatemode="onchange" period="0"/>
|
||||||
|
<telemetryflight acked="true" updatemode="onchange" period="0"/>
|
||||||
|
<logging updatemode="manual" period="0"/>
|
||||||
|
</object>
|
||||||
|
</xml>
|
11
shared/uavobjectdefinition/temperaturestate.xml
Normal file
11
shared/uavobjectdefinition/temperaturestate.xml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<xml>
|
||||||
|
<object name="TemperatureState" singleinstance="true" settings="false" category="Sensors">
|
||||||
|
<description>Temperature status information.</description>
|
||||||
|
<field name="Temperature1" units="C" type="float" elements="1" description="NTC temp sensor"/>
|
||||||
|
<field name="Temperature2" units="C" type="float" elements="1" description="LM35 temp sensor"/>
|
||||||
|
<access gcs="readonly" flight="readwrite"/>
|
||||||
|
<telemetrygcs acked="false" updatemode="manual" period="0"/>
|
||||||
|
<telemetryflight acked="false" updatemode="periodic" period="1000"/>
|
||||||
|
<logging updatemode="manual" period="0"/>
|
||||||
|
</object>
|
||||||
|
</xml>
|
Loading…
x
Reference in New Issue
Block a user