Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tfmini.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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 */
22
27#include "tfmini.h"
28#include "mcu_periph/uart.h"
29#include "modules/core/abi.h"
30
31// State interface for rotation compensation
32#include "state.h"
33
34// Messages
35#include "pprzlink/messages.h"
37
41
42static void tfmini_parse(uint8_t byte);
43
44#if PERIODIC_TELEMETRY
46
50static void tfmini_send_lidar(struct transport_tx *trans, struct link_device *dev)
51{
55 &tfmini.mode,
56 &status);
57}
58
59#endif
60
79
84void tfmini_event(void)
85{
86 while (tfmini.parse_status != TFMINI_INITIALIZE && tfmini.device->char_available(tfmini.device->periph)) {
87 tfmini_parse(tfmini.device->get_byte(tfmini.device->periph));
88 }
89}
90
94static void tfmini_parse(uint8_t byte)
95{
96 switch (tfmini.parse_status) {
98 break;
100 if (byte == 0x59) {
103 }
104 break;
106 if (byte == 0x59) {
109 } else {
111 }
112 break;
113
118 break;
120 tfmini.raw_dist |= (byte << 8);
123 break;
124
129 break;
131 tfmini.raw_strength |= (byte << 8);
134 break;
135
140 break;
144 break;
145
147 // When the CRC matches
148 if (tfmini.parse_crc == byte) {
150 tfmini.distance = tfmini.raw_dist / 100.f;
153
154 // When the distance is valid
155 if (tfmini.distance != 0xFFFF) {
156 // compensate AGL measurement for body rotation
158 float phi = stateGetNedToBodyEulers_f()->phi;
159 float theta = stateGetNedToBodyEulers_f()->theta;
160 float gain = (float)fabs((double)(cosf(phi) * cosf(theta)));
162 }
163
164 // send message (if requested)
165 if (tfmini.update_agl) {
167 }
168 }
169 }
170
171 // Start reading again
173 break;
174
175 default:
176 // Error, return to start
178 break;
179 }
180}
Main include for ABI (AirBorneInterface).
#define AGL_LIDAR_TFMINI_ID
static uint8_t status
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
float phi
in radians
float theta
in radians
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
uint16_t foo
Definition main_demo5.c:58
#define byte
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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
void tfmini_event(void)
Lidar event function Receive bytes from the UART port and parse them.
Definition tfmini.c:84
static void tfmini_parse(uint8_t byte)
Parse the lidar bytes 1 by 1.
Definition tfmini.c:94
static void tfmini_send_lidar(struct transport_tx *trans, struct link_device *dev)
Downlink message lidar.
Definition tfmini.c:50
struct TFMini tfmini
Definition tfmini.c:38
void tfmini_init(void)
Initialization function.
Definition tfmini.c:64
driver for the TFMini lidar
uint8_t mode
Definition tfmini.h:56
float distance
Definition tfmini.h:55
bool compensate_rotation
Definition tfmini.h:58
bool update_agl
Definition tfmini.h:57
uint8_t raw_mode
Definition tfmini.h:52
uint16_t raw_dist
Definition tfmini.h:50
uint8_t parse_crc
Definition tfmini.h:49
struct link_device * device
Definition tfmini.h:47
uint16_t raw_strength
Definition tfmini.h:51
enum TFMiniParseStatus parse_status
Definition tfmini.h:48
uint16_t strength
Definition tfmini.h:54
@ TFMINI_INITIALIZE
Definition tfmini.h:34
@ TFMINI_PARSE_STRENGTH_L
Definition tfmini.h:39
@ TFMINI_PARSE_HEAD
Definition tfmini.h:35
@ TFMINI_PARSE_DIST_L
Definition tfmini.h:37
@ TFMINI_PARSE_BYTE7
Definition tfmini.h:42
@ TFMINI_PARSE_HEAD2
Definition tfmini.h:36
@ TFMINI_PARSE_STRENGTH_H
Definition tfmini.h:40
@ TFMINI_PARSE_MODE
Definition tfmini.h:41
@ TFMINI_PARSE_CHECKSUM
Definition tfmini.h:43
@ TFMINI_PARSE_DIST_H
Definition tfmini.h:38
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.