Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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 */
25
29#include "modules/core/abi.h"
31
34
35#ifndef RPM_FILTER_TAU
36#define RPM_FILTER_TAU RPM_SENSOR_PERIODIC_PERIOD
37#endif
38
39#ifndef RPM_SENSOR_ACTUATOR_IDX
40#error "You need to define an actuator for which the RPM is read, please define RPM_SENSOR_ACTUATOR_IDX"
41#endif
42
43
44#if PERIODIC_TELEMETRY
46
47static void rpm_sensor_send_motor(struct transport_tx *trans, struct link_device *dev)
48{
49 pprz_msg_send_MOTOR(trans, dev, AC_ID, &rpm, &electrical.current);
50}
51#endif
52
53/* Initialize the RPM measurement by configuring the telemetry */
55{
56 rpm = 0;
57 init_first_order_low_pass(&rpm_lp, RPM_FILTER_TAU, RPM_SENSOR_PERIODIC_PERIOD, 0);
58
59#if PERIODIC_TELEMETRY
61#endif
62}
63
64/* RPM periodic */
66{
67 struct act_feedback_t feedback = {0};
68 feedback.idx = RPM_SENSOR_ACTUATOR_IDX;
70 feedback.set.rpm = true;
71 AbiSendMsgACT_FEEDBACK(ACT_FEEDBACK_RPM_SENSOR_ID, &feedback, 1);
72}
73
74/* Get the RPM sensor */
76{
77 uint16_t rpm_meas = 0;
78 uint32_t period_us = get_pwm_input_period_in_usec(RPM_PWM_CHANNEL) * RPM_PULSE_PER_RND;
79 if (period_us > 0) {
80 rpm_meas = ((uint32_t)1000000 * 60) / period_us;
81 }
82
83 return rpm_meas;
84}
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_RPM_SENSOR_ID
static struct uart_periph * dev
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
Simple first order low pass filter with bilinear transform.
static void init_first_order_low_pass(struct FirstOrderLowPass *filter, float tau, const float sample_time, float value)
Init first order low pass filter.
static float update_first_order_low_pass(struct FirstOrderLowPass *filter, const float value)
Update first order low pass filter state with a new value.
First order low pass filter structure.
int32_t rpm
RPM.
Definition actuators.h:54
struct act_feedback_t::act_feedback_set_t set
Bitset registering what is set as feedback.
uint8_t idx
General index of the actuators (generated in airframe.h).
Definition actuators.h:45
uint32_t get_pwm_input_period_in_usec(uint32_t channel)
Definition pwm_input.c:44
arch independent PWM input capture API
static struct FirstOrderLowPass rpm_lp
Definition rpm_sensor.c:32
static void rpm_sensor_send_motor(struct transport_tx *trans, struct link_device *dev)
Definition rpm_sensor.c:47
void rpm_sensor_periodic(void)
Definition rpm_sensor.c:65
uint16_t rpm
Definition rpm_sensor.c:33
uint16_t rpm_sensor_get_rpm(void)
Definition rpm_sensor.c:75
#define RPM_FILTER_TAU
Definition rpm_sensor.c:36
void rpm_sensor_init(void)
Definition rpm_sensor.c:54
#define RPM_PULSE_PER_RND
Definition rpm_sensor.h:33
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.