Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
actuators_dshot_arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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
30#include "modules/core/abi.h"
31#include "mcu_periph/ram_arch.h"
32#include "mcu_periph/gpio.h"
33#include BOARD_CONFIG
34
35#if PERIODIC_TELEMETRY
38#endif
39
44
47
48#if DSHOT_CONF_TIM1
49static DSHOTDriver DSHOTD1;
51#if DSHOT_BIDIR
53#endif
55#endif
56#if DSHOT_CONF_TIM2
57static DSHOTDriver DSHOTD2;
59#if DSHOT_BIDIR
61#endif
63#endif
64#if DSHOT_CONF_TIM3
65static DSHOTDriver DSHOTD3;
67#if DSHOT_BIDIR
69#endif
71#endif
72#if DSHOT_CONF_TIM4
73static DSHOTDriver DSHOTD4;
75#if DSHOT_BIDIR
77#endif
79#endif
80#if DSHOT_CONF_TIM5
81static DSHOTDriver DSHOTD5;
83#if DSHOT_BIDIR
85#endif
87#endif
88#if DSHOT_CONF_TIM8
89static DSHOTDriver DSHOTD8;
91#if DSHOT_BIDIR
93#endif
95#endif
96#if DSHOT_CONF_TIM9
97static DSHOTDriver DSHOTD9;
99#if DSHOT_BIDIR
101#endif
103#endif
104
105#if PERIODIC_TELEMETRY
106static void esc_msg_send(struct transport_tx *trans, struct link_device *dev) {
107 for (uint8_t i = 0; i < ACTUATORS_DSHOT_NB; i++) {
108 if (actuators_dshot_values[i].activated) {
110
111 actuators_dshot_values[i].current = (float)dtelem.frame.current * 0.01f;
112 actuators_dshot_values[i].voltage = (float)dtelem.frame.voltage * 0.01f;
113 actuators_dshot_values[i].rpm = (float)dtelem.frame.rpm;
114
115#if DSHOT_BIDIR
119 }
120#endif
121
123 float power = actuators_dshot_values[i].current * bat_voltage;
124 float energy = (float)dtelem.frame.consumption;
125 float temp = dtelem.frame.temp;
126 float temp_dev = 0;
128 &actuators_dshot_values[i].current,
130 &power,
132 &actuators_dshot_values[i].voltage,
133 &energy,
134 &temp,
135 &temp_dev,
136 &i,
137 &i);
138 }
139 }
140}
141#endif
142
143static void dshot_init_struct(struct dshot * ds)
144{
145 ds->cmd = 0;
146 ds->rpm = 0;
147 ds->current = 0;
148 ds->voltage = 0;
149 ds->activated = false;
150}
151
153{
154 ds->activated = true;
155 dsp->driver = driver;
156 dsp->channel = channel;
157}
158
159#define _CONCAT_GPIO(num, name) UART ## num ## _GPIO_ ## name
160#define CONCAT_GPIO(num, name) _CONCAT_GPIO(num, name)
161
163{
164 // init dshot structure to zero
165 for (int i = 0; i < ACTUATORS_DSHOT_NB; i++) {
167 }
168
169 // configure telemetry pin if needed
170 // the serial device interface might have to be activated
171 // by hand (ChibiOS HAL), but PPRZ one disabled
172#ifdef DSHOT_TIM1_TELEMETRY_NUM
178#endif
179#ifdef DSHOT_TIM2_TELEMETRY_NUM
184#endif
185#ifdef DSHOT_TIM3_TELEMETRY_NUM
190#endif
191#ifdef DSHOT_TIM4_TELEMETRY_NUM
197#endif
198#ifdef DSHOT_TIM5_TELEMETRY_NUM
203#endif
204#ifdef DSHOT_TIM8_TELEMETRY_NUM
209#endif
210#ifdef DSHOT_TIM9_TELEMETRY_NUM
215#endif
216
217 /*----------------
218 * Configure GPIO
219 *----------------*/
220#ifdef DSHOT_SERVO_0
223#endif
224#ifdef DSHOT_SERVO_1
227#endif
228#ifdef DSHOT_SERVO_2
231#endif
232#ifdef DSHOT_SERVO_3
235#endif
236#ifdef DSHOT_SERVO_4
239#endif
240#ifdef DSHOT_SERVO_5
243#endif
244#ifdef DSHOT_SERVO_6
247#endif
248#ifdef DSHOT_SERVO_7
251#endif
252#ifdef DSHOT_SERVO_8
255#endif
256#ifdef DSHOT_SERVO_9
259#endif
260#ifdef DSHOT_SERVO_10
263#endif
264#ifdef DSHOT_SERVO_11
267#endif
268
269 /*---------------
270 * Configure DSHOT
271 *---------------*/
272#if DSHOT_CONF_TIM1
274#endif
275#if DSHOT_CONF_TIM2
277#endif
278#if DSHOT_CONF_TIM3
280#endif
281#if DSHOT_CONF_TIM4
283#endif
284#if DSHOT_CONF_TIM5
286#endif
287#if DSHOT_CONF_TIM8
289#endif
290#if DSHOT_CONF_TIM9
292#endif
293
294#if PERIODIC_TELEMETRY
296#endif
297}
298
299
301{
302#ifdef DSHOT_SERVO_0
304#endif
305#ifdef DSHOT_SERVO_1
307#endif
308#ifdef DSHOT_SERVO_2
310#endif
311#ifdef DSHOT_SERVO_3
313#endif
314#ifdef DSHOT_SERVO_4
316#endif
317#ifdef DSHOT_SERVO_5
319#endif
320#ifdef DSHOT_SERVO_6
322#endif
323#ifdef DSHOT_SERVO_7
325#endif
326#ifdef DSHOT_SERVO_8
328#endif
329#ifdef DSHOT_SERVO_9
331#endif
332#ifdef DSHOT_SERVO_10
334#endif
335#ifdef DSHOT_SERVO_11
337#endif
338
339#if DSHOT_CONF_TIM1
341#endif
342#if DSHOT_CONF_TIM2
344#endif
345#if DSHOT_CONF_TIM3
347#endif
348#if DSHOT_CONF_TIM4
350#endif
351#if DSHOT_CONF_TIM5
353#endif
354#if DSHOT_CONF_TIM8
356#endif
357#if DSHOT_CONF_TIM9
359#endif
360
361
362 struct act_feedback_t feedback[ACTUATORS_DSHOT_NB] = { 0 };
363 for (uint8_t i = 0; i < ACTUATORS_DSHOT_NB; i++) {
364 feedback[i].idx = get_servo_idx_DSHOT(i);
365 if (actuators_dshot_values[i].activated) {
367 feedback[i].rpm = dtelem.frame.rpm;
368 feedback[i].set.rpm = true;
369#if DSHOT_BIDIR
373 feedback[i].rpm = (float) erpm;
374 feedback[i].set.rpm = true;
375 }
376 } else {
377 feedback[i].set.rpm = false;
378 }
379#endif
380 }
381 }
383}
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_DSHOT_ID
float current
current
float voltage
motor current
#define ACTUATORS_DSHOT_NB
Maxnum number of DSHOT commands This should be large enough for max applications: 8 motors +1 in case...
float rpm
rpm
void gpio_setup_pin_af_pullup(ioportid_t port, uint16_t pin, uint8_t af)
Setup a gpio for input pullup with alternate function.
Definition gpio_arch.c:61
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
Definition gpio_arch.c:65
void actuators_dshot_arch_init(void)
Arch dependent init.
struct dshot_private actuators_dshot_private[ACTUATORS_DSHOT_NB]
#define CONCAT_GPIO(num, name)
static void dshot_set_struct(struct dshot *ds, struct dshot_private *dsp, DSHOTDriver *driver, uint32_t channel)
struct dshot actuators_dshot_values[ACTUATORS_DSHOT_NB]
static void dshot_init_struct(struct dshot *ds)
static void esc_msg_send(struct transport_tx *trans, struct link_device *dev)
void actuators_dshot_arch_commit(void)
DSHOTDriver * driver
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
float vsupply
supply voltage in V
Definition electrical.h:45
void dshotStart(DSHOTDriver *driver, const DSHOTConfig *config)
Configures and activates the DSHOT peripheral.
Definition esc_dshot.c:154
void dshotSetThrottle(DSHOTDriver *driver, const uint8_t index, const uint16_t throttle)
prepare throttle order for specified ESC
Definition esc_dshot.c:301
DshotTelemetry dshotGetTelemetry(DSHOTDriver *driver, uint32_t index)
return last received telemetry data
Definition esc_dshot.c:468
void dshotSendFrame(DSHOTDriver *driver)
send throttle order
Definition esc_dshot.c:404
DSHOT driver based on ChibiOS.
#define DSHOT_BIDIR_TLM_EDT
Definition esc_dshot.h:66
#define DSHOT_BIDIR_ERR_CRC
special values returned by dshotGetRpm function
Definition esc_dshot.h:65
DSHOT Driver configuration structure.
Definition esc_dshot.h:182
telemetry with timestamp
Definition esc_dshot.h:158
Some architecture independent helper functions for GPIOs.
uint16_t foo
Definition main_demo5.c:58
int32_t rpm
RPM.
Definition actuators.h:51
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
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Specific RAM section for DMA usage on F7.
#define IN_DMA_SECTION_NOINIT(var)
Definition ram_arch.h:85
uint16_t rpm
Definition rpm_sensor.c:33
#define FALSE
Definition std.h:5
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
DSHOT driver structure.
Definition esc_dshot.h:287
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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 int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.