Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
tfmini_nps.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Alejandro Rochas <alrochas@ucm.es>
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
28#include "tfmini.h"
29#include "state.h"
30
31// Messages
32#include "pprzlink/messages.h"
34#include "modules/core/abi.h"
35
36#define LIDAR_MIN_RANGE 0.1
37#define LIDAR_MAX_RANGE 12.0
38
40
41#if PERIODIC_TELEMETRY
43
47static void tfmini_send_lidar(struct transport_tx *trans, struct link_device *dev)
48{
52 &tfmini.mode,
53 &status);
54}
55
56#endif
57
58
59
63void tfmini_init(void)
64{
65 tfmini.distance = 0;
67
68#if PERIODIC_TELEMETRY
70#endif
71}
72
73
74void tfmini_event(void)
75{
77}
78
79
80
81// If you want to use the lidar simulation, you need to use the lidar correction module
83{
84 if (!stateIsLocalCoordinateValid()) { return; }
85
86 // Convert GPS position to NED coordinates
87 struct FloatVect2 pos = {0.0f, 0.0f};
88 struct NedCoor_i ned = {0.0f, 0.0f, 0.0f};
90 pos.x = (float)(ned.y / 100.0f);
91 pos.y = (float)(ned.x / 100.0f);
92
93 // Calculate the angle of the rover (and servo if used)
94 float theta = M_PI / 2 - (stateGetNedToBodyEulers_f()->psi);
95#ifdef USE_SERVO_LIDAR
96 theta = theta - servoLidar.angle * M_PI / 180;
97#endif
98
99 float min_distance = FLT_MAX;
100
101 // Traverse the wall array and store the minimum distance (!= 0)
102 for (uint8_t w = 0; w < wall_system.wall_count; w++) {
103 struct Wall *wall = &wall_system.walls[w];
104 for (uint8_t p = 0; p < wall->count - 1; p++) {
105 struct FloatVect2 p1 = wall->points_ltp[p];
106 struct FloatVect2 p2 = wall->points_ltp[p + 1];
107 float distance = distance_to_wall(theta, &pos, &p1, &p2);
109 min_distance = distance;
110 }
111 }
112 }
113
114 // Store that data in the variable tfmini.distance
116}
117
118
123void setLidarDistance_f(float distance)
124{
126 distance = 0;
127 }
128 tfmini.distance = distance;
130}
131
132
133// Send the lidar message (if requested, OBSTACLE_DETECTION)
135{
136#ifndef USE_SERVO_LIDAR
137 //send message (if there is not servo module)
139#endif
140}
Main include for ABI (AirBorneInterface).
#define AGL_LIDAR_TFMINI_ID
static uint8_t status
struct GpsState gps
global GPS state
Definition gps.c:74
struct LlaCoor_i lla_pos
position in LLA (lat,lon: deg*1e7; alt: mm over ellipsoid)
Definition gps.h:95
float psi
in radians
void ned_of_lla_point_i(struct NedCoor_i *ned, struct LtpDef_i *def, struct LlaCoor_i *lla)
Convert a point from LLA to local NED.
vector in North East Down coordinates
static struct FloatEulers * stateGetNedToBodyEulers_f(void)
Get vehicle body attitude euler angles (float).
Definition state.h:1306
static bool stateIsLocalCoordinateValid(void)
Test if local coordinates are valid.
Definition state.h:613
static struct LtpDef_i * stateGetNedOrigin_i(void)
Get the coordinate NED frame origin (int)
Definition state.h:556
static float p[2][2]
float distance_to_wall(float theta, const struct FloatVect2 *P, const struct FloatVect2 *A, const struct FloatVect2 *B)
struct WallSystem wall_system
uint8_t wall_count
struct Wall walls[MAX_WALLS]
uint16_t foo
Definition main_demo5.c:58
struct ServoLidar servoLidar
Definition servo_lidar.c:44
float angle
Definition servo_lidar.h:40
API to get/set the generic vehicle states.
static const struct usb_device_descriptor dev
Definition usb_ser_hw.c:74
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_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
driver for the TFMini lidar
uint8_t mode
Definition tfmini.h:58
float distance
Definition tfmini.h:57
struct link_device * device
Definition tfmini.h:49
enum TFMiniParseStatus parse_status
Definition tfmini.h:50
void tfmini_event(void)
Lidar event function Receive bytes from the UART port and parse them.
Definition tfmini_nps.c:74
static void tfmini_send_lidar(struct transport_tx *trans, struct link_device *dev)
Downlink message lidar.
Definition tfmini_nps.c:47
void sim_overwrite_lidar(void)
Definition tfmini_nps.c:82
#define LIDAR_MAX_RANGE
Definition tfmini_nps.c:37
struct TFMini tfmini
Definition tfmini_nps.c:39
void setLidarDistance_f(float distance)
Set the distance of the lidar This function is used in NPS to set the distance of the lidar.
Definition tfmini_nps.c:123
void tfmini_send_abi(void)
Definition tfmini_nps.c:134
void tfmini_init(void)
Initialization function.
Definition tfmini_nps.c:63
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.