Skip to content

Commit 1c75510

Browse files
committed
add RdrGizmoUSD1
1 parent 80e95f2 commit 1c75510

File tree

12 files changed

+152
-51
lines changed

12 files changed

+152
-51
lines changed

examples/01.Quadcopter/madflight_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// You have 3 options to setup the pins (gpio numbers) and busses for the flight controller:
66
//
77
// 1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
8-
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_default_XXX.h
8+
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_XXX.h
99
//
1010
// 2) Header - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1111
// boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
@@ -63,6 +63,10 @@ gps_baud 0 // use 0 for auto baud
6363
// BBX - Black Box Data Logger
6464
bbx_gizmo NONE // options: NONE, SDSPI, SDMMC
6565

66+
// RDR - Radar
67+
rdr_gizmo NONE // options: NONE, LD2411S, LD2413, USD1
68+
rdr_baud 0
69+
6670
)"" // End of MADFLIGHT_CONFIG
6771

6872

examples/02.QuadcopterAdvanced/madflight_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// You have 3 options to setup the pins (gpio numbers) and busses for the flight controller:
66
//
77
// 1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
8-
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_default_XXX.h
8+
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_XXX.h
99
//
1010
// 2) Header - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1111
// boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
@@ -63,6 +63,10 @@ gps_baud 0 // use 0 for auto baud
6363
// BBX - Black Box Data Logger
6464
bbx_gizmo NONE // options: NONE, SDSPI, SDMMC
6565

66+
// RDR - Radar
67+
rdr_gizmo NONE // options: NONE, LD2411S, LD2413, USD1
68+
rdr_baud 0
69+
6670
)"" // End of MADFLIGHT_CONFIG
6771

6872

examples/03.Plane/madflight_config.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// You have 3 options to setup the pins (gpio numbers) and busses for the flight controller:
66
//
77
// 1) Default - #include <madflight_board.h> and see https://madflight.com for default pinout diagrams for the supported
8-
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_default_XXX.h
8+
// processor families. Default pinouts are defined in the board header files library/src/madflight_board_XXX.h
99
//
1010
// 2) Header - #include the BetaFlight flight controller you want to use. See library/madflight/src for all available
1111
// boards. For example: #include <madflight_zzz_MTKS-MATEKH743.h>
@@ -63,6 +63,10 @@ gps_baud 0 // use 0 for auto baud
6363
// BBX - Black Box Data Logger
6464
bbx_gizmo NONE // options: NONE, SDSPI, SDMMC
6565

66+
// RDR - Radar
67+
rdr_gizmo NONE // options: NONE, LD2411S, LD2413, USD1
68+
rdr_baud 0
69+
6670
)"" // End of MADFLIGHT_CONFIG
6771

6872

src/madflight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void madflight_setup() {
179179

180180
// GPS
181181
gps.config.gizmo = (Cfg::gps_gizmo_enum)cfg.gps_gizmo; //the gizmo to use
182-
gps.config.ser_bus = hal_get_ser_bus(cfg.gps_ser_bus); //serial bus
182+
gps.config.ser_bus_id = cfg.gps_ser_bus; //serial bus id
183183
gps.config.baud = cfg.gps_baud; //baud rate
184184
gps.setup();
185185

src/madflight/cfg/cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ SOFTWARE.
221221
MF_PARAM( mag_lp, 1e10, float, 'f') /*Magnetometer Gyro Low Pass Filter cutoff frequency in Hz (default 1e10Hz, i.e. no filtering) */ \
222222
\
223223
/*RDR - Radar*/ \
224-
MF_PARAM( rdr_gizmo, 0, int32_t, 'e', mf_NONE,mf_LD2411S,mf_LD2413) \
224+
MF_PARAM( rdr_gizmo, 0, int32_t, 'e', mf_NONE,mf_LD2411S,mf_LD2413,mf_USD1) \
225225
MF_PARAM( rdr_ser_bus, -1, int32_t, 'i') \
226226
MF_PARAM( rdr_baud, 0, int32_t, 'i') \
227227
\

src/madflight/gps/GpsGizmoUblox.h

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
#pragma once
22

33
#include "gps.h"
4-
#include "../hal/MF_Serial.h"
4+
#include "../hal/hal.h"
55
#include "GPS-uBlox/qqqlab_GPS_UBLOX.h"
66
//#include "GPS-uBlox/qqqlab_AutoBaud.h"
77

88
class GpsGizmoUblox: public GpsGizmo {
9-
public:
10-
GpsGizmoUblox(GpsState *state, MF_Serial *ser_bus, int baud) {
11-
//baud is initial GPS baud rate to try
12-
if(baud<=0) baud = 230400;
9+
private:
10+
GpsGizmoUblox() {} //private constructor
1311

14-
//optional auto-baud to speed up gps connection
15-
//baud = autobaud(PIN_GPS_RX);
16-
//Serial.printf("Initial GPS baud rate:%d\n", baud);
12+
public:
13+
static GpsGizmoUblox* create(GpsState *state, int ser_bus_id, int baud) {
14+
//get serial bus
15+
if(baud == 0) baud = 230400; //baud is initial GPS baud rate to try
16+
MF_Serial* ser_bus = hal_get_ser_bus(ser_bus_id, baud);
17+
if(!ser_bus) return nullptr;
1718

18-
//start GPS Serial with initial baud
19-
ser_bus->begin(baud);
19+
//setup gizmo
20+
auto gizmo = new GpsGizmoUblox();
21+
gizmo->gps_ublox.state = state;
22+
gizmo->gps_ublox.ser_bus = ser_bus;
23+
gizmo->gps_ublox.rate_ms = 100; //optional - gps update rate in milliseconds (default 100)
24+
gizmo->gps_ublox.save_config = 2, //optional - save config 0:Do not save config, 1:Save config, 2:Save only when needed (default 2)
25+
gizmo->gps_ublox.gnss_mode = 0; //optonial - GNSS system(s) to use Bitmask: 1:GPS, 2:SBAS, 4:Galileo, 8:Beidou, 16:IMES, 32:QZSS, 64:GLONASS (default 0=leave as configured)
26+
return gizmo;
27+
}
2028

21-
//start GPS
22-
gps_ublox.state = state;
23-
gps_ublox.ser_bus = ser_bus;
24-
gps_ublox.rate_ms = 100; //optional - gps update rate in milliseconds (default 100)
25-
gps_ublox.save_config = 2, //optional - save config 0:Do not save config, 1:Save config, 2:Save only when needed (default 2)
26-
gps_ublox.gnss_mode = 0; //optonial - GNSS system(s) to use Bitmask: 1:GPS, 2:SBAS, 4:Galileo, 8:Beidou, 16:IMES, 32:QZSS, 64:GLONASS (default 0=leave as configured)
27-
}
29+
bool update() override {
30+
//update GPS (call at least 10 times per second)
31+
return gps_ublox.update();
32+
}
33+
34+
protected:
35+
class GPS_UBLOX : public AP_GPS_UBLOX {
36+
public:
37+
MF_Serial *ser_bus;
2838

29-
bool update() override {
30-
//update GPS (call at least 10 times per second)
31-
return gps_ublox.update();
32-
}
33-
34-
protected:
35-
class GPS_UBLOX : public AP_GPS_UBLOX {
36-
public:
37-
MF_Serial *ser_bus;
38-
39-
//interface
40-
void I_setBaud(int baud) override {ser_bus->begin(baud);}
41-
inline int I_availableForWrite() override {return ser_bus->availableForWrite();}
42-
inline int I_available() override {return ser_bus->available();}
43-
inline int I_read(uint8_t* data, size_t len) override {return ser_bus->read(data, len);}
44-
inline int I_write(uint8_t* data, size_t len) override {return ser_bus->write(data, len);}
45-
inline uint32_t I_millis() override {return ::millis();}
46-
void I_print(const char *str) override {Serial.print("GPS: "); Serial.print(str);}
47-
} gps_ublox;
48-
};
39+
//interface
40+
void I_setBaud(int baud) override {ser_bus->begin(baud);}
41+
inline int I_availableForWrite() override {return ser_bus->availableForWrite();}
42+
inline int I_available() override {return ser_bus->available();}
43+
inline int I_read(uint8_t* data, size_t len) override {return ser_bus->read(data, len);}
44+
inline int I_write(uint8_t* data, size_t len) override {return ser_bus->write(data, len);}
45+
inline uint32_t I_millis() override {return ::millis();}
46+
void I_print(const char *str) override {Serial.print("GPS: "); Serial.print(str);}
47+
} gps_ublox;
48+
};

src/madflight/gps/gps.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,14 @@ Gps gps;
3737
int Gps::setup() {
3838
Cfg::printModule(MF_MOD);
3939

40-
if(!config.ser_bus && config.gizmo != Cfg::gps_gizmo_enum::mf_NONE) {
41-
Serial.println("\n" MF_MOD ": ERROR Serial bus not connected, check pins.\n");
42-
return -1002;
43-
}
44-
4540
//create gizmo
4641
delete gizmo;
4742
switch(config.gizmo) {
4843
case Cfg::gps_gizmo_enum::mf_NONE :
4944
gizmo = nullptr;
5045
break;
5146
case Cfg::gps_gizmo_enum::mf_UBLOX :
52-
gizmo = new GpsGizmoUblox((GpsState*)this, config.ser_bus, config.baud);
47+
gizmo = GpsGizmoUblox::create((GpsState*)this, config.ser_bus_id, config.baud);
5348
break;
5449
}
5550

src/madflight/gps/gps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct GpsState {
7171
struct GpsConfig {
7272
public:
7373
Cfg::gps_gizmo_enum gizmo = Cfg::gps_gizmo_enum::mf_NONE; //the gizmo to use
74-
MF_Serial *ser_bus = nullptr; //Serial bus
74+
int ser_bus_id = -1; //Serial bus id
7575
int baud = 0; //baud rate. 0=autobaud
7676
};
7777

src/madflight/rdr/RdrGizmoLD2411S.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// HKL-LD2411S driver
2+
// range: 6m
3+
// reporting rate: 100ms
24
// default baud rate 256000
3-
// default reporting rate: ???
45
// reported data: AA AA tt xx xx 55 55
56
// where xx xx is a LE int16 with distance in cm
67
// and tt is 00=no data, 01="campaign target", 02="mircomotion target"

src/madflight/rdr/RdrGizmoLD2413.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// HKL-LD2413 driver
2+
// range: 10m
3+
// reporting rate: 50-1000ms, 160ms default
24
// default baud rate 115200
3-
// default reporting rate: 160ms
45
// reported data: F4 F3 F2 F1 04 00 xx xx xx xx F8 F7 F6 F5
56
// where xx xx xx xx is a LE float with distance in mm
67

0 commit comments

Comments
 (0)