mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-22 12:28:03 +08:00
[actuators] Spektrum output actuators
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
|
||||
# Actuator drivers for spektrum output
|
||||
|
||||
ACTUATORS_SPEKTRUM_DEV ?= UART4
|
||||
ACTUATORS_SPEKTRUM_DEV_UPPER =$(shell echo $(ACTUATORS_SPEKTRUM_DEV) | tr a-z A-Z)
|
||||
ACTUATORS_SPEKTRUM_DEV_LOWER =$(shell echo $(ACTUATORS_SPEKTRUM_DEV) | tr A-Z a-z)
|
||||
|
||||
ACTUATORS_SPEKTRUM_CFLAGS = -DACTUATORS_SPEKTRUM_DEV=$(ACTUATORS_SPEKTRUM_DEV_LOWER) -DUSE_$(ACTUATORS_SPEKTRUM_DEV_UPPER)
|
||||
ACTUATORS_SPEKTRUM_CFLAGS += -D$(ACTUATORS_SPEKTRUM_DEV_UPPER)_BAUD=115200 -DUSE_$(ACTUATORS_SPEKTRUM_DEV_UPPER)_RX=FALSE
|
||||
|
||||
ifdef ACTUATORS_SPEKTRUM_DEV2
|
||||
ACTUATORS_SPEKTRUM_DEV2_UPPER =$(shell echo $(ACTUATORS_SPEKTRUM_DEV2) | tr a-z A-Z)
|
||||
ACTUATORS_SPEKTRUM_DEV2_LOWER =$(shell echo $(ACTUATORS_SPEKTRUM_DEV2) | tr A-Z a-z)
|
||||
ACTUATORS_SPEKTRUM_CFLAGS += -DACTUATORS_SPEKTRUM_DEV2=$(ACTUATORS_SPEKTRUM_DEV2_LOWER) -DUSE_$(ACTUATORS_SPEKTRUM_DEV2_UPPER)
|
||||
ACTUATORS_SPEKTRUM_CFLAGS += -D$(ACTUATORS_SPEKTRUM_DEV2_UPPER)_BAUD=115200 -DUSE_$(ACTUATORS_SPEKTRUM_DEV2_UPPER)_RX=FALSE
|
||||
endif
|
||||
|
||||
ap.CFLAGS += -DACTUATORS $(ACTUATORS_SPEKTRUM_CFLAGS)
|
||||
ap.srcs += subsystems/actuators/actuators_spektrum.c
|
||||
@@ -218,6 +218,9 @@ STATIC_INLINE void main_init(void)
|
||||
// send body_to_imu from here for now
|
||||
AbiSendMsgBODY_TO_IMU_QUAT(1, orientationGetQuat_f(&imu.body_to_imu));
|
||||
#endif
|
||||
|
||||
// Do a failsafe check first
|
||||
failsafe_check();
|
||||
}
|
||||
|
||||
STATIC_INLINE void handle_periodic_tasks(void)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/** @file actuators_spektrum.c
|
||||
* Spektrum actuator driver, which can output as 7 spektrum channels at ~11ms.
|
||||
* Channels min, averga and maximum should be: 340, 1024, 1708
|
||||
*/
|
||||
|
||||
#include "subsystems/actuators.h"
|
||||
#include "subsystems/actuators/actuators_spektrum.h"
|
||||
#include "generated/airframe.h"
|
||||
#include "mcu_periph/uart.h"
|
||||
|
||||
/* Currently we only support 7 channels, but could be extended to 14+ */
|
||||
#if SERVOS_SPEKTRUM_NB > ACTUATORS_SPEKTRUM_MAX_NB
|
||||
#error Spektrum actuators only support less then 7 servos
|
||||
#endif
|
||||
|
||||
/* Calculate the frequency divider to aim at 11ms (~90Hz) */
|
||||
#if PERIODIC_FREQUENCY < 90
|
||||
#error Spektrum actuators need at leest a frequency of Hz
|
||||
#else
|
||||
static uint8_t freq_trig = PERIODIC_FREQUENCY / 90.0 + 0.5; // Round it to nearest value
|
||||
|
||||
/* Main actuator structure */
|
||||
struct ActuatorsSpektrum actuators_spektrum;
|
||||
static inline void actuators_spektrum_send(struct link_device *dev);
|
||||
|
||||
/*
|
||||
* Initialize the spektrum devices (UART output devices)
|
||||
*/
|
||||
void actuators_spektrum_init(void)
|
||||
{
|
||||
actuators_spektrum.device = &((ACTUATORS_SPEKTRUM_DEV).device);
|
||||
|
||||
#ifdef ACTUATORS_SPEKTRUM_DEV2
|
||||
actuators_spektrum.device2 = &((ACTUATORS_SPEKTRUM_DEV2).device);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Transmit the spektrum output at ~90Hz
|
||||
*/
|
||||
void actuators_spektrum_set(void)
|
||||
{
|
||||
static uint8_t cnt = 0;
|
||||
|
||||
// Only send every 11 ms
|
||||
cnt++;
|
||||
if (cnt == freq_trig) {
|
||||
actuators_spektrum_send(actuators_spektrum.device);
|
||||
|
||||
#ifdef ACTUATORS_SPEKTRUM_DEV2
|
||||
actuators_spektrum_send(actuators_spektrum.device2);
|
||||
#endif
|
||||
|
||||
cnt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Actually transmit the spektrum output on a link device
|
||||
*/
|
||||
static inline void actuators_spektrum_send(struct link_device *dev)
|
||||
{
|
||||
dev->put_byte(dev->periph, 0x00); // number missed frames
|
||||
dev->put_byte(dev->periph, 0x12); // 7 channels, 11 bit, 11ms
|
||||
|
||||
/* Transmit all channels */
|
||||
for (i = 0; i < ACTUATORS_SPEKTRUM_MAX_NB; i++) {
|
||||
dev->put_byte(dev->periph, i << 3 | actuators_spektrum.cmds[i] >> 8);
|
||||
dev->put_byte(dev->periph, actuators_spektrum.cmds[i] & 0xFF);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
|
||||
*
|
||||
* This file is part of paparazzi.
|
||||
*
|
||||
* paparazzi is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* paparazzi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with paparazzi; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/** @file actuators_spektrum.h
|
||||
* Spektrum actuator driver, which can output as 7 spektrum channels at ~11ms.
|
||||
* Channels min, averga and maximum should be: 340, 1024, 1708
|
||||
*/
|
||||
|
||||
#ifndef ACTUATORS_SPEKTRUM_H
|
||||
#define ACTUATORS_SPEKTRUM_H
|
||||
|
||||
#include "std.h"
|
||||
|
||||
/* Maximum amount of spektrum actuator channels */
|
||||
#define ACTUATORS_SPEKTRUM_MAX_NB 7
|
||||
|
||||
/* Main actuator structure */
|
||||
struct ActuatorsSpektrum {
|
||||
int32_t cmds[ACTUATORS_SPEKTRUM_MAX_NB];
|
||||
struct link_device *device;
|
||||
struct link_device *device2;
|
||||
};
|
||||
|
||||
/* Functions used in actuator macros */
|
||||
extern struct ActuatorsSpektrum actuators_spektrum;
|
||||
extern void actuators_spektrum_init(void);
|
||||
extern void actuators_spektrum_set(void);
|
||||
|
||||
/* Actuator macros */
|
||||
#define ActuatorSpektrumSet(_i, _v) { actuators_spektrum.cmds[_i] = _v; }
|
||||
#define ActuatorsSpektrumInit() actuators_spektrum_init()
|
||||
#define ActuatorsSpektrumCommit() actuators_spektrum_set()
|
||||
|
||||
|
||||
#endif /* ACTUATORS_SPEKTRUM_H */
|
||||
Reference in New Issue
Block a user