mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
drivers: heater: fix module build and startup
- Startup was broken due to unnecessary cyclic check probably introduced during transition to work_queues - Module never used other than on Teal One which had a hacky heater input GPIO, this enables usage on general boards drivers: heater: reduce verbosity and simplify commandline options - We prefer the linux way of only reporting errors and staying quiet when everything is functioning as designed - Most of the commandline options just read out the values of the system parameters, and one can just check the parameter values directly. sensor_params: make thermal control parameters system parameters heater_params: make thermal control parameters system parameters drivers: heater: remove pin control hacks - px4_arch_configgpio(GPIO_HEATER_OUTPUT) directly inits the heater pin to OFF, and as a PUSHPULL (TTL totem pole) OUTPUT drivers: heater: set default device ID to 0
This commit is contained in:
parent
69694ab000
commit
00d00fdca9
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2018-19 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -37,6 +37,7 @@
|
||||
* @author Mark Sauder <mcsauder@gmail.com>
|
||||
* @author Alex Klimaj <alexklimaj@gmail.com>
|
||||
* @author Jake Dahl <dahl.jakejacob@gmail.com>
|
||||
* @author Mohammed Kabir <mhkabir@mit.edu>
|
||||
*/
|
||||
|
||||
#include "heater.h"
|
||||
@ -45,39 +46,22 @@
|
||||
#include <px4_platform_common/log.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
|
||||
#ifndef GPIO_HEATER_INPUT
|
||||
#error "To use the heater driver, the board_config.h must define and initialize GPIO_HEATER_INPUT and GPIO_HEATER_OUTPUT"
|
||||
#ifndef GPIO_HEATER_OUTPUT
|
||||
#error "To use the heater driver, the board_config.h must define and initialize GPIO_HEATER_OUTPUT"
|
||||
#endif
|
||||
|
||||
Heater::Heater() :
|
||||
ModuleParams(nullptr),
|
||||
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::lp_default)
|
||||
{
|
||||
// Initialize heater to off state
|
||||
px4_arch_configgpio(GPIO_HEATER_OUTPUT);
|
||||
px4_arch_gpiowrite(GPIO_HEATER_OUTPUT, 0);
|
||||
}
|
||||
|
||||
Heater::~Heater()
|
||||
{
|
||||
// Drive the heater GPIO pin low.
|
||||
px4_arch_gpiowrite(GPIO_HEATER_OUTPUT, 0);
|
||||
|
||||
// Verify if GPIO is low, and if not, configure it as an input pulldown then reconfigure as an output.
|
||||
if (px4_arch_gpioread(GPIO_HEATER_OUTPUT)) {
|
||||
px4_arch_configgpio(GPIO_HEATER_INPUT);
|
||||
px4_arch_configgpio(GPIO_HEATER_OUTPUT);
|
||||
px4_arch_gpiowrite(GPIO_HEATER_OUTPUT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int Heater::controller_period(char *argv[])
|
||||
{
|
||||
if (argv[1]) {
|
||||
_controller_period_usec = atoi(argv[1]);
|
||||
}
|
||||
|
||||
PX4_INFO("controller period (usec): %i", _controller_period_usec);
|
||||
return _controller_period_usec;
|
||||
// Reset heater to off state
|
||||
px4_arch_configgpio(GPIO_HEATER_OUTPUT);
|
||||
}
|
||||
|
||||
int Heater::custom_command(int argc, char *argv[])
|
||||
@ -88,35 +72,7 @@ int Heater::custom_command(int argc, char *argv[])
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
const char *arg_v = argv[0];
|
||||
|
||||
// Display/Set the heater controller period value (usec).
|
||||
if (strcmp(arg_v, "controller_period") == 0) {
|
||||
return get_instance()->controller_period(argv);
|
||||
}
|
||||
|
||||
// Display/Set the heater driver integrator gain value.
|
||||
if (strcmp(arg_v, "integrator") == 0) {
|
||||
return get_instance()->integrator(argv);
|
||||
}
|
||||
|
||||
// Display/Set the heater driver proportional gain value.
|
||||
if (strcmp(arg_v, "proportional") == 0) {
|
||||
return get_instance()->proportional(argv);
|
||||
}
|
||||
|
||||
// Display the id of the sensor we are controlling temperature on.
|
||||
if (strcmp(arg_v, "sensor_id") == 0) {
|
||||
return get_instance()->sensor_id();
|
||||
}
|
||||
|
||||
// Displays/Set the current IMU temperature setpoint.
|
||||
if (strcmp(arg_v, "setpoint") == 0) {
|
||||
return get_instance()->temperature_setpoint(argv);
|
||||
}
|
||||
|
||||
get_instance()->print_usage("Unrecognized command.");
|
||||
return PX4_OK;
|
||||
return print_usage("Unrecognized command.");
|
||||
}
|
||||
|
||||
void Heater::Run()
|
||||
@ -131,13 +87,6 @@ void Heater::Run()
|
||||
px4_arch_gpiowrite(GPIO_HEATER_OUTPUT, 0);
|
||||
_heater_on = false;
|
||||
|
||||
// Check if GPIO is stuck on, and if so, configure it as an input pulldown then reconfigure as an output.
|
||||
if (px4_arch_gpioread(GPIO_HEATER_OUTPUT)) {
|
||||
px4_arch_configgpio(GPIO_HEATER_INPUT);
|
||||
px4_arch_configgpio(GPIO_HEATER_OUTPUT);
|
||||
px4_arch_gpiowrite(GPIO_HEATER_OUTPUT, 0);
|
||||
}
|
||||
|
||||
} else {
|
||||
update_params(false);
|
||||
|
||||
@ -166,7 +115,6 @@ void Heater::Run()
|
||||
|
||||
// Turn the heater on.
|
||||
_heater_on = true;
|
||||
|
||||
px4_arch_gpiowrite(GPIO_HEATER_OUTPUT, 1);
|
||||
}
|
||||
|
||||
@ -196,13 +144,10 @@ void Heater::initialize_topics()
|
||||
|
||||
// If the correct ID is found, exit the for-loop with _sensor_accel_sub pointing to the correct instance.
|
||||
if (_sensor_accel.device_id == (uint32_t)_param_sens_temp_id.get()) {
|
||||
PX4_INFO("IMU sensor identified.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
PX4_INFO("Device ID: %d", _sensor_accel.device_id);
|
||||
|
||||
// Exit the driver if the sensor ID does not match the desired sensor.
|
||||
if (_sensor_accel.device_id != (uint32_t)_param_sens_temp_id.get()) {
|
||||
request_stop();
|
||||
@ -210,19 +155,10 @@ void Heater::initialize_topics()
|
||||
}
|
||||
}
|
||||
|
||||
float Heater::integrator(char *argv[])
|
||||
{
|
||||
if (argv[1]) {
|
||||
_param_sens_imu_temp_i.set(atof(argv[1]));
|
||||
}
|
||||
|
||||
PX4_INFO("Integrator gain: %2.5f", (double)_param_sens_imu_temp_i.get());
|
||||
return _param_sens_imu_temp_i.get();
|
||||
}
|
||||
|
||||
int Heater::print_status()
|
||||
{
|
||||
PX4_INFO("Temperature: %3.3fC - Setpoint: %3.2fC - Heater State: %s",
|
||||
PX4_INFO("Sensor ID: %d - Temperature: %3.3fC, Setpoint: %3.2fC, Heater State: %s",
|
||||
_sensor_accel.device_id,
|
||||
(double)_sensor_temperature,
|
||||
(double)_param_sens_imu_temp.get(),
|
||||
_heater_on ? "On" : "Off");
|
||||
@ -230,36 +166,13 @@ int Heater::print_status()
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
float Heater::proportional(char *argv[])
|
||||
{
|
||||
if (argv[1]) {
|
||||
_param_sens_imu_temp_p.set(atof(argv[1]));
|
||||
}
|
||||
|
||||
PX4_INFO("Proportional gain: %2.5f", (double)_param_sens_imu_temp_p.get());
|
||||
return _param_sens_imu_temp_p.get();
|
||||
}
|
||||
|
||||
uint32_t Heater::sensor_id()
|
||||
{
|
||||
PX4_INFO("Sensor ID: %d", _sensor_accel.device_id);
|
||||
return _sensor_accel.device_id;
|
||||
}
|
||||
|
||||
int Heater::start()
|
||||
{
|
||||
if (is_running()) {
|
||||
PX4_INFO("Driver already running.");
|
||||
return PX4_ERROR;
|
||||
}
|
||||
|
||||
update_params(true);
|
||||
initialize_topics();
|
||||
|
||||
ScheduleNow();
|
||||
|
||||
PX4_INFO("Driver started successfully.");
|
||||
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
@ -280,16 +193,6 @@ int Heater::task_spawn(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
float Heater::temperature_setpoint(char *argv[])
|
||||
{
|
||||
if (argv[1]) {
|
||||
_param_sens_imu_temp.set(atof(argv[1]));
|
||||
}
|
||||
|
||||
PX4_INFO("Target temp: %3.3f", (double)_param_sens_imu_temp.get());
|
||||
return _param_sens_imu_temp.get();
|
||||
}
|
||||
|
||||
void Heater::update_params(const bool force)
|
||||
{
|
||||
// check for parameter updates
|
||||
@ -318,15 +221,7 @@ This task can be started at boot from the startup scripts by setting SENS_EN_THE
|
||||
)DESCR_STR");
|
||||
|
||||
PRINT_MODULE_USAGE_NAME("heater", "system");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("controller_period", "Reports the heater driver cycle period value, (us), and sets it if supplied an argument.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("integrator", "Sets the integrator gain value if supplied an argument and reports the current value.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("proportional", "Sets the proportional gain value if supplied an argument and reports the current value.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("sensor_id", "Reports the current IMU the heater is temperature controlling.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("setpoint", "Reports the current IMU temperature.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("start", "Starts the IMU heater driver as a background task");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("status", "Reports the current IMU temperature, temperature setpoint, and heater on/off status.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("stop", "Stops the IMU heater driver.");
|
||||
PRINT_MODULE_USAGE_COMMAND_DESCR("temp", "Reports the current IMU temperature.");
|
||||
PRINT_MODULE_USAGE_COMMAND("start");
|
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS();
|
||||
|
||||
return 0;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2018-19 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -43,13 +43,15 @@
|
||||
/**
|
||||
* Target IMU device ID to regulate temperature.
|
||||
*
|
||||
* @category system
|
||||
* @group Sensors
|
||||
*/
|
||||
PARAM_DEFINE_INT32(SENS_TEMP_ID, 1442826);
|
||||
PARAM_DEFINE_INT32(SENS_TEMP_ID, 0);
|
||||
|
||||
/**
|
||||
* Target IMU temperature.
|
||||
*
|
||||
* @category system
|
||||
* @group Sensors
|
||||
* @unit C
|
||||
* @min 0
|
||||
@ -61,6 +63,7 @@ PARAM_DEFINE_FLOAT(SENS_IMU_TEMP, 55.0f);
|
||||
/**
|
||||
* IMU heater controller integrator gain value.
|
||||
*
|
||||
* @category system
|
||||
* @group Sensors
|
||||
* @unit microseconds/C
|
||||
* @min 0
|
||||
@ -69,10 +72,10 @@ PARAM_DEFINE_FLOAT(SENS_IMU_TEMP, 55.0f);
|
||||
*/
|
||||
PARAM_DEFINE_FLOAT(SENS_IMU_TEMP_I, 0.025f);
|
||||
|
||||
|
||||
/**
|
||||
* IMU heater controller proportional gain value.
|
||||
*
|
||||
* @category system
|
||||
* @group Sensors
|
||||
* @unit microseconds/C
|
||||
* @min 0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2012-2019 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -207,6 +207,8 @@ PARAM_DEFINE_FLOAT(SENS_BOARD_Z_OFF, 0.0f);
|
||||
*
|
||||
* @value -1 Thermal control unavailable
|
||||
* @value 0 Thermal control off
|
||||
* @value 1 Thermal control enabled
|
||||
* @category system
|
||||
* @group Sensors
|
||||
*/
|
||||
PARAM_DEFINE_INT32(SENS_EN_THERMAL, -1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user