mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-01 04:46:51 +08:00
added hott sumd radio control input (#2030)
Added Graupner HOTT SUMD serial rc control protocol. I used the sbus implementation as base for the hott sumd input. Tested with lisa m 2.0 uart1 and Graupner GR-12L with 9 and 12 channels. Should work with 2 to 32 channels. and example airframe config.
This commit is contained in:
committed by
Felix Ruess
parent
1a4cf57b0c
commit
ae8141490d
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
|
||||
*
|
||||
* 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 subsystems/radio_control/hott.c
|
||||
*
|
||||
* Single HOTT radio_control SUMD
|
||||
*/
|
||||
|
||||
#include "subsystems/radio_control.h"
|
||||
#include "subsystems/radio_control/hott.h"
|
||||
#include BOARD_CONFIG
|
||||
|
||||
|
||||
/** HOTT struct */
|
||||
struct SHott hott;
|
||||
|
||||
// Telemetry function
|
||||
#if PERIODIC_TELEMETRY
|
||||
#include "subsystems/datalink/telemetry.h"
|
||||
|
||||
static void send_hott(struct transport_tx *trans, struct link_device *dev)
|
||||
{
|
||||
// Using PPM message
|
||||
pprz_msg_send_PPM(trans, dev, AC_ID,
|
||||
&radio_control.frame_rate, HOTT_NB_CHANNEL, hott.ppm);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Init function
|
||||
void radio_control_impl_init(void)
|
||||
{
|
||||
hott_common_init(&hott, &HOTT_UART_DEV);
|
||||
|
||||
// Register telemetry message
|
||||
#if PERIODIC_TELEMETRY
|
||||
register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_PPM, send_hott);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Decoding event function
|
||||
// Reading from UART
|
||||
static inline void hott_decode_event(void)
|
||||
{
|
||||
hott_common_decode_event(&hott, &HOTT_UART_DEV);
|
||||
}
|
||||
|
||||
void radio_control_impl_event(void (* _received_frame_handler)(void))
|
||||
{
|
||||
hott_decode_event();
|
||||
if (hott.frame_available) {
|
||||
radio_control.frame_cpt++;
|
||||
radio_control.time_since_last_frame = 0;
|
||||
if (radio_control.radio_ok_cpt > 0) {
|
||||
radio_control.radio_ok_cpt--;
|
||||
} else {
|
||||
radio_control.status = RC_OK;
|
||||
NormalizePpmIIR(hott.pulses, radio_control);
|
||||
_received_frame_handler();
|
||||
}
|
||||
hott.frame_available = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
|
||||
*
|
||||
* 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, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file subsystems/radio_control/hott.h
|
||||
*
|
||||
* Radio control via single HOTT receiver in SUMD mode.
|
||||
*/
|
||||
|
||||
#ifndef RC_HOTT_H
|
||||
#define RC_HOTT_H
|
||||
|
||||
#include "subsystems/radio_control/hott_common.h"
|
||||
|
||||
extern struct SHott hott;
|
||||
|
||||
#endif /* RC_HOTT_H */
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
|
||||
*
|
||||
* 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, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file subsystems/radio_control/hott_common.c
|
||||
*
|
||||
* Graupner HOTT SUMD decoder
|
||||
*/
|
||||
|
||||
#include "subsystems/radio_control.h"
|
||||
#include "subsystems/radio_control/hott_common.h"
|
||||
#include BOARD_CONFIG
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* HOTT protocol and state machine status
|
||||
*/
|
||||
#define HOTT_START_BYTE 0xa8
|
||||
|
||||
#define HOTT_STATUS_UNINIT 0
|
||||
#define HOTT_STATUS_GOT_START 1
|
||||
#define HOTT_STATUS_GOT_HEADER1 2
|
||||
#define HOTT_STATUS_DATA 3
|
||||
|
||||
|
||||
void hott_common_init(struct SHott *hott_p, struct uart_periph *dev)
|
||||
{
|
||||
hott_p->frame_available = false;
|
||||
hott_p->status = HOTT_STATUS_UNINIT;
|
||||
// Set UART parameters (115200, 8 bits, 1 stops, UPARITY_NO)
|
||||
uart_periph_set_baudrate(dev, B115200);
|
||||
uart_periph_set_bits_stop_parity(dev, UBITS_8, USTOP_1, UPARITY_NO);
|
||||
}
|
||||
|
||||
#define HOTT_CRC_POLYNOME 0x1021
|
||||
/******************************************
|
||||
*************************************
|
||||
* Function Name : CRC16
|
||||
* Description : crc calculation, adds a 8 bit unsigned to 16 bit crc
|
||||
*******************************************************************************/
|
||||
static uint16_t hott_CRC16(uint16_t crc, uint8_t value)
|
||||
{
|
||||
uint8_t i;
|
||||
crc = crc ^ (int16_t)value<<8;
|
||||
for(i=0; i<8; i++) {
|
||||
if (crc & 0x8000)
|
||||
crc = (crc << 1) ^ HOTT_CRC_POLYNOME;
|
||||
else
|
||||
crc = (crc << 1);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/** Decode the raw buffer */
|
||||
static void decode_hott_buffer(const uint8_t *src, uint16_t *dst, uint8_t channels, bool *available, uint16_t *dstppm __attribute__((unused)))
|
||||
{
|
||||
// decode hott data
|
||||
uint8_t i;
|
||||
uint16_t sumd_crc_rx, sumd_crc=0;
|
||||
sumd_crc = hott_CRC16(sumd_crc, src[0]);
|
||||
sumd_crc = hott_CRC16(sumd_crc, src[1]);
|
||||
sumd_crc = hott_CRC16(sumd_crc, src[2]);
|
||||
for(i=0;i<channels;i++) {
|
||||
sumd_crc = hott_CRC16(sumd_crc, src[i*2+3]);
|
||||
sumd_crc = hott_CRC16(sumd_crc, src[i*2+4]);
|
||||
dst[i] = (uint16_t)src[i*2 + 3]<<8 | (uint16_t)src[i*2+4];
|
||||
}
|
||||
sumd_crc_rx = (uint16_t)src[channels*2 +3]<<8 | (uint16_t)src[channels*2+4];
|
||||
// convert hott to ppm
|
||||
#if PERIODIC_TELEMETRY
|
||||
for (int channel = 0; channel < HOTT_NB_CHANNEL; channel++) {
|
||||
dstppm[channel] = USEC_OF_RC_PPM_TICKS(dst[channel]);
|
||||
}
|
||||
#endif
|
||||
// test crc
|
||||
*available = (sumd_crc == sumd_crc_rx);
|
||||
}
|
||||
|
||||
|
||||
// Decoding event function
|
||||
// Reading from UART
|
||||
void hott_common_decode_event(struct SHott *hott_p, struct uart_periph *dev)
|
||||
{
|
||||
uint8_t rbyte;
|
||||
if (uart_char_available(dev)) {
|
||||
do {
|
||||
rbyte = uart_getch(dev);
|
||||
switch (hott_p->status) {
|
||||
case HOTT_STATUS_UNINIT:
|
||||
// Wait for the start byte
|
||||
hott_p->idx = 0;
|
||||
if (rbyte == HOTT_START_BYTE) {
|
||||
hott_p->status++;
|
||||
hott_p->expected_channels = 0;
|
||||
hott_p->buffer[hott_p->idx] = rbyte; // store header for crc
|
||||
hott_p->idx++;
|
||||
}
|
||||
break;
|
||||
case HOTT_STATUS_GOT_START:
|
||||
if (rbyte ==0x01 || rbyte ==0x81) { // hott status
|
||||
/*
|
||||
* SUMD_Header Byte 1 Status
|
||||
* 0x01: valid and live SUMD data frame
|
||||
* 0x81: valid SUMD data frame with transmitter in fail safe condition.
|
||||
* Note:
|
||||
* The SUMD_Data section contains
|
||||
* valid channel data. The channel data are
|
||||
* set by transmitter fail safe values. A FBL
|
||||
* system may replace the transmitter fail safe
|
||||
* data by FBL stored values
|
||||
*
|
||||
* other values: Values different to 0x01 or 0x81 indicate an invalid SUMD data frame and
|
||||
* should not be processed by SUMD algorithms
|
||||
* */
|
||||
hott_p->buffer[hott_p->idx] = rbyte; // store byte for CRC
|
||||
hott_p->idx++;
|
||||
hott_p->status++;
|
||||
} else
|
||||
{
|
||||
hott_p->status=0; // reset
|
||||
}
|
||||
break;
|
||||
case HOTT_STATUS_GOT_HEADER1:
|
||||
/*Indicates the number of channels transmitted in the SUMD_Data section
|
||||
*/
|
||||
if (rbyte >=2 && rbyte <= HOTT_NB_CHANNEL) {
|
||||
hott_p->buffer[hott_p->idx] = rbyte; // stored for crc calculation
|
||||
hott_p->idx++;
|
||||
hott_p->expected_channels = rbyte;
|
||||
hott_p->status++;
|
||||
}else {
|
||||
hott_p->status=0; // reset
|
||||
}
|
||||
break;
|
||||
case HOTT_STATUS_DATA:
|
||||
// Store buffer
|
||||
hott_p->buffer[hott_p->idx] = rbyte;
|
||||
hott_p->idx++;
|
||||
// Decode if last byte is (one of) the correct end byte
|
||||
if(hott_p->idx >= (hott_p->expected_channels*2 +2+3)){ // 3 bytes header, 2 bytes crc
|
||||
decode_hott_buffer(hott_p->buffer, hott_p->pulses , hott_p->expected_channels, &hott_p->frame_available, hott_p->ppm);
|
||||
hott_p->status = HOTT_STATUS_UNINIT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (uart_char_available(dev));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Alexandre Bustico, Gautier Hattenberger
|
||||
*
|
||||
* 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, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file subsystems/radio_control/hott_common.h
|
||||
*
|
||||
* Common hott structs and defines.
|
||||
*/
|
||||
|
||||
#ifndef RC_HOTT_COMMON_H
|
||||
#define RC_HOTT_COMMON_H
|
||||
|
||||
#include "std.h"
|
||||
#include "mcu_periph/uart.h"
|
||||
#include "mcu_periph/gpio.h"
|
||||
|
||||
/* in case you want to override RADIO_CONTROL_NB_CHANNEL */
|
||||
#include "generated/airframe.h"
|
||||
|
||||
/**
|
||||
* Macro to use radio.h file
|
||||
*
|
||||
* HOTT: 7040..12000..16800
|
||||
* PPM: 880..1500..2100
|
||||
*/
|
||||
#define RC_PPM_TICKS_OF_USEC(_v) ((_v) * 8 ) // USEC IN HOTT OUT
|
||||
#define RC_PPM_SIGNED_TICKS_OF_USEC(_v) ((_v) * 8 ) // usec -1000 + 1000 in, HOTT out
|
||||
#define USEC_OF_RC_PPM_TICKS(_v) ((_v) / 8) // HOTT IN USEC OUT
|
||||
|
||||
/**
|
||||
* Generated code holding the description of a given
|
||||
* transmitter
|
||||
*/
|
||||
#include "generated/radio.h"
|
||||
|
||||
/**
|
||||
* Define number of channels.
|
||||
*
|
||||
* HOTT SUMD frame has between 2 and 32 channels
|
||||
* The radio XML file is used to assign the
|
||||
* input values to RC channels.
|
||||
*/
|
||||
#define HOTT_NB_CHANNEL 32
|
||||
#define HOTT_BUF_LENGTH (HOTT_NB_CHANNEL*2+3+2) // 2 bytes per chennel 3 bytes header, 2 bytes CRC
|
||||
|
||||
/**
|
||||
* Default number of channels to actually use.
|
||||
*/
|
||||
#ifndef RADIO_CONTROL_NB_CHANNEL
|
||||
#define RADIO_CONTROL_NB_CHANNEL HOTT_NB_CHANNEL
|
||||
#endif
|
||||
|
||||
#if RADIO_CONTROL_NB_CHANNEL > HOTT_NB_CHANNEL
|
||||
#error "RADIO_CONTROL_NB_CHANNEL mustn't be higher than 32."
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HOTT structure
|
||||
*/
|
||||
struct SHott {
|
||||
uint16_t pulses[HOTT_NB_CHANNEL]; ///< decoded values
|
||||
uint16_t ppm[HOTT_NB_CHANNEL]; ///< decoded and converted values
|
||||
bool frame_available; ///< new frame available
|
||||
uint8_t buffer[HOTT_BUF_LENGTH]; ///< input buffer
|
||||
uint8_t expected_channels; ///< expected number of channels send in header
|
||||
uint8_t idx; ///< input index
|
||||
uint8_t status; ///< decoder state machine status
|
||||
};
|
||||
|
||||
/**
|
||||
* Init function
|
||||
*/
|
||||
void hott_common_init(struct SHott *hott, struct uart_periph *dev);
|
||||
|
||||
/**
|
||||
* Decoding event function
|
||||
*/
|
||||
void hott_common_decode_event(struct SHott *hott, struct uart_periph *dev);
|
||||
|
||||
|
||||
/**
|
||||
* RC event function with handler callback.
|
||||
*/
|
||||
extern void radio_control_impl_event(void (* _received_frame_handler)(void));
|
||||
|
||||
/**
|
||||
* Event macro with handler callback
|
||||
*/
|
||||
#define RadioControlEvent(_received_frame_handler) radio_control_impl_event(_received_frame_handler)
|
||||
|
||||
|
||||
#endif /* RC_HOTT_H */
|
||||
Reference in New Issue
Block a user