Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
rpm_sensor.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Freek van Tienen <freek.v.tienen@gmail.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  */
27 #include "mcu_periph/pwm_input.h"
28 #include "subsystems/electrical.h"
29 #include "subsystems/abi.h"
31 
32 static struct FirstOrderLowPass rpm_lp;
34 
35 #ifndef RPM_FILTER_TAU
36 #define RPM_FILTER_TAU RPM_SENSOR_PERIODIC_PERIOD
37 #endif
38 
39 
40 #if PERIODIC_TELEMETRY
42 
43 static void rpm_sensor_send_motor(struct transport_tx *trans, struct link_device *dev)
44 {
45  pprz_msg_send_MOTOR(trans, dev, AC_ID, &rpm, &electrical.current);
46 }
47 #endif
48 
49 /* Initialize the RPM measurement by configuring the telemetry */
50 void rpm_sensor_init(void)
51 {
52  rpm = 0;
53  init_first_order_low_pass(&rpm_lp, RPM_FILTER_TAU, RPM_SENSOR_PERIODIC_PERIOD, 0);
54 
55 #if PERIODIC_TELEMETRY
57 #endif
58 }
59 
60 /* RPM periodic */
62 {
64  AbiSendMsgRPM(RPM_SENSOR_ID, &rpm, 1);
65 }
66 
67 /* Get the RPM sensor */
69 {
70  uint16_t rpm_meas = 0;
71  uint32_t period_us = get_pwm_input_period_in_usec(RPM_PWM_CHANNEL) * RPM_PULSE_PER_RND;
72  if (period_us > 0) {
73  rpm_meas = ((uint32_t)1000000 * 60) / period_us;
74  }
75 
76  return rpm_meas;
77 }
int32_t current
current in milliamps
Definition: electrical.h:49
unsigned short uint16_t
Definition: types.h:16
Periodic telemetry system header (includes downlink utility and generated code).
uint32_t get_pwm_input_period_in_usec(uint32_t channel)
Definition: pwm_input.c:44
Simple first order low pass filter with bilinear transform.
arch independent PWM input capture API
Main include for ABI (AirBorneInterface).
First order low pass filter structure.
#define RPM_SENSOR_ID
void rpm_sensor_periodic(void)
Definition: rpm_sensor.c:61
Interface for electrical status: supply voltage, current, battery status, etc.
uint16_t rpm
Definition: rpm_sensor.c:33
unsigned long uint32_t
Definition: types.h:18
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
#define RPM_PULSE_PER_RND
Definition: rpm_sensor.h:33
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define RPM_FILTER_TAU
Definition: rpm_sensor.c:36
void rpm_sensor_init(void)
Definition: rpm_sensor.c:50
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, float sample_time, float value)
Init first order low pass filter.
uint16_t rpm_sensor_get_rpm(void)
Definition: rpm_sensor.c:68
struct Electrical electrical
Definition: electrical.c:65
static void rpm_sensor_send_motor(struct transport_tx *trans, struct link_device *dev)
Definition: rpm_sensor.c:43
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, float value)
Update first order low pass filter state with a new value.
static struct FirstOrderLowPass rpm_lp
Definition: rpm_sensor.c:32