Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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;
33 
34 #ifndef RPM_FILTER_TAU
35 #define RPM_FILTER_TAU RPM_SENSOR_PERIODIC_PERIOD
36 #endif
37 
38 
39 #if PERIODIC_TELEMETRY
41 
42 static void rpm_sensor_send_motor(struct transport_tx *trans, struct link_device *dev)
43 {
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  init_first_order_low_pass(&rpm_lp, RPM_FILTER_TAU, RPM_SENSOR_PERIODIC_PERIOD, 0);
53 
54 #if PERIODIC_TELEMETRY
56 #endif
57 }
58 
59 /* RPM periodic */
61 {
63  AbiSendMsgRPM(RPM_SENSOR_ID, rpm);
64 }
65 
66 /* Get the RPM sensor */
68 {
69  uint16_t rpm = 0;
70  uint32_t period_us = get_pwm_input_period_in_usec(RPM_PWM_CHANNEL) * RPM_PULSE_PER_RND;
71  if (period_us > 0) {
72  rpm = ((uint32_t)1000000 * 60) / period_us;
73  }
74 
75  return rpm;
76 }
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).
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:60
Interface for electrical status: supply voltage, current, battery status, etc.
unsigned long uint32_t
Definition: types.h:18
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
static float get_first_order_low_pass(struct FirstOrderLowPass *filter)
Get current value of the first order low pass filter.
#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:35
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:67
struct Electrical electrical
Definition: electrical.c:65
uint32_t get_pwm_input_period_in_usec(uint32_t channel)
static void rpm_sensor_send_motor(struct transport_tx *trans, struct link_device *dev)
Definition: rpm_sensor.c:42
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