MPC9808: Run ScheduleOnInterval() at desired publishing rate and remove elapsed time check and timestamp_sample field from message as no longer needed.

MCP9808: Replaced PX4_INFO with PX4_DEBUG

MCP9808: Update date in headers

MCP9808: Define functions before variables

MCP9808: Increase logging interval for sensor_temp

MCP9808: Removed extra space

MCP9808: Remove this->
This commit is contained in:
TedObrien 2025-03-29 11:07:30 +00:00 committed by Jacob Dahl
parent ddb98abf1d
commit 5483d901f9
7 changed files with 20 additions and 29 deletions

View File

@ -1,6 +1,4 @@
uint64 timestamp # time since system start (microseconds) uint64 timestamp # time since system start (microseconds)
uint64 timestamp_sample # Time at which measurement was taken
uint32 device_id # unique device ID for the sensor that does not change between power cycles uint32 device_id # unique device ID for the sensor that does not change between power cycles
float32 temperature # Temperature provided by sensor (Celsius) float32 temperature # Temperature provided by sensor (Celsius)

View File

@ -1,6 +1,6 @@
############################################################################ ############################################################################
# #
# Copyright (c) 2024 PX4 Development Team. All rights reserved. # Copyright (c) 2025 PX4 Development Team. All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions # modification, are permitted provided that the following conditions

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2024 PX4 Development Team. All rights reserved. * Copyright (c) 2025 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -39,7 +39,7 @@ MCP9808::MCP9808(const I2CSPIDriverConfig &config) :
_cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": single-sample")), _cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": single-sample")),
_comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors")) _comms_errors(perf_alloc(PC_COUNT, MODULE_NAME": comms errors"))
{ {
_sensor_temp.device_id = this->get_device_id(); _sensor_temp.device_id = get_device_id();
} }
MCP9808::~MCP9808() MCP9808::~MCP9808()
@ -53,23 +53,17 @@ void MCP9808::RunImpl()
{ {
perf_begin(_cycle_perf); perf_begin(_cycle_perf);
// publish at around 5HZ float temperature = read_temperature();
if ((hrt_elapsed_time(&measurement_time)) > 200_ms) {
float temperature = read_temperature(); if (std::isnan(temperature)) {
measurement_time = hrt_absolute_time(); // get the time the measurement was taken
if (std::isnan(temperature)) { perf_count(_comms_errors);
perf_count(_comms_errors); } else {
_sensor_temp.timestamp = hrt_absolute_time();
_sensor_temp.temperature = temperature;
} else { _sensor_temp_pub.publish(_sensor_temp);
_sensor_temp.timestamp = hrt_absolute_time();
_sensor_temp.timestamp_sample = measurement_time;
_sensor_temp.temperature = temperature;
_sensor_temp_pub.publish(_sensor_temp);
}
} }
perf_end(_cycle_perf); perf_end(_cycle_perf);
@ -109,7 +103,7 @@ int MCP9808::init()
return ret; return ret;
} }
PX4_INFO("I2C initialized successfully"); PX4_DEBUG("I2C initialized successfully");
ret = write_reg(MCP9808_REG_CONFIG, 0x0000); // Ensure default configuration ret = write_reg(MCP9808_REG_CONFIG, 0x0000); // Ensure default configuration
@ -120,7 +114,7 @@ int MCP9808::init()
_sensor_temp_pub.advertise(); _sensor_temp_pub.advertise();
ScheduleOnInterval(100_ms); // Sample at 10 Hz ScheduleOnInterval(200_ms); // Sample at 5 Hz
return PX4_OK; return PX4_OK;
} }

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2024 PX4 Development Team. All rights reserved. * Copyright (c) 2025 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -66,11 +66,10 @@ protected:
private: private:
uORB::PublicationMulti<sensor_temp_s> _sensor_temp_pub{ORB_ID(sensor_temp)}; uORB::PublicationMulti<sensor_temp_s> _sensor_temp_pub{ORB_ID(sensor_temp)};
perf_counter_t _cycle_perf;
perf_counter_t _comms_errors;
sensor_temp_s _sensor_temp{};
int read_reg(uint8_t address, uint16_t &data); int read_reg(uint8_t address, uint16_t &data);
int write_reg(uint8_t address, uint16_t value); int write_reg(uint8_t address, uint16_t value);
float read_temperature(); float read_temperature();
hrt_abstime measurement_time = 0; sensor_temp_s _sensor_temp{};
perf_counter_t _cycle_perf;
perf_counter_t _comms_errors;
}; };

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2024 PX4 Development Team. All rights reserved. * Copyright (c) 2025 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -35,7 +35,7 @@
* @file mcp9808_main.cpp * @file mcp9808_main.cpp
* @author TedObrien * @author TedObrien
* *
* Driver for the Microchip MCP9080 Temperature Sensor connected via I2C. * Driver for the Microchip MCP9080 Temperature Sensor connected via I2C.
*/ */
#include "mcp9808.h" #include "mcp9808.h"

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2024 PX4 Development Team. All rights reserved. * Copyright (c) 2025 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions

View File

@ -123,7 +123,7 @@ void LoggedTopics::add_default_topics()
add_optional_topic("sensor_gyro_fft", 50); add_optional_topic("sensor_gyro_fft", 50);
add_topic("sensor_selection"); add_topic("sensor_selection");
add_topic("sensors_status_imu", 200); add_topic("sensors_status_imu", 200);
add_optional_topic("sensor_temp", 10); add_optional_topic("sensor_temp", 100);
add_optional_topic("spoilers_setpoint", 1000); add_optional_topic("spoilers_setpoint", 1000);
add_topic("system_power", 500); add_topic("system_power", 500);
add_optional_topic("takeoff_status", 1000); add_optional_topic("takeoff_status", 1000);