Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
thermal_ctl.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Fabien-B <fabien-b@github.com>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
37#include <stdio.h>
38#include <string.h>
39
40float thermal_ctl = 0;
42
43#define THERMAL_CTL_NONE 0
44#define THERMAL_CTL_PWR_OFF 1
45#define THERMAL_CTL_REC_ON 2
46#define THERMAL_CTL_REC_OFF 3
47
48#define NB_SPOTS 3
49
58
59
61
62static void thermal_send_draw(struct thermal_spot* spot);
63static void update_hottests(struct thermal_spot* spot);
64
65
67 int val = (int)value;
68 uint8_t tab[2];
69 uint8_t dst_id = 0;
71 tab[0] = 's';
72 tab[1] = 0;
73 } else if(val == THERMAL_CTL_REC_ON) {
74 tab[0] = 'r';
75 tab[1] = 1;
76 } else if(val == THERMAL_CTL_REC_OFF) {
77 tab[0] = 'r';
78 tab[1] = 0;
79 } else {
80 return;
81 }
82
84
85}
86
88 thermal_threshold = value;
89 uint8_t kind = value > 0 ? 'h': 'c';
90 uint8_t tab[2] = {kind, (uint8_t)fabs(value)};
91 uint8_t dst_id = 0;
93}
94
96{
97 // PAYLOAD_FLOAT: cluster_key,east,north,up,latitude,longitude,median_temperature,member_count
98
100 if (nb != 8) { return; }
101
103
104 // prevent unaligned access
105 float data[8];
106 memcpy(data, b, 8*sizeof(float));
107
108
109 struct thermal_spot spot = {
110 .cluster_idx = data[0] + 1, // first is id 1, 0 is reserved.
111 .lat = data[4] * 1e7,
112 .lon = data[5] * 1e7,
113 .temp = data[6],
114 .count = data[7],
115 };
116
119}
120
121static void update_hottests(struct thermal_spot* spot) {
122 int coldest_idx = 0;
123 for (int i=0; i<NB_SPOTS; i++) {
124 struct thermal_spot *hp = &hottest_spots[i];
125
126 // cluster found in hottests, just update it.
127 if (hp->cluster_idx == spot->cluster_idx) {
128 memcpy(hp, spot, sizeof(struct thermal_spot));
129 return;
130 }
131
132 // find the coldest/hottest amongst the array.
133 if ((hp->temp < hottest_spots[coldest_idx].temp && thermal_threshold > 0) ||
135 coldest_idx = i;
136 }
137 }
138
139 // the new spot it hotter than the coldest of the array, save it in place of the coldest.
140 // or colder than the hottest.
141 if ((spot->temp > hottest_spots[coldest_idx].temp && thermal_threshold > 0) ||
144 }
145}
146
147
149{
150 uint8_t color = 0 << 6 | 5 << 3 | 5; // Transparent, Magenta, Magenta
151 uint8_t shape = 0;
152 uint8_t status = 0;
153 float radius = 2;
154
155 char text[10];
156 int nb_text = snprintf(text, 10, "%.0fC (%d)", spot->temp, spot->count);
157
159 &status, &radius, 1, &spot->lat, 1, &spot->lon, nb_text, text);
160}
161
162
171
static uint8_t status
struct pprz_transport extra_pprz_tp
Extra datalink and telemetry using PPRZ protocol.
uint16_t foo
Definition main_demo5.c:58
uint16_t val[TCOUPLE_NB]
int32_t lat
Definition thermal_ctl.c:53
void thermal_ctl_thermal_ctl_handler(float value)
Definition thermal_ctl.c:66
#define NB_SPOTS
Definition thermal_ctl.c:48
static void update_hottests(struct thermal_spot *spot)
void thermal_clusters_cb(uint8_t *buf)
Definition thermal_ctl.c:95
void thermal_ctl_thermal_threshold_handler(float value)
Definition thermal_ctl.c:87
int32_t lon
Definition thermal_ctl.c:54
static void thermal_send_draw(struct thermal_spot *spot)
#define THERMAL_CTL_REC_OFF
Definition thermal_ctl.c:46
uint8_t cluster_idx
Definition thermal_ctl.c:52
struct thermal_spot hottest_spots[3]
Definition thermal_ctl.c:60
float thermal_ctl
Definition thermal_ctl.c:40
#define THERMAL_CTL_REC_ON
Definition thermal_ctl.c:45
#define THERMAL_CTL_PWR_OFF
Definition thermal_ctl.c:44
void thermal_cluster_periodic()
float thermal_threshold
Definition thermal_ctl.c:41
int int32_t
Typedef defining 32 bit int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
float b
Definition wedgebug.c:202