mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-02 13:27:32 +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,222 @@
|
||||
<!DOCTYPE airframe SYSTEM "../airframe.dtd">
|
||||
|
||||
<!-- Microjet Multiplex (http://www.multiplex-rc.de/)
|
||||
Lisa/M v2.0 board (http://wiki.paparazziuav.org/wiki/Lisa/M_v20)
|
||||
Aspirin IMU v2.2 with MS5611 barometer
|
||||
Xbee modem in transparent mode
|
||||
-->
|
||||
|
||||
<airframe name="Hobbyking X1 Li sa/M 2.0">
|
||||
<firmware name="setup">
|
||||
<target name="tunnel" board="lisa_m_2.0"/>
|
||||
<target name="usb_tunnel" board="lisa_m_2.0">
|
||||
<configure name="TUNNEL_PORT" value="UART3"/>
|
||||
</target>
|
||||
<target name="setup_actuators" board="lisa_m_2.0">
|
||||
<module name="actuators" type="pwm"/>
|
||||
<define name="SERVO_HZ" value="400"/>
|
||||
<define name="USE_SERVOS_7AND8"/>
|
||||
</target>
|
||||
</firmware>
|
||||
|
||||
|
||||
<firmware name="fixedwing">
|
||||
<target name="sim" board="pc"/>
|
||||
<target name="nps" board="pc">
|
||||
<module name="fdm" type="jsbsim"/>
|
||||
</target>
|
||||
<target name="ap" board="lisa_m_2.0">
|
||||
<!-- baro board options for Lisa/M 2.0: BARO_BOARD_BMP085, BARO_MS5611_I2C, BARO_MS5611_SPI (default) -->
|
||||
<configure name="LISA_M_BARO" value="BARO_BOARD_BMP085"/>
|
||||
<configure name="PERIODIC_FREQUENCY" value="120"/>
|
||||
<configure name="AHRS_PROPAGATE_FREQUENCY" value="100"/>
|
||||
<configure name="AHRS_CORRECT_FREQUENCY" value="100"/>
|
||||
</target>
|
||||
|
||||
<configure name="USE_MAGNETOMETER" value="FALSE"/>
|
||||
|
||||
<define name="AGR_CLIMB"/>
|
||||
<define name="LOITER_TRIM"/>
|
||||
<define name="STRONG_WIND"/>
|
||||
|
||||
<module name="actuators" type="pwm"/>
|
||||
<define name="SERVO_HZ" value="50"/>
|
||||
|
||||
<!-- <module name="radio_control" type="ppm"/> -->
|
||||
<module name="radio_control" type="hott">
|
||||
<configure name="HOTT_PORT" value="UART1"/>
|
||||
</module>
|
||||
|
||||
<!-- Communication -->
|
||||
<module name="telemetry" type="transparent"/>
|
||||
|
||||
<!-- Sensors -->
|
||||
<module name="imu" type="aspirin_v2.1"/>
|
||||
<module name="gps" type="ublox"/>
|
||||
<module name="usb_serial_stm32_example2" />
|
||||
|
||||
<module name="ahrs" type="int_cmpl_quat"/>
|
||||
<module name="control"/>
|
||||
<module name="navigation"/>
|
||||
<module name="ins" type="alt_float">
|
||||
<define name="USE_BAROMETER" value="TRUE"/>
|
||||
</module>
|
||||
<module name="adc_generic">
|
||||
<configure name="ADC_CHANNEL_GENERIC1" value="ADC_1"/>
|
||||
<configure name="ADC_CHANNEL_GENERIC2" value="ADC_2"/>
|
||||
</module>
|
||||
</firmware>
|
||||
|
||||
<modules>
|
||||
<module name="sys_mon"/>
|
||||
<module name="baro_sim"/>
|
||||
<module name="air_data">
|
||||
<define name="AIR_DATA_CALC_AMSL_BARO" value="TRUE"/>
|
||||
</module>
|
||||
|
||||
<module name="digital_cam_servo">
|
||||
<define name="DC_SHUTTER_SERVO" value="COMMAND_SHUTTER"/>
|
||||
</module>
|
||||
</modules>
|
||||
|
||||
|
||||
<servos>
|
||||
<servo name="MOTOR" no="0" min="1100" neutral="1100" max="1810"/>
|
||||
<servo name="AILEVON_LEFT" no="1" min="2000" neutral="1510" max="1000"/>
|
||||
<servo name="AILEVON_RIGHT" no="2" min="1000" neutral="1535" max="2000"/>
|
||||
</servos>
|
||||
|
||||
<commands>
|
||||
<axis name="THROTTLE" failsafe_value="0"/>
|
||||
<axis name="ROLL" failsafe_value="0"/>
|
||||
<axis name="PITCH" failsafe_value="0"/>
|
||||
<axis name="SHUTTER" failsafe_value="0"/>
|
||||
</commands>
|
||||
|
||||
<rc_commands>
|
||||
<set command="THROTTLE" value="@THROTTLE"/>
|
||||
<set command="ROLL" value="@ROLL"/>
|
||||
<set command="PITCH" value="@PITCH"/>
|
||||
</rc_commands>
|
||||
|
||||
<section name="MIXER">
|
||||
<define name="AILEVON_AILERON_RATE" value="0.75"/>
|
||||
<define name="AILEVON_ELEVATOR_RATE" value="0.75"/>
|
||||
</section>
|
||||
|
||||
<command_laws>
|
||||
<let var="aileron" value="@ROLL * AILEVON_AILERON_RATE"/>
|
||||
<let var="elevator" value="@PITCH * AILEVON_ELEVATOR_RATE"/>
|
||||
<set servo="MOTOR" value="@THROTTLE"/>
|
||||
<set servo="AILEVON_LEFT" value="$elevator - $aileron"/>
|
||||
<set servo="AILEVON_RIGHT" value="$elevator + $aileron"/>
|
||||
</command_laws>
|
||||
|
||||
<section name="IMU" prefix="IMU_">
|
||||
<!-- ACCEL and GYRO calibration left out to take default datasheet values -->
|
||||
|
||||
<!-- replace this with your own mag calibration -->
|
||||
<define name="MAG_X_NEUTRAL" value="-45"/>
|
||||
<define name="MAG_Y_NEUTRAL" value="334"/>
|
||||
<define name="MAG_Z_NEUTRAL" value="7"/>
|
||||
<define name="MAG_X_SENS" value="4.47647816128" integer="16"/>
|
||||
<define name="MAG_Y_SENS" value="4.71085671542" integer="16"/>
|
||||
<define name="MAG_Z_SENS" value="4.41585354498" integer="16"/>
|
||||
|
||||
<define name="BODY_TO_IMU_PHI" value="0." unit="deg"/>
|
||||
<define name="BODY_TO_IMU_THETA" value="0." unit="deg"/>
|
||||
<define name="BODY_TO_IMU_PSI" value="-90" unit="deg"/>
|
||||
</section>
|
||||
|
||||
<section name="INS" prefix="INS_">
|
||||
<define name="ROLL_NEUTRAL_DEFAULT" value="0" unit="deg"/>
|
||||
<define name="PITCH_NEUTRAL_DEFAULT" value="0" unit="deg"/>
|
||||
</section>
|
||||
|
||||
<section name="VERTICAL CONTROL" prefix="V_CTL_">
|
||||
<define name="POWER_CTL_BAT_NOMINAL" value="11.1" unit="volt"/>
|
||||
<!-- outer loop proportional gain -->
|
||||
<define name="ALTITUDE_PGAIN" value="0.03"/>
|
||||
<!-- outer loop saturation -->
|
||||
<define name="ALTITUDE_MAX_CLIMB" value="2."/>
|
||||
|
||||
<!-- auto throttle inner loop -->
|
||||
<define name="AUTO_THROTTLE_NOMINAL_CRUISE_THROTTLE" value="0.32"/>
|
||||
<define name="AUTO_THROTTLE_MIN_CRUISE_THROTTLE" value="0.25"/>
|
||||
<define name="AUTO_THROTTLE_MAX_CRUISE_THROTTLE" value="0.65"/>
|
||||
<define name="AUTO_THROTTLE_LOITER_TRIM" value="1500"/>
|
||||
<define name="AUTO_THROTTLE_DASH_TRIM" value="-4000"/>
|
||||
<define name="AUTO_THROTTLE_CLIMB_THROTTLE_INCREMENT" value="0.15" unit="%/(m/s)"/>
|
||||
<define name="AUTO_THROTTLE_PGAIN" value="0.01"/>
|
||||
<define name="AUTO_THROTTLE_IGAIN" value="0.1"/>
|
||||
<define name="AUTO_THROTTLE_PITCH_OF_VZ_PGAIN" value="0.05"/>
|
||||
|
||||
<define name="THROTTLE_SLEW_LIMITER" value="2" unit="s"/>
|
||||
</section>
|
||||
|
||||
<section name="HORIZONTAL CONTROL" prefix="H_CTL_">
|
||||
<define name="COURSE_PGAIN" value="1.0"/>
|
||||
<define name="COURSE_DGAIN" value="0.3"/>
|
||||
|
||||
<define name="ROLL_MAX_SETPOINT" value="35" unit="deg"/>
|
||||
<define name="PITCH_MAX_SETPOINT" value="30" unit="deg"/>
|
||||
<define name="PITCH_MIN_SETPOINT" value="-30" unit="deg"/>
|
||||
|
||||
<define name="PITCH_PGAIN" value="12000."/>
|
||||
<define name="PITCH_DGAIN" value="1.5"/>
|
||||
|
||||
<define name="ELEVATOR_OF_ROLL" value="1250"/>
|
||||
|
||||
<define name="ROLL_SLEW" value="0.1"/>
|
||||
|
||||
<define name="ROLL_ATTITUDE_GAIN" value="7500"/>
|
||||
<define name="ROLL_RATE_GAIN" value="1500"/>
|
||||
</section>
|
||||
|
||||
<section name="AGGRESSIVE" prefix="AGR_">
|
||||
<define name="BLEND_START" value="20"/><!-- Altitude Error to Initiate Aggressive Climb CANNOT BE ZERO!!-->
|
||||
<define name="BLEND_END" value="10"/><!-- Altitude Error to Blend Aggressive to Regular Climb Modes CANNOT BE ZERO!!-->
|
||||
<define name="CLIMB_THROTTLE" value="1.00"/><!-- Gaz for Aggressive Climb -->
|
||||
<define name="CLIMB_PITCH" value="0.3"/><!-- Pitch for Aggressive Climb -->
|
||||
<define name="DESCENT_THROTTLE" value="0.1"/><!-- Gaz for Aggressive Decent -->
|
||||
<define name="DESCENT_PITCH" value="-0.25"/><!-- Pitch for Aggressive Decent -->
|
||||
<define name="CLIMB_NAV_RATIO" value="0.8"/><!-- Percent Navigation for Altitude Error Equal to Start Altitude -->
|
||||
<define name="DESCENT_NAV_RATIO" value="1.0"/>
|
||||
</section>
|
||||
|
||||
<section name="FAILSAFE" prefix="FAILSAFE_">
|
||||
<define name="DELAY_WITHOUT_GPS" value="2" unit="s"/>
|
||||
<define name="DEFAULT_THROTTLE" value="0.3" unit="%"/>
|
||||
<define name="DEFAULT_ROLL" value="0.3" unit="rad"/>
|
||||
<define name="DEFAULT_PITCH" value="0.5" unit="rad"/>
|
||||
</section>
|
||||
|
||||
<section name="AUTO1" prefix="AUTO1_">
|
||||
<define name="MAX_ROLL" value="40." unit="deg"/>
|
||||
<define name="MAX_PITCH" value="35." unit="deg"/>
|
||||
</section>
|
||||
|
||||
<section name="BAT">
|
||||
<define name="MILLIAMP_AT_FULL_THROTTLE" value="2000"/>
|
||||
<define name="CATASTROPHIC_BAT_LEVEL" value="9.3" unit="V"/>
|
||||
<define name="CRITIC_BAT_LEVEL" value="9.6" unit="V"/>
|
||||
<define name="LOW_BAT_LEVEL" value="9.7" unit="V"/>
|
||||
<define name="MAX_BAT_LEVEL" value="12.4" unit="V"/>
|
||||
</section>
|
||||
|
||||
<section name="MISC">
|
||||
<define name="NOMINAL_AIRSPEED" value="13." unit="m/s"/>
|
||||
<define name="CARROT" value="5." unit="s"/>
|
||||
<define name="KILL_MODE_DISTANCE" value="(1.5*MAX_DIST_FROM_HOME)"/>
|
||||
<define name="CONTROL_FREQUENCY" value="60" unit="Hz"/>
|
||||
<define name="DEFAULT_CIRCLE_RADIUS" value="80."/>
|
||||
</section>
|
||||
|
||||
<section name="SIMULATOR" prefix="NPS_">
|
||||
<define name="JSBSIM_MODEL" value="easystar" type="string"/>
|
||||
<define name="JSBSIM_LAUNCHSPEED" value="20"/>
|
||||
<define name="SENSORS_PARAMS" value="nps_sensors_params_default.h" type="string"/>
|
||||
<define name="JS_AXIS_MODE" value="4"/>
|
||||
</section>
|
||||
|
||||
</airframe>
|
||||
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE module SYSTEM "module.dtd">
|
||||
|
||||
<module name="radio_control_hott" dir="radio_control">
|
||||
<doc>
|
||||
<description>
|
||||
Radio control based on Graupner HOTT SUMD
|
||||
</description>
|
||||
<configure name="RADIO_CONTROL_LED" value="none|num" description="LED number or 'none' to disable"/>
|
||||
<configure name="HOTT_PORT" value="UARTX" description="UART name where HOTT receiver is plugged"/>
|
||||
</doc>
|
||||
<header>
|
||||
<file name="hott.h" dir="subsystems/radio_control"/>
|
||||
</header>
|
||||
<makefile target="ap|fbw">
|
||||
<configure name="RADIO_CONTROL_LED" default="none"/>
|
||||
<configure name="HOTT_UART" value="$(HOTT_PORT)" case="upper|lower"/>
|
||||
<define name="RADIO_CONTROL_LED" value="$(RADIO_CONTROL_LED)" cond="ifneq ($(RADIO_CONTROL_LED),none)"/>
|
||||
<define name="RADIO_CONTROL_TYPE_H" value="subsystems/radio_control/hott.h" type="string"/>
|
||||
</makefile>
|
||||
<makefile target="fbw">
|
||||
<define name="RADIO_CONTROL"/>
|
||||
<define name="RADIO_CONTROL_TYPE_HOTT"/>
|
||||
<define name="USE_$(HOTT_UART_UPPER)"/>
|
||||
<define name="$(HOTT_UART_UPPER)_BAUD" value="B115200"/>
|
||||
<define name="HOTT_UART_DEV" value="$(HOTT_UART_LOWER)"/>
|
||||
<file name="radio_control.c" dir="subsystems"/>
|
||||
<file name="hott.c" dir="subsystems/radio_control"/>
|
||||
<file name="hott_common.c" dir="subsystems/radio_control"/>
|
||||
</makefile>
|
||||
<makefile target="ap" cond="ifeq (,$(findstring $(SEPARATE_FBW),1 TRUE))">
|
||||
<define name="RADIO_CONTROL"/>
|
||||
<define name="RADIO_CONTROL_TYPE_HOTT"/>
|
||||
<define name="USE_$(HOTT_UART_UPPER)"/>
|
||||
<define name="$(HOTT_UART_UPPER)_BAUD" value="B115200"/>
|
||||
<define name="HOTT_UART_DEV" value="$(HOTT_UART_LOWER)"/>
|
||||
<file name="radio_control.c" dir="subsystems"/>
|
||||
<file name="hott.c" dir="subsystems/radio_control"/>
|
||||
<file name="hott_common.c" dir="subsystems/radio_control"/>
|
||||
</makefile>
|
||||
</module>
|
||||
|
||||
@@ -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