Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
actuators_spektrum.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2015 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, write to
18
* the Free Software Foundation, 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
20
*/
21
27
#include "
subsystems/actuators.h
"
28
#include "
subsystems/actuators/actuators_spektrum.h
"
29
#include "generated/airframe.h"
30
#include "
mcu_periph/uart.h
"
31
32
/* Currently we only support 7 channels, but could be extended to 14+ */
33
#if SERVOS_SPEKTRUM_NB > ACTUATORS_SPEKTRUM_MAX_NB
34
#error Spektrum actuators only support less then 7 servos
35
#endif
36
37
/* Calculate the frequency divider to aim at 11ms (~90Hz) */
38
#if PERIODIC_FREQUENCY < 90
39
#error Spektrum actuators need at leest a frequency of Hz
40
#else
41
static
uint8_t
freq_trig = PERIODIC_FREQUENCY / 90.0 + 0.5;
// Round it to nearest value
42
#endif
43
44
/* Main actuator structure */
45
struct
ActuatorsSpektrum
actuators_spektrum
;
46
static
inline
void
actuators_spektrum_send
(
struct
link_device *
dev
);
47
48
/*
49
* Initialize the spektrum devices (UART output devices)
50
*/
51
void
actuators_spektrum_init
(
void
)
52
{
53
actuators_spektrum
.
device
= &((ACTUATORS_SPEKTRUM_DEV).
device
);
54
55
#ifdef ACTUATORS_SPEKTRUM_DEV2
56
actuators_spektrum
.
device2
= &((ACTUATORS_SPEKTRUM_DEV2).
device
);
57
#endif
58
}
59
60
/*
61
* Transmit the spektrum output at ~90Hz
62
*/
63
void
actuators_spektrum_set
(
void
)
64
{
65
static
uint8_t
cnt = 0;
66
67
// Only send every 11 ms
68
cnt++;
69
if
(cnt == freq_trig) {
70
actuators_spektrum_send
(
actuators_spektrum
.
device
);
71
72
#ifdef ACTUATORS_SPEKTRUM_DEV2
73
actuators_spektrum_send
(
actuators_spektrum
.
device2
);
74
#endif
75
76
cnt = 0;
77
}
78
}
79
80
/*
81
* Actually transmit the spektrum output on a link device
82
*/
83
static
inline
void
actuators_spektrum_send
(
struct
link_device *
dev
)
84
{
85
uint8_t
i = 0;
86
dev
->put_byte(
dev
->periph, 0, 0x00);
// number missed frames
87
dev
->put_byte(
dev
->periph, 0, 0
x12
);
// 7 channels, 11 bit, 11ms
88
89
/* Transmit all channels */
90
for
(i = 0; i <
ACTUATORS_SPEKTRUM_MAX_NB
; i++) {
91
dev
->put_byte(
dev
->periph, 0, i << 3 |
actuators_spektrum
.
cmds
[i] >> 8);
92
dev
->put_byte(
dev
->periph, 0,
actuators_spektrum
.
cmds
[i] & 0xFF);
93
}
94
}
actuators_spektrum
struct ActuatorsSpektrum actuators_spektrum
Definition:
actuators_spektrum.c:45
ActuatorsSpektrum::cmds
int32_t cmds[ACTUATORS_SPEKTRUM_MAX_NB]
Definition:
actuators_spektrum.h:37
actuators_spektrum_set
void actuators_spektrum_set(void)
Definition:
actuators_spektrum.c:63
ActuatorsSpektrum::device
struct link_device * device
Definition:
actuators_spektrum.h:38
actuators_spektrum_init
void actuators_spektrum_init(void)
Definition:
actuators_spektrum.c:51
ActuatorsSpektrum::device2
struct link_device * device2
Definition:
actuators_spektrum.h:39
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
x12
@ x12
Definition:
discrete_ekf_no_north.c:34
dev
static const struct usb_device_descriptor dev
Definition:
usb_ser_hw.c:74
uint8_t
unsigned char uint8_t
Definition:
types.h:14
ActuatorsSpektrum
Definition:
actuators_spektrum.h:36
ACTUATORS_SPEKTRUM_MAX_NB
#define ACTUATORS_SPEKTRUM_MAX_NB
Definition:
actuators_spektrum.h:33
actuators_spektrum.h
actuators_spektrum_send
static void actuators_spektrum_send(struct link_device *dev)
Definition:
actuators_spektrum.c:83
actuators.h
sw
airborne
subsystems
actuators
actuators_spektrum.c
Generated on Tue Feb 1 2022 13:51:17 for Paparazzi UAS by
1.8.17