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
40// Default number of poles in a motor
41// Used to convert electrical RPM to physical RPM
42// by dividing eRPM by (MOTOR_POLES/2)
43#ifndef DSHOT_MOTOR_POLES
44#define DSHOT_MOTOR_POLES 14
45#endif
46
51
53
54#if DSHOT_CONF_TIM1
55static DSHOTDriver DSHOTD1;
57#if DSHOT_BIDIR
59#endif
61#endif
62#if DSHOT_CONF_TIM2
63static DSHOTDriver DSHOTD2;
65#if DSHOT_BIDIR
67#endif
69#endif
70#if DSHOT_CONF_TIM3
71static DSHOTDriver DSHOTD3;
73#if DSHOT_BIDIR
75#endif
77#endif
78#if DSHOT_CONF_TIM4
79static DSHOTDriver DSHOTD4;
81#if DSHOT_BIDIR
83#endif
85#endif
86#if DSHOT_CONF_TIM5
87static DSHOTDriver DSHOTD5;
89#if DSHOT_BIDIR
91#endif
93#endif
94#if DSHOT_CONF_TIM8
95static DSHOTDriver DSHOTD8;
97#if DSHOT_BIDIR
99#endif
101#endif
102#if DSHOT_CONF_TIM9
103static DSHOTDriver DSHOTD9;
105#if DSHOT_BIDIR
107#endif
109#endif
110
111#if PERIODIC_TELEMETRY
112static void esc_msg_send(struct transport_tx *trans, struct link_device *dev) {
113 for (uint8_t i = 0; i < ACTUATORS_DSHOT_NB; i++) {
114 if (actuators_dshot_values[i].activated) {
116 float power = actuators_dshot_values[i].current * bat_voltage;
117 float temp_dev = 0;
119 &actuators_dshot_values[i].current,
121 &power,
123 &actuators_dshot_values[i].voltage,
124 &actuators_dshot_values[i].energy,
125 &actuators_dshot_values[i].temp,
126 &temp_dev,
127 &i,
128 &i);
129 }
130 }
131}
132#endif
133
134static void dshot_init_struct(struct dshot * ds)
135{
136 ds->cmd = 0;
137 ds->rpm = 0;
138 ds->current = 0;
139 ds->voltage = 0;
140 ds->activated = false;
141}
142
144{
145 ds->activated = true;
146 dsp->driver = driver;
147 dsp->channel = channel;
148}
149
150#define _CONCAT_GPIO(num, name) UART ## num ## _GPIO_ ## name
151#define CONCAT_GPIO(num, name) _CONCAT_GPIO(num, name)
152
154{
155 // init dshot structure to zero
156 for (int i = 0; i < ACTUATORS_DSHOT_NB; i++) {
158 }
159
160 // configure telemetry pin if needed
161 // the serial device interface might have to be activated
162 // by hand (ChibiOS HAL), but PPRZ one disabled
163#ifdef DSHOT_TIM1_TELEMETRY_NUM
169#endif
170#ifdef DSHOT_TIM2_TELEMETRY_NUM
175#endif
176#ifdef DSHOT_TIM3_TELEMETRY_NUM
181#endif
182#ifdef DSHOT_TIM4_TELEMETRY_NUM
188#endif
189#ifdef DSHOT_TIM5_TELEMETRY_NUM
194#endif
195#ifdef DSHOT_TIM8_TELEMETRY_NUM
200#endif
201#ifdef DSHOT_TIM9_TELEMETRY_NUM
206#endif
207
208 /*----------------
209 * Configure GPIO
210 *----------------*/
211#ifdef DSHOT_SERVO_0
214#endif
215#ifdef DSHOT_SERVO_1
218#endif
219#ifdef DSHOT_SERVO_2
222#endif
223#ifdef DSHOT_SERVO_3
226#endif
227#ifdef DSHOT_SERVO_4
230#endif
231#ifdef DSHOT_SERVO_5
234#endif
235#ifdef DSHOT_SERVO_6
238#endif
239#ifdef DSHOT_SERVO_7
242#endif
243#ifdef DSHOT_SERVO_8
246#endif
247#ifdef DSHOT_SERVO_9
250#endif
251#ifdef DSHOT_SERVO_10
254#endif
255#ifdef DSHOT_SERVO_11
258#endif
259
260 /*---------------
261 * Configure DSHOT
262 *---------------*/
263#if DSHOT_CONF_TIM1
265#endif
266#if DSHOT_CONF_TIM2
268#endif
269#if DSHOT_CONF_TIM3
271#endif
272#if DSHOT_CONF_TIM4
274#endif
275#if DSHOT_CONF_TIM5
277#endif
278#if DSHOT_CONF_TIM8
280#endif
281#if DSHOT_CONF_TIM9
283#endif
284
285#if PERIODIC_TELEMETRY
287#endif
288}
289
290
292{
293#ifdef DSHOT_SERVO_0
295#endif
296#ifdef DSHOT_SERVO_1
298#endif
299#ifdef DSHOT_SERVO_2
301#endif
302#ifdef DSHOT_SERVO_3
304#endif
305#ifdef DSHOT_SERVO_4
307#endif
308#ifdef DSHOT_SERVO_5
310#endif
311#ifdef DSHOT_SERVO_6
313#endif
314#ifdef DSHOT_SERVO_7
316#endif
317#ifdef DSHOT_SERVO_8
319#endif
320#ifdef DSHOT_SERVO_9
322#endif
323#ifdef DSHOT_SERVO_10
325#endif
326#ifdef DSHOT_SERVO_11
328#endif
329
330#if DSHOT_CONF_TIM1
332#endif
333#if DSHOT_CONF_TIM2
335#endif
336#if DSHOT_CONF_TIM3
338#endif
339#if DSHOT_CONF_TIM4
341#endif
342#if DSHOT_CONF_TIM5
344#endif
345#if DSHOT_CONF_TIM8
347#endif
348#if DSHOT_CONF_TIM9
350#endif
351
352 // update public structure with latest telemetry data
353 // and send actuator feedback message
354 struct act_feedback_t feedback[ACTUATORS_DSHOT_NB] = { 0 };
355 for (uint8_t i = 0; i < ACTUATORS_DSHOT_NB; i++) {
356 feedback[i].idx = get_servo_idx_DSHOT(i);
357 if (actuators_dshot_values[i].activated) {
359 // RPM in telemetry is electrical RMP with a scale of 100,
360 // so physical value is 2 * 100 / motor_poles
361 const int32_t rpm = dtelem.frame.rpm * 200 / DSHOT_MOTOR_POLES;
362 feedback[i].rpm = rpm;
363 feedback[i].set.rpm = true;
365 actuators_dshot_values[i].current = (float)dtelem.frame.current * 0.01f;
366 actuators_dshot_values[i].voltage = (float)dtelem.frame.voltage * 0.01f;
367 actuators_dshot_values[i].energy = (float)dtelem.frame.consumption;
368 actuators_dshot_values[i].temp = (float)dtelem.frame.temp;
369#if DSHOT_BIDIR
370 // overwrite RPM if DSHOT_BIDIR is used as it provides faster update
373 feedback[i].rpm = erpm * 2 / DSHOT_MOTOR_POLES;
374 feedback[i].set.rpm = true;
375 actuators_dshot_values[i].rpm = (float)feedback[i].rpm;
376 } else {
377 feedback[i].set.rpm = false;
378 }
379#endif
380 }
381 }
383}
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_DSHOT_ID
struct dshot actuators_dshot_values[ACTUATORS_DSHOT_NB]
float current
current
float temp
temperature
float voltage
motor current
float energy
energy (from dshot telemetry)
#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 DSHOT_MOTOR_POLES
#define CONCAT_GPIO(num, name)
static void dshot_set_struct(struct dshot *ds, struct dshot_private *dsp, DSHOTDriver *driver, uint32_t channel)
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
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
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.